Last modified: 2014-08-16 12:33:08 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T50450, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 48450 - CodeSniffer Generic.Formatting.SpaceAfterCast.NoSpace is incorrect
CodeSniffer Generic.Formatting.SpaceAfterCast.NoSpace is incorrect
Status: RESOLVED FIXED
Product: Wikimedia
Classification: Unclassified
Continuous integration (Other open bugs)
wmf-deployment
All All
: Low enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-05-14 13:01 UTC by Siebrand Mazeland
Modified: 2014-08-16 12:33 UTC (History)
6 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Siebrand Mazeland 2013-05-14 13:01:32 UTC
CodeSniffer currently tries to enforce a space after a cast[2].

Our documentation states: "When type casting, do not use a space within the cast operator or after the cast"[1]

Please update the CodeSniffer configuration to issue the correct warning.

[1] https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP
[2] https://integration.wikimedia.org/ci/job/mwext-Translate-phpcs-HEAD/1291/console
Comment 1 Antoine "hashar" Musso (WMF) 2013-05-14 13:18:26 UTC
Been done with https://gerrit.wikimedia.org/r/#/c/45140/

then reverted with https://gerrit.wikimedia.org/r/#/c/45142/  which actually cause the issue.

The SpaceAfterCast has been readded by Timo in https://gerrit.wikimedia.org/r/#/c/58637/
Comment 2 Siebrand Mazeland 2013-06-03 21:20:46 UTC
Timo, can you please explain why this is closed WORKSFORME? See https://gerrit.wikimedia.org/r/#/c/66558/ where https://integration.wikimedia.org/ci/job/mwext-Translate-phpcs-HEAD/1361/console throws an error on https://gerrit.wikimedia.org/r/#/c/66558/2/tag/TranslateDeleteJob.php:

73: ERROR A cast statement must be followed by a single space / Generic.Formatting.SpaceAfterCast.NoSpace
73: $pages = (array)$cache->get( wfMemcKey( 'pt-base', $base ) );

This was a few hours ago.
Comment 3 Krinkle 2013-06-03 21:26:59 UTC
Yes, that's by design.

Our code had mostly a 50/50 between cast with and without a space afterwards.

There was no explicit rule either way, and we'll have to make changes either way.

I made a judgement call and believe that in our coding style it makes most sense to have a space there. Therefor I removed the rule in phpcs that considered code with a space afterwards to be a violation and instead configured it the other way around.
Comment 4 Siebrand Mazeland 2013-06-04 06:42:06 UTC
(In reply to comment #3)
> Yes, that's by design.
> 
> Our code had mostly a 50/50 between cast with and without a space afterwards.
> 
> There was no explicit rule either way, and we'll have to make changes either
> way.
> 
> I made a judgement call and believe that in our coding style it makes most
> sense to have a space there. Therefor I removed the rule in phpcs that
> considered code with a space afterwards to be a violation and instead
> configured it the other way around.

Our docs say otherwise, and despite your consistent replies here, you have not made an effort to remedy the inconsistencies between the checker and the docs.
Comment 5 Antoine "hashar" Musso (WMF) 2013-06-04 12:19:23 UTC
We had that debate at the beginning of 2013.

When type casting, do not use a space after the cast:

 (int)$foo;

http://www.mediawiki.org/w/index.php?title=Manual:Coding_conventions/PHP&diff=652478&oldid=648613


Later improved with code to not use (aka anything with spaces):

 ( int )$bar;
 ( int ) $bar;
 ( int ) $bar;

http://www.mediawiki.org/w/index.php?title=Manual:Coding_conventions/PHP&diff=674672&oldid=673901


Using the standard from mediawiki/tools/codesniffer.git at commit e1de64e4 , PHPCs processing gives out:

 (int)$foo;   // A cast statement must be followed by a single space
 ( int )$bar; // A cast statement must be followed by a single space
 ( int ) $bar;  // considered valid, should not
 ( int ) $bar;  // considered valid, should not

That is happening since https://gerrit.wikimedia.org/r/#/c/58637/  which did the following change:

-       <rule ref="Generic.Formatting.NoSpaceAfterCast" />
+       <rule ref="Generic.Formatting.SpaceAfterCast" />


We need to revert it again, aka like what I did in https://gerrit.wikimedia.org/r/#/c/45142/ :

-       <rule ref="Generic.Formatting.SpaceAfterCast" />
+       <rule ref="Generic.Formatting.NoSpaceAfterCast" />
Comment 6 Gerrit Notification Bot 2013-06-04 12:25:19 UTC
Related URL: https://gerrit.wikimedia.org/r/66961 (Gerrit Change I641535209fd477e7d56d8659015bb9c66f10ac68)
Comment 7 Gerrit Notification Bot 2013-06-04 13:28:29 UTC
Related URL: https://gerrit.wikimedia.org/r/66964 (Gerrit Change Ied10f203af5dcff45893bb0246cb6a0469728cb3)
Comment 8 Krinkle 2013-06-04 13:53:22 UTC
phpcs no longer warns about (type) casting now.
Comment 9 Antoine "hashar" Musso (WMF) 2013-06-04 14:09:15 UTC
Timo that bug is a regression, we used to have that sniff in and https://gerrit.wikimedia.org/r/#/c/66961/ reintroduce it.
Comment 10 Gerrit Notification Bot 2013-11-06 16:21:57 UTC
Change 66961 abandoned by Hashar:
Enable Generic.Formatting.NoSpaceAfterCast

https://gerrit.wikimedia.org/r/66961
Comment 11 Siebrand Mazeland 2013-11-06 20:18:55 UTC
I think the status should be "reopened" now, per comment 9. It's pretty confusing that the bot changes bug status to "patch to review" when a patch is abandoned. I'll have to change status twice to get there...
Comment 12 Siebrand Mazeland 2013-11-06 20:19:22 UTC
Hmm, can't get to reopened, so will leave this at new... Messed up...
Comment 13 Addshore 2014-08-12 10:24:56 UTC
So what is the state here and what do we want?
Comment 14 Antoine "hashar" Musso (WMF) 2014-08-12 19:39:58 UTC
Per Timo Comment #8 the rule is abandoned so we do not enforce one way or another.

My patch https://gerrit.wikimedia.org/r/#/c/66961/ was to reintroduce one of the style and Timo and I agreed to abandon it (see discussion on Gerrit change).


I guess we can mark this bug as FIXED. The fix being that we abandoned that sniff entirely.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links