Skip to content

Conversation

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Apr 17, 2019

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
    • 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 version="1.0"?>
<ruleset name="WP-CLI">
    <rule ref="./phpcs.xml.dist"/>
</ruleset>

PHPCS: add a ruleset for this project

The file is completely documented in-line.

Fixes #158

Related wp-cli/wp-cli#5179

@jrfnl jrfnl force-pushed the feature/use-phpcs branch 2 times, most recently from 5b6f22a to 21e20b6 Compare April 17, 2019 15:24
@jrfnl
Copy link
Contributor Author

jrfnl commented Apr 17, 2019

Remaining issues list:
20190417-phpcs-result-i18n.txt

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 Ready for review and the build should go green.

@jrfnl jrfnl force-pushed the feature/use-phpcs branch from 21e20b6 to f2e4ebb Compare April 17, 2019 16:34
jrfnl added 3 commits April 18, 2019 21:41
... 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.
@jrfnl jrfnl force-pushed the feature/use-phpcs branch from f2e4ebb to e09e5e9 Compare April 19, 2019 13:52
@schlessera schlessera changed the title Implement CS checking based on the WPCliCS ruleset Implement CS checking based on the WP_CLI_CS ruleset Apr 20, 2019
@schlessera schlessera marked this pull request as ready for review April 24, 2019 15:14
@schlessera schlessera requested a review from a team as a code owner April 24, 2019 15:14
@schlessera schlessera added this to the 2.1.1 milestone Apr 24, 2019
@schlessera
Copy link
Member

@jrfnl I pushed changes into this PR, it should now pass PHPCS.

@swissspidy swissspidy merged commit e4edd2f into wp-cli:master Apr 24, 2019
@jrfnl
Copy link
Contributor Author

jrfnl commented Apr 24, 2019

@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. -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that only seems to work for properties, not variables. Am I missing a specific notation?
Here's what seems to work for the properties:
Image 2019-04-24 at 5 57 28 PM
This leaves me with the following errors:
Image 2019-04-24 at 5 58 10 PM

Copy link
Contributor Author

@jrfnl jrfnl Apr 24, 2019

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:

  1. src/JSFunctionsScanner.php: I see no reason why the $extractComments property hasn't been renamed. It is a private property, so independent of the parent class. Why should this not comply ?
  2. src/MapCodeExtractor.php: $mapObject is a function local variable, so it is perfectly safe to rename it. Why should this not comply ?
  3. src/MapCodeExtractor.php: sourcesContent is a property and comes from an external source. This can be whitelisted via the above.
  4. src/PhpFunctionsScanner.php: $extractedComment is 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>

Copy link
Member

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

@swissspidy
Copy link
Member

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 ), '/' );
Copy link
Contributor Author

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.

Copy link
Member

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.

@schlessera
Copy link
Member

@schlessera Thanks. I have a couple of remarks, but it seems that @swissspidy already merged this....

Just post the remarks here, and I'll follow up in a separate PR as needed.

@jrfnl
Copy link
Contributor Author

jrfnl commented Apr 24, 2019

I just have ;-)

@jrfnl jrfnl deleted the feature/use-phpcs branch April 24, 2019 15:43
@schlessera
Copy link
Member

I replied to them. Do you agree with my assessments, or is there something I did not consider?

@jrfnl
Copy link
Contributor Author

jrfnl commented Apr 24, 2019

@schlessera I agree with the one, not so much the other ;-)

@schlessera
Copy link
Member

The mb_ereg/preg_quote mismatch, I assume.

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.

schlessera pushed a commit that referenced this pull request Jan 6, 2022
Implement CS checking based on the `WP_CLI_CS` ruleset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adopt and enforce new WP_CLI_CS standard

3 participants