Skip to content
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

Switch to sirbrillig/phpcs-variable-analysis #450

Merged
merged 1 commit into from
Jul 13, 2020

Conversation

GaryJones
Copy link
Contributor

Introduces a new dependency of sirbrillig/phpcs-variable-analysis which is a more maintained version of the existing VariableAnalysis sniff in VIPCS.

The new sniff is added to the WordPressVIPMinimum ruleset. WordPress-VIP-Go ruleset inherits this, and maintains its dropping of the severity for UnusedVariable and UndefinedVariable violations.

The ruleset tests have set the previously undefined variables (or changed some variable names), so that violations on each line are still specific to the thing being tested, and doesn't include extra violations due to the use of throwaway variables.

One of the reasons for changing was the previously false positive with respect to the use of $this inside closures inside class methods. A ruleset test has been added to cover this, and it correctly does not get flagged in the ruleset test.

The old VariableAnalysis has been marked as deprecated, until it can be removed in the next major release of VIPCS. This will stop any breakage of setups which reference WordPressVIPMinimum.Variables.VariableAnalysis in a custom ruleset. If called, it throws a warning, and then passes control to the new VariableAnalysis sniff. The deprecation notice is excluded if the sniff is not explicitly included, and the duplicate violation messages are also silenced.

The previously used VariableAnalaysisHelper.php has been removed completely, as no-one should have been referencing that directly.

Fixes #449.

WordPressVIPMinimum/ruleset.xml Show resolved Hide resolved
david-binda
david-binda previously approved these changes Nov 4, 2019
Copy link
Contributor

@david-binda david-binda left a comment

Choose a reason for hiding this comment

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

I added the custom fork of the upstream repository to VIPCS due to backward compatibility, as we have been on old version of PHPCS and WPCS for a long time.

That said, if we can switch to the upstream repository now, let's do it!

I haven't really tested this change, but can see that the tests have been adjusted. So as long as those are all still passing, :shipit:

One question, tho. WordPressVIPMinimum.Variables.VariableAnalysis.UndefinedVariable becomes VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable. Is there a way to create an "alias", so this won't break the // phpcs:ignore WordPressVIPMinimum.Variables.VariableAnalysis.UndefinedVariable comments?

@GaryJones
Copy link
Contributor Author

Is there a way to create an "alias", so this won't break the // phpcs:ignore WordPressVIPMinimum.Variables.VariableAnalysis.UndefinedVariable comments?

Not as far as I know. The deprecation handles references in custom rulesets, but not ignore / disable references.

@GaryJones
Copy link
Contributor Author

Noting that VA 2.6.3+ requires PHP 5.6, so a composer install may need to ignore platform requirements to be able to test PHP 5.4 and PHP 5.5.

@GaryJones GaryJones force-pushed the feature/variable-analysis branch from 6d33c19 to f3ed636 Compare July 11, 2020 15:28
@GaryJones GaryJones requested a review from a team as a code owner July 11, 2020 15:28
@GaryJones GaryJones force-pushed the feature/variable-analysis branch 2 times, most recently from 4097c7a to d1a4c29 Compare July 11, 2020 15:49
@GaryJones
Copy link
Contributor Author

GaryJones commented Jul 11, 2020

Refactored and fixed up tests and updated to use VA ^2.8.2. Currently failing on PHP 5.4 and PHP 5.5 Travis jobs.

I tested ignoring platform requirements so that VA could be installed on PHP 5.4 and 5.5, but a) it fails due to the PHP 5.6+ code in VA, and b) ignoring platform requirements make no sense when this is a non-dev dependency.

I suspect my comment isn't going to result in VA moving back to PHP 5.4 due to the code in it, so we'll have to bump the minimum PHP for VIPCS back up (having only just dropped it) to PHP 5.6.

@GaryJones
Copy link
Contributor Author

Before merging, we should check the changes here against the proposals made in #449, or at least open a follow-up PR which the extra changes, within the same release.

@sirbrillig
Copy link
Member

I suspect my comment isn't going to result in VA moving back to PHP 5.4 due to the code in it, so we'll have to bump the minimum PHP for VIPCS back up (having only just dropped it) to PHP 5.6.

Surprise! 😁 sirbrillig/phpcs-variable-analysis#191

I'll still need to backport it to the 2.x branch though. Coming soon...

@sirbrillig
Copy link
Member

@GaryJones
Copy link
Contributor Author

@sirbrillig You are a wonderful human - thank you!

@GaryJones GaryJones force-pushed the feature/variable-analysis branch from d1a4c29 to 298dcc9 Compare July 13, 2020 13:58
@GaryJones GaryJones marked this pull request as ready for review July 13, 2020 14:05
Introduces a new dependency of `sirbrillig/phpcs-variable-analysis` which is a more maintained version of the existing `VariableAnalysis` sniff in VIPCS.

Requires ^2.8.3, since 2.6.3 – 2.8.2 had PHP 5.6 as the minimum version, but 2.8.3 changes it down to PHP 5.4 as the minimum.

The new sniff is added to the `WordPressVIPMinimum` ruleset. `WordPress-VIP-Go` ruleset inherits this, and maintains its dropping of the severity for `UnusedVariable` and `UndefinedVariable` violations.

The ruleset tests have set the previously undefined variables (or changed some variable names), so that violations on each line are still specific to the thing being tested, and doesn't include extra violations due to the use of throwaway variables.

One of the reasons for changing was the previously false positive with respect to the use of `$this` inside closures inside class methods. A ruleset test has been added to cover this, and it correctly does not get flagged in the ruleset test.

The old `VariableAnalysis` has been marked as deprecated, until it can be removed in the next major release of VIPCS. This will stop any breakage of setups which reference `WordPressVIPMinimum.Variables.VariableAnalysis` in a custom ruleset. If called, it throws a warning, and then passes control to the new VariableAnalysis sniff. The deprecation notice is excluded if the sniff is not explicitly included, and the duplicate violation messages are also silenced.

The previously used `VariableAnalaysisHelper.php` has been removed completely, as no-one should have been referencing that directly.

Fixes #449.
@GaryJones GaryJones force-pushed the feature/variable-analysis branch from 298dcc9 to a896729 Compare July 13, 2020 14:09
@rebeccahum rebeccahum merged commit bfc7fc5 into develop Jul 13, 2020
@rebeccahum rebeccahum deleted the feature/variable-analysis branch July 13, 2020 15:10
franciscodua pushed a commit to codacy/codacy-codesniffer that referenced this pull request Sep 9, 2020
Unused variable was deprecated on this version Automattic/VIP-Coding-Standards#450
Note: users that have this pattern enabled will see a deprecation notice
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.

Replace VariableAnalysis Sniff with VariableAnalysis package
4 participants