-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
Splitting the Core ruleset into Code style & Core #740
Comments
N.B. One thing we should be aware off when this will be pulled, is that sniffs which now rely in their token walking on code being formatted according to the WP code style rules will no longer work as expected for those rulesets where the code style rules won't be included. In effect this means that all (non-code style) sniffs will have to be reviewed critically for this. Example of what could go wrong: // Line taken from the `is_in_isset_or_empty()` method in WordPress.Sniff
return in_array( $this->tokens[ ( $open_parenthesis - 1 ) ]['code'], array( T_ISSET, T_EMPTY ), true ); This relies on the code being formatted like so: if ( isset( $something ) && ! empty( $something['key'] ) ) {} And will not catch code formatted like this - note the extra space before the open parenthesis for isset/empty: if ( isset ($something) && ! empty ($something['key']) ) {} The original line would have to be rewritten to read like this for the functionality to be maintained: $previous_token = $this->phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true);
return in_array( $this->tokens[ $previous_token ]['code'], array( T_ISSET, T_EMPTY ), true ); |
On the whole, I think this idea makes sense. But I think we need to be clear about exactly why this is useful/who this benefits. People who are contributing to WordPress core will still need to use the I doubt that many people who are using WordPress code styles will want to exclude all of the best practices, but maybe I'm wrong. It seems that mainly this is geared toward people who don't want the code-style rules but do want to know about best practices, like i18n, SQL escaping, etc. However, those best practices that people who don't care about code-style are likely to care about are a small minority of the rules. I doubt they'll worry about the small stuff, just the larger stuff like i18n and query formatting, etc. Just like 3-5 sniffs. So it would be really easy for these picky people to pick what they want and leave the rest. If that's the case, would we really be splitting this as they would want or not? I get the feeling that it would start some debate about what goes where, and people would still end up excluding rules from the best practices ruleset. As far as I can see, the main benefit to splitting this ourselves rather than each person having to construct their own ruleset is that this way they don't have to update their custom ruleset each time WPCS is updated. They'll automatically get the best practice (or code-style) sniffs based on what they want. I'm just not sure that best practices is really going to offer them exactly what they want. If they don't care about the code styles in the handbook, they probably aren't going to care about all of the best practices in the handbook. So if the rule as to what is So again, I'm not against this, it sounds very reasonable, but I'm not entirely convinced where to split this to be the most help to people. I think really we need some more input from the community to know if there is a pattern that has emerged in what people include/exclude as far as the |
@JDGrimes Thanks for your thoughtful response. Anyone got ideas of who we should ping for opinions on whether or not to split the ruleset ? |
Since #1067 provides an example use-case, I'm happy for us to go ahead with this. 👍 |
I previously said:
However, I now do think there is value, as folks could choose to follow PSR-2, or PSR-12, or some company code style rules, but can also use a As @jrfnl proposed, having the default be to include the code style checks, then we're still recommended that they be followed, but we make it more flexible for developers to at least embrace the really important bits of the checks. |
Closing as killed by #1157 (proposal 1) not getting enough support. |
Following up on #676:
I've made a start at splitting the ruleset, but would like a second opinion on what should go where.
N.B. the below list includes rules which are currently not covered yet!
Current proposal:
Opinions ?
Practical implications
From a practical point of view, I think we'll need to split the ruleset into two new rulesets - I propose
WordPress-Code-Style
andWordPress-Core-Basic
(or should this beWordPress-Core-Best-Practices
?).WordPress-Core
would then include both.WordPress-VIP
would only includeWordPress-Core-Basic
The reason for this is that while we can include a standard and subsequently exclude all rules coming from a specific other standard, as the rules contained in the WP rulesets come from a lot of different standards, this will not work smoothly AFAICS.
By splitting it into two new rulesets, we can overcome this.
The text was updated successfully, but these errors were encountered: