Page MenuHomePhabricator

Sniff for one space after each comma in inline array declaration
Closed, ResolvedPublic

Description

This has been quite messy. See the comments in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/939385
Basically, stuff like:

$a = ['a','b'];
$a = ['a',     'b'];

Should fail the phpcs.

I found https://github.com/squizlabs/PHP_CodeSniffer/issues/582 and https://github.com/squizlabs/PHP_CodeSniffer/issues/2687

This would be extremely useful when I'm mass switching calls to deprecated Database methods to QueryBuilders as the php parser strips all spaces

Event Timeline

Change 940967 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/tools/codesniffer@master] Introduce OneSpaceInlineArraySniff

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

Change 940969 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] Fix space after comma in single-line array declaration

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

Change 940969 merged by jenkins-bot:

[mediawiki/core@master] Fix space after comma in single-line array declaration

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

Change 940967 merged by jenkins-bot:

[mediawiki/tools/codesniffer@master] Introduce OneSpaceInlineArraySniff

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

It is done but should I close it? How should we enable it in core?

It is done but should I close it? How should we enable it in core?

It's automatically live in the dev branch; see the testrun result:

00:02:24.053 FILE: /src/languages/messages/MessagesAr.php
00:02:24.053 ----------------------------------------------------------------------
00:02:24.053 FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
00:02:24.053 ----------------------------------------------------------------------
00:02:24.053  171 | WARNING | [x] array elements need one space after comma
00:02:24.054      |         |     (MediaWiki.Arrays.OneSpaceInlineArray.OneSpaceInlineArray)
00:02:24.054  255 | WARNING | [x] array elements need one space after comma
00:02:24.054      |         |     (MediaWiki.Arrays.OneSpaceInlineArray.OneSpaceInlineArray)
00:02:24.054 ----------------------------------------------------------------------
00:02:24.054 PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
00:02:24.054 ----------------------------------------------------------------------

It'll be enabled in all repos when we update them to the next release, which is T340889: Release mediawiki-codesniffer v42.0.0; I'll poke on that now.

Change 950059 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] languages: Fix phpcbf errors

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

Change 950059 merged by jenkins-bot:

[mediawiki/core@master] languages: Fix phpcs errors

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