Page MenuHomePhabricator

phpcbf: MediaWiki_Sniffs_WhiteSpace_SpaceyParenthesisSniff removes array elements
Closed, ResolvedPublic

Description

Before:

'props' => ['sitelinks', 'claims'],

After running phpcbf with the mediawiki/mediawiki-codesniffer 0.7.1 rule set:

'props' => [ 'sitelinks', ],

This happened in https://gerrit.wikimedia.org/r/#/c/287826/1/includes/SearchHookHandler.php, line 267.

Originally posted as https://github.com/squizlabs/PHP_CodeSniffer/issues/999. Quoting https://github.com/squizlabs/PHP_CodeSniffer/issues/999#issuecomment-218117484:

We can see that the sniff that removed "claims" was MediaWiki_Sniffs_WhiteSpace_SpaceyParenthesisSniff as it was trying to fix the warning "Single space expected before closing parenthesis". It replaced this content with a single space character.

Event Timeline

thiemowmde triaged this task as Unbreak Now! priority.May 10 2016, 10:12 AM
thiemowmde renamed this task from phpcbf removes array elements to phpcbf: MediaWiki_Sniffs_WhiteSpace_SpaceyParenthesisSniff removes array elements.May 10 2016, 10:28 AM
thiemowmde updated the task description. (Show Details)
Nikerabbit subscribed.

This is especially worrisome given that many extensions were just mass-changed by this method. We might need to double check all of those.

Change 288043 had a related patch set uploaded (by PleaseStand):
SpaceyParenthesisSniff: Don't remove last argument or array element

https://gerrit.wikimedia.org/r/288043

As there has been a patch for two weeks and as this is "Unbreak now", anyone having plans to merge?

Change 288043 merged by jenkins-bot:
SpaceyParenthesisSniff: Don't remove last argument or array element

https://gerrit.wikimedia.org/r/288043

I wrote a script to identify extensions that would have been affected by the SpaceyParenthesisSniff bug. The only extension that triggered it was ArticlePlaceholder, though I would appreciate additional eyes on my script.

1#!/usr/bin/env python3
2
3import os
4import subprocess
5import sys
6
7last = 'SemanticForms'
8
9name = os.getcwd().split('/')[-1]
10if name <= last:
11 sys.exit(0)
12
13print(name)
14patches = subprocess.check_output(['git', 'log', '--oneline']).decode()
15splitlines = patches.splitlines()
16for i, line in enumerate(splitlines):
17 sp = line.split()
18 sha1 = sp[0]
19 message = ' '.join(sp[1:])
20 if message == 'build: Updating mediawiki/mediawiki-codesniffer to 0.7.1':
21 subprocess.check_call(['composer', 'update'])
22 subprocess.check_call(['git', 'checkout', splitlines[i+1].split()[0]])
23 try:
24 out = subprocess.check_output(['vendor/bin/phpcs', '-s']).decode()
25 print('No errors? All good.')
26 sys.exit(0)
27 except subprocess.CalledProcessError as e:
28 out = e.output.decode()
29 print('---')
30 # print(out)
31 if 'MediaWiki.WhiteSpace.SpaceyParenthesis.SingleSpaceAfterOpenParenthesis' in out\
32 or 'MediaWiki.WhiteSpace.SpaceyParenthesis.SingleSpaceBeforeCloseParenthesis' in out:
33 print('BADDDDDD')
34 sys.exit(1)
35sys.exit(0)

I will be releasing 0.7.2 with this bug fix, and submitting patches to upgrade all 0.7.1 repos to 0.7.2.

Legoktm assigned this task to PleaseStand.