Page MenuHomePhabricator

Provide Codesniffer rules to enforce "short" type definitions (int/bool, not integer/boolean)
Closed, ResolvedPublic

Description

Per @matmarex, apparently we normally use int not integer and bool not boolean; would be nice to enforce this (and any other similar ones).

Event Timeline

Legoktm renamed this task from Provide an MWCS rule to enforce "short" type definitions to Provide an MWCS rule to enforce "short" type definitions: int and bool, not integer and boolean.Sep 9 2016, 2:38 AM
Legoktm subscribed.

I looked upstream and the only thing I could find was https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/666

So we'll probably have to write our own.

I have plans to change the sniff to use the short data types by default so I don't think there is any need for an option. This will only be in the 3.0 version - I don't want to change this functionality in 2.x.

Renaming task to avoid confusing with WMCS.

Krinkle renamed this task from Provide an MWCS rule to enforce "short" type definitions: int and bool, not integer and boolean to Provide a Codesniffer rule to enforce "short" type definitions: int and bool, not integer and boolean.May 26 2017, 10:04 PM

So I believe there are two places this needs to be done: type casts and documentation blocks. Anywhere else?

Change 362171 had a related patch set uploaded (by Legoktm; owner: Legoktm):
[mediawiki/tools/codesniffer@master] Add sniff to verify type-casts use the short form (bool, int)

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

Change 362171 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Add sniff to verify type-casts use the short form (bool, int)

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

Change 362593 had a related patch set uploaded (by Legoktm; owner: Legoktm):
[mediawiki/tools/codesniffer@master] Sniff that the short type form is used in @return tags

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

In addition to @return, we should handle @param as well.

Change 362593 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Sniff that the short type form is used in @return tags

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

What about e.g. double instead of float?

Along with @return it should also check @param or @var

Krinkle renamed this task from Provide a Codesniffer rule to enforce "short" type definitions: int and bool, not integer and boolean to Provide Codesniffer rules to enforce "short" type definitions (int/bool, not integer/boolean).Jul 25 2017, 6:02 PM
Krinkle triaged this task as Medium priority.
Krinkle removed a project: Patch-For-Review.

The sniff should also check case insensitive and with a colon after it, have seen "@return Boolean: Some comment" in extension RSS

Change 370232 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Enforce "short" type definitions on @param in comments

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

Have seen "@return integer|bool", which is not covered - also not from my patch set for @param

The check is not run for existing @return/@param of private functions, because the sniff is returning in that case too early for this check. In my opinion if a @param/@return exists on private function it should be checked.

Change 370232 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Enforce "short" type definitions on @param in comments

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

The check is not run for existing @return/@param of private functions, because the sniff is returning in that case too early for this check. In my opinion if a @param/@return exists on private function it should be checked.

It is also not run for function of interface or for abstract functions, which can have @return to check.

Change 373954 had a related patch set uploaded (by Umherirrender; owner: Umherirrender):
[mediawiki/tools/codesniffer@master] Enforce "short" type definitions in multi types in function comments

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

Change 373954 merged by jenkins-bot:
[mediawiki/tools/codesniffer@master] Enforce "short" type definitions in multi types in function comments

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

In https://gerrit.wikimedia.org/r/#/c/375285/1/ShortUrl.utils.php "@return Boolean" was not changed to the short form. I think it's because the B was capitalized? Maybe lowercase forms of all primitive types (array, string, etc) should be a separate task?

In https://gerrit.wikimedia.org/r/#/c/375285/1/ShortUrl.utils.php "@return Boolean" was not changed to the short form. I think it's because the B was capitalized? Maybe lowercase forms of all primitive types (array, string, etc) should be a separate task?

T172836 exists for that

I would say that all work is done here. Feel free to create a new task, if anything is open.