-
Notifications
You must be signed in to change notification settings - Fork 58
Implement CS checking based on the WP_CLI_CS ruleset
#156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5b6f22a to
21e20b6
Compare
|
Remaining issues list: Once these issues have been resolved, either by fixing them, whitelisting individual issues or pinging me to adjust the ruleset, this PR will need to be rebased. After that it can be marked |
21e20b6 to
f2e4ebb
Compare
... as that version contains the new WPCliCS PHPCS standard.
* `.distignore`: no need to distribute the phpcs/phpunit config files.
* `.gitignore`: Allow devs to overwrite config files for PHPUnit and PHPCS
- The `.dist` files should be committed. However, for their personal use, devs can overrule those files with versions without `.dist`.
Those personal versions should never be committed.
As a side-note: for PHPCS, having a personal version while still using the original `.dist` file is made very easy, as you can just import the `.dist` file as a starting point, like so:
```xml
<?xml version="1.0"?>
<ruleset name="WP-CLI">
<rule ref="./phpcs.xml.dist"/>
</ruleset>
```
The file is completely documented in-line.
f2e4ebb to
e09e5e9
Compare
WP_CLI_CS ruleset
|
@jrfnl I pushed changes into this PR, it should now pass PHPCS. |
|
@schlessera Thanks. I have a couple of remarks, but it seems that @swissspidy already merged this.... |
| <exclude-pattern>*/src/IterableCodeExtractor\.php$</exclude-pattern> | ||
| </rule> | ||
|
|
||
| <!-- Whitelist variable names for classes that extend a PSR-2 package. --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use the specific configuration for this sniff to allow for these.
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#mixed-case-property-name-exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrfnl There was actually three different ones that were triggered, so I didn't bother listing them individually anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with that is that now newly introduced variable name violations in these files will no longer be reported, which is why I suggested using the property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm sorry, I should have actually read the link you posted. So instead of whitelisting against the rule, I should whitelist against the individual variable names.
Yes, I agree that that makes more sense, I'll push a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a look now at the files in question. This is what I see:
src/JSFunctionsScanner.php: I see no reason why the$extractCommentsproperty hasn't been renamed. It is aprivateproperty, so independent of the parent class. Why should this not comply ?src/MapCodeExtractor.php:$mapObjectis a function local variable, so it is perfectly safe to rename it. Why should this not comply ?src/MapCodeExtractor.php:sourcesContentis a property and comes from an external source. This can be whitelisted via the above.src/PhpFunctionsScanner.php:$extractedCommentis a function local variable, so it is perfectly safe to rename it. Why should this not comply ?
So basically this would be the ruleset config. Everything else should just be renamed:
<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="customPropertiesWhitelist" type="array">
<element value="sourcesContent"/>
</property>
</properties>
</rule>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I did these changes in #161
|
Whoops 🙃 Sorry about that. |
|
|
||
| foreach ( $matchers as $path_or_file ) { | ||
| $pattern = preg_quote( str_replace( '*', '__wildcard__', $path_or_file ) ); | ||
| $pattern = preg_quote( str_replace( '*', '__wildcard__', $path_or_file ), '/' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This disregards the bug reported in #117 - MBString regexes don't use delimiters and using preg_quote() on a regex to be passed to one of the MBString regex functions is risky and potentially buggy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrfnl Noted. We have the bug report open, so the issue won't be forgotten. I assume it is a bigger refactor to fix this, though. We're not worse off for now with the above code, as the bug was detected and recorded for a later fix.
Just post the remarks here, and I'll follow up in a separate PR as needed. |
|
I just have ;-) |
|
I replied to them. Do you agree with my assessments, or is there something I did not consider? |
|
@schlessera I agree with the one, not so much the other ;-) |
|
The I'm happy to look into actually fixing the bug for this release if I end up having time once the blocking bugs are fixed. This one hasn't bitten anyone yet and doesn't block the release, so it is low priority for me right now. |


Composer: use wp-cli-tests ^2.1
... as that version contains the new WPCliCS PHPCS standard.
.gitignore/.distignore: ignore phpcs/phpunit config files
.distignore: no need to distribute the phpcs/phpunit config files..gitignore: Allow devs to overwrite config files for PHPUnit and PHPCS.distfiles should be committed. However, for their personal use, devs can overrule those files with versions without.dist.Those personal versions should never be committed.
As a side-note: for PHPCS, having a personal version while still using the original
.distfile is made very easy, as you can just import the.distfile as a starting point, like so:PHPCS: add a ruleset for this project
The file is completely documented in-line.
Fixes #158
Related wp-cli/wp-cli#5179