Page MenuHomePhabricator

Add sniff to remove space after not operator
Closed, ResolvedPublic

Description

It seems the mediawiki codebase is using the not operator ! without a space after it.

I suggest to add a sniff for this case

phpcs does not provide a default sniff for this. It have a sniff to enforce the space after ! - SpaceAfterNotSniff

The sniff should remove a space/tab or newline after not operator. Maybe validate one space before the ! (T_BOOLEAN_NOT) as well (when there is not another !).

Event Timeline

Generic.Formatting.SpaceAfterNot takes a property spacing since phpcs3.4.0, needs check if it could be used here

Umherirrender triaged this task as Medium priority.

Change 481530 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Enable Generic.Formatting.SpaceAfterNot with spacing 0

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

I run phpcs to detect the different cases:

Spacing=1Spacing=0Extension
1265AbuseFilter
134Cite
1250Echo
16GPGMail
157LdapAuthentication
117OAuthAuthentication
126PropertySuggester
157ReadingLists
12SimpleSAMLphp
1168TimedMediaHandler
16TrustedXFF
185WikimediaMaintenance
279PageTriage
2269SecurePoll
257ZeroBanner
363PagedTiffHandler
330ReplaceText
33SafeDelete
37UploadLocal
40Carp
536CommonsMetadata
67Memento
8435CirrusSearch
1248Math
1213SemanticDrilldown
284Arrays
34216LiquidThreads
42410WikiLexicalData

All other extensions does not have spacing=1

Uh, awesome. It looks like the MediaWiki-extensions-Arrays might be the only codebase that intentionally uses spaces after ! operators. All others – even if some of the numbers are high – look like mistakes or situations where different developers used inconsistent formatting.

I wrote a comment at https://gerrit.wikimedia.org/r/481530 questioning if adding this rule would make some developers angry. I feel the table above gives an answer: No. It's fine, especially since it's auto-fixable.

Change 481530 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Enable Generic.Formatting.SpaceAfterNot with spacing 0

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