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

Make best practice sniffs code-style independent #763

Closed
jrfnl opened this issue Jan 1, 2017 · 1 comment
Closed

Make best practice sniffs code-style independent #763

jrfnl opened this issue Jan 1, 2017 · 1 comment

Comments

@jrfnl
Copy link
Member

jrfnl commented Jan 1, 2017

There are a number of sniffs which currently walk the token tree presuming that code complies with the WP code style rules.
The net end-result of this is that the messages from these sniffs will not be thrown for code which does not comply with the WP code style rules.
As VIP plugins as well as themes generally don't have to comply with the WP code style, but do have to comply with a lot of best practices, this means that important messages might be missed.

As a secondary result, it also means that an initial run against the WP rulesets might not show all messages and new messages might start to get thrown only once code style issues have been fixed.

I would suggest we should review all (non-code style specific) sniffs for these kind of issues and improve them where necessary.

Particular attention should be paid to:

  • Object/Function/Namespace name compares using strpos(), preg_match() or a strict compare. These are all case-insensitive in PHP so should be compared as such.
  • If constant name compares are being done and the define() function is checked, it should be checked that the third parameter $case_insensitive is either not passed or passed a false, otherwise a case-insensitive name check is needed.
  • Sniffs doing token "calculations" ( $token + 1 ) instead of using findNext/Previous() in combination with Tokens::$emptyTokens
@jrfnl
Copy link
Member Author

jrfnl commented Dec 2, 2022

I believe this has been addressed by now in most sniffs in the codebase, safe for one or two. The AbstractArrayAssignmentRestrictionsSniff comes to mind as one of the exceptions.

I'll keep an eye out for these kind of things when going through the sniffs anyway to upgrade them for Utils/PHP 8.x, but suggest we close this issue as "fixed".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant