Page MenuHomePhabricator

Bogus MediaWiki.WhiteSpace.SpaceyParenthesis auto-fix when there is whitespace at the end of the line
Closed, ResolvedPublic

Description

Before
$options = [ 
	'timeout' => 'default',
];

Note there is a space after the opening [.

After
$options = [ 'timeout' => 'default',
];

Example from https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/ExternalData/+/575982/1/includes/ED_Utils.php.

It seems the sniff detects the [ sequence with the space, continues as if the array is on a single line, and removes the following newline and indention.

What it could do instead: Check if the opening [ is followed by a horizontal whitespace token (spaces, tabs), directly followed by a vertical whitespace token (newlines). If this is the case, remove the first one instead of the second. Detecting "horizontal" vs. "vertical" tokens is easily possible by comparing the 'line' of the current and next token. String comparisons are not needed.

Event Timeline

Change 585961 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Fix newline detection in SpacyParenthesisSniff

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

Change 585961 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Fix newline detection in SpacyParenthesisSniff

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

Umherirrender claimed this task.
Umherirrender triaged this task as Medium priority.