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

Proposal for restructuring the rulesets & some of the sniffs #1157

Closed
jrfnl opened this issue Sep 22, 2017 · 72 comments
Closed

Proposal for restructuring the rulesets & some of the sniffs #1157

jrfnl opened this issue Sep 22, 2017 · 72 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Sep 22, 2017

As a follow up on issues #676, #740, #1067, #1156, I would like to propose a restructuring.

I'm opening this as a separate issue as I would like to get as many eyes as possible on this proposal and would like a (preferably unanimous) 👍 / 👎 / 👀 (= seen it, no opinion either way) vote from all the @WordPress-Coding-Standards/wpcs-admins on whether to go ahead with this. /cc @grappler @david-binda

Please vote separately for proposal 1 and proposal 2.

TL;DR

Proposal to split the rulesets up into additional separate rulesets for codestyle and best practices and move some of the sniffs around to make adoption of the best practice sniffs from WPCS easier for the wider WP community.


Justification

While WPCS is based on the Core handbook and originally was probably primarily intended for usage by Core, the WordPress infrastructure is a lot wider than just Core and the way the current rulesets are set up are hindering adoption of WPCS in the wider WordPress community.

Example usecases

  • Plugin/Theme developer preferring to use PSR2 for codestyle, but still wanting the benefits of the WPCS best practice sniffs - see New PSR2 + WP best practices ruleset #1067
  • Plugin/Theme developer choosing not to support PHP 5.2, but setting the minimum at for instance PHP 5.6 and wanting to check the code style of modern PHP constructs in a way that closely matches the WP code style.
  • VIP/Plugin/Theme reviewers wanting to just and only check whether plugins/themes comply with best practices without being inundated by messages about code style issues - also see Slidedeck: Using WPCS to review plugins and themes

Proposal 1: changing the rulesets

Adding 7 new (subset) rulesets:

New Ruleset Notes
WordPress-Core-Style See #740 for an initial proposal (albeit slightly outdated)
WordPress-Extra-Style Would contain sniffs like Squiz.Scope.MethodScope, Generic.PHP.Syntax and WordPress.Classes.ClassInstantiation
WordPress-Modern-Style Would contain sniffs like PSR2.Namespaces.NamespaceDeclaration, but also the ReturnTypeSniff from PR #1084 and the use declaration sniffs I've been working on to fix #1071
WordPress-Core-Best-Practices See #740 for an initial proposal
WordPress-Extra-Best-Practices Would contain nearly everything else now in Extra
WordPress-Modern-Best-Practices Could contain sniffs like WordPress.PHP.DiscourageGoto and sniffs checking for untestable code like the Generic.Metrics.NestingLevel and Generic.Metric.CyclomaticComplexity sniffs
WordPress-VIP-Requirements Would contain everything now in VIP, except for the inclusion of WordPress-Core

The existing rulesets would not change in functionality, but would now all be compound rulesets:

  • WordPress-Core = WordPress-Core-Style + WordPress-Core-Best-Practices
  • WordPress-Extra = WordPress-Core + WordPress-Extra-Style + WordPress-Extra-Best-Practices
  • WordPress-VIP = WordPress-Core + WordPress-VIP-Requirements

Additionally an extra compound ruleset would be introduced:

  • WordPress-Extra-Modern = WordPress-Extra + WordPress-Modern-Style + WordPress-Modern-Best-Practices

As far as I can see at this moment, the changes would not impact the WordPress-Docs ruleset.

Impact analysis

  • If done correctly, the existing rulesets will still work as before with possibly just one or two sniffs being removed from Extra and moved to Modern.
  • End-users of WPCS using a custom ruleset should review their own ruleset(s) to determine whether the ruleset can be optimized after this change.
  • A (hopefully large) number of users could benefit from switching over from using WordPress-Extra to WordPress-Extra-Modern

Pros

It will make maintenance of custom rulesets based on WPCS far more easy and more future-proof.

Cons

The downside of this change is that the amount of rulesets WPCS provides increases exponentially and this could be confusing to new users.
Extra attention will need to be paid to rewriting the Readme section explaining which rulesets are available and which should be used when.

Proposal 2: Moving some sniffs to other categories

There are a number of sniffs where the current category is historically grown, but a different category would be more intuitive and make including whole groups of sniffs easier.

Sniff Old Category Proposed New Category Notes
DirectDatabaseQuery VIP DB Errors should probably be changed to warnings and the messages adjusted (and changed back for VIP from the ruleset) .
SlowDBQuery VIP DB
PreparedSQL WP DB
DontExtract Functions PHP
NonceVerification CSRF Security
EscapeOutput XSS Security
PluginMenuSlug VIP Security Should probably become a warning and only upped to error for VIP.
ValidatedSanitizedInput VIP Security
CronInterval VIP WP Errors should probably be changed to warnings and the messages adjusted (and changed back for VIP from the ruleset) + It would be good to make the time which is being checked for (currently 15 minutes) configurable.
PostsPerPage VIP WP Or rather, this sniff should probably be split into two sniffs: one in VIP checking for disabling of pagination, one in WP checking for high pagination limit.
TimezoneChange VIP WP

Impact analysis

This would be a breaking change for people including/excluding any of the affected sniffs in custom rulesets.
However, the break could be minimized by deprecating the old sniffs (with notification) and letting these extend the new sniffs for a limited period.

Pros

It will make it easier to include a whole category from a custom ruleset, rather than having to include individual sniffs.

Cons

It will be a BC break.

Planning

I would like to propose releasing WPCS 0.14.0 around the end of this month and having a dedicated 0.15.0 release soon after containing only those PRs necessary for the above proposed changes.


For those who've read this far: thank you for your attention and dedication to WPCS.
Opinions & feedback welcome!

@JDGrimes
Copy link
Contributor

👍 For proposal 2. I've thought before that things should be better organized, and although the BC breaks will be a pain, that's just another reason to do it sooner rather than later.

For proposal 1, I favor the general idea, but I'm not sure I understand the necessity of having Modern rulesets. Why can't the rules be included in the non-Modern versions? Anybody not using modern code just won't trigger those sniffs for the most part, right? Or is that not the case for some of the sniffs?

I think if we do these, dedicating a release to them is definitely a good idea.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 22, 2017

For proposal 1, I favor the general idea, but I'm not sure I understand the necessity of having Modern rulesets. Why can't the rules be included in the non-Modern versions? Anybody not using modern code just won't trigger those sniffs for the most part, right? Or is that not the case for some of the sniffs?

I was thinking that having a separate Modern set of rulesets would allow us to add sniffs like PSR1.Classes.ClassDeclaration (which demands that all classes must be in a namespace).
That would otherwise not be possible.

[Edit]: Maybe all non-blocking modern sniffs could just go into Extra and only blocking ones would go into Modern ? That might make the Modern ruleset quite small to start with, but I have little doubt that this will grown over time. Think: demanding type declarations in function declarations, favouring use statements over using FQNs in code etc

@JDGrimes
Copy link
Contributor

Maybe all non-blocking modern sniffs could just go into Extra and only blocking ones would go into Modern ?

That's what I was thinking as well. In general, it would be nice if the standard automatically progressed as a project evolved to using newer PHP features, rather than having to remember manually switch standards. (Though the blocking sniffs would unfortunately still need to isolated, I guess.)

That might make the Modern ruleset quite small to start with, but I have little doubt that this will grown over time. Think: demanding type declarations in function declarations, favouring use statements over using FQNs in code etc

This makes me think that possibly people will want different levels of modernity. I mean, some people will want namespaces long before they want to mandate type declarations. And fragmenting this further into sub-standards doesn't really seem like a good idea. So maybe we need to think about this some more.

In addition, I was also thinking that it might be better to use Legacy instead of Modern. In other words, rather than putting the modern code in a special standard, treat modern development as the baseline and exclude blocking rules that Core doesn't follow yet in a Legacy standard. I think that kind of makes more sense if we are going to include the non-blocking rules anyway. But I'm also thinking out loud here. 😄

@ntwb
Copy link
Member

ntwb commented Sep 23, 2017

Thumbs up for proposal 2 👍

For proposal 1 also a thumbs up 👍 though I'm not a fan of Modern, and to a lesser extent Legacy as the terminologies used.

_If I were a new user who has just discovered this repo after a quick glance I'd more than likely skim read the docs I'm pretty sure I might just go with Modern as I doubt I'd want Legacy from the good ol days. That would be a bad assumption and I'd probably have to revisit the docs to redress.

So, rather than using a time methodology to name these how about swapping out Modern for Next? My thinking here is "Next" meaning upcoming, moving sniffs from a "Next" ruleset to it's "Core" equivalent once approved and documented as a core coding standard.

Proposed Ruleset Alternative
WordPress-Core-Style WordPress-Core-Style
WordPress-Extra-Style WordPress-Extra-Style
WordPress-Modern-Style WordPress-Next-Style
WordPress-Core-Best-Practices WordPress-Core-Best-Practices
WordPress-Extra-Best-Practices WordPress-Extra-Best-Practices
WordPress-Modern-Best-Practices WordPress-Next-Best-Practices
WordPress-VIP-Requirements WordPress-VIP-Requirements

And change the newly introduced compound ruleset from WordPress-Extra-Modern to:
WordPress-Extra-Next = WordPress-Extra + WordPress-Next-Style + WordPress-Next-Best-Practices

ESLint also has a category of rules "Possible Errors" along with "Best Practices" and "Stylistic Issues"

Would it be worth considering moving the relevant sniffs to a WordPress-Core-Possible-Errors new compound ruleset and thenWordPress-Core = WordPress-Core-Style + WordPress-Core-Best-Practices + WordPress-Core-Possible-Errors ?

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

@ntwb Thanks for your response and your thoughts.

I'm not a fan of the "Next" terminology as in WordPress-Next-Best-Practices it sounds like "next best thing", i.e. second best, better not use, but I am open to other suggestions.

ESLint also has a category of rules "Possible Errors" along with "Best Practices" and "Stylistic Issues"

There are a number of sniffs which point out possible errors, but for WPCS, those are generally thrown as warnings, have whitelist flags and the message is also worded as such.
As far as I can remember, those are all contained in the Extra ruleset now, never in the Core ruleset.
I'm going to have a think about that one.

@tfrommen
Copy link
Member

tfrommen commented Sep 23, 2017

Lately, I am working more and more with PHPCS and WPCS, for example, for MultilingualPress (also the current stable legacy branch - ugh). Furthermore, I have been following discussion both here and in the Slack channel for a little while. Now, I would like to get involved here (more and more). 🙂 👋


In general, I like both proposals, or rather: the individual idea behind them.

I fully support the split between Stylistic Issues and Best Practices (which also happen to be ESLint categories, as already mentioned before).

Also, having a VIP-specific ruleset, VIP-Requirements, is great!

To be honest, I never (and here I am not talking only about the last weeks, because I had been working with PHPCS and WPCS already several times before) understood the Extra ruleset. To me, this always sounded like stuff that doesn't really belong somewhere else, or rather: you are not sure about where it does belong. Now, I absolutely do not like Extra-Style or Extra-Best-Practices rulesets. Not even talking about the names here... 😉

Furthermore, I neither support Modern rulesets, nor Next ones. It simply isn't clear what stuff is of modern or next (generation) nature, and what isn't. Also, the finer-grained names (e.g., Next-Best-Practices, Extra-Modern - or is it Modern-Extra?) ... well, they are just pretty awkward.

I would rather have something like WordPress-Style and WordPress-Best-Practices as base to be used for Core stuff, but also plugin/theme development. Core-specific additions then go into WordPress-Core-Style and WordPress-Core-Best-Practices, respectively.

Next, I would not have something like Modern(-*), but always assume the rulesets target state-of-the-art codebases. Where it makes sense, a Legacy(-*) variant may exist that extends the current/modern ruleset and includes/excludes rules as needed. This is what I am used to from various kinds of generation-based versioning, and what I am following myself.

This makes me think that possibly people will want different levels of modernity. I mean, some people will want namespaces long before they want to mandate type declarations. And fragmenting this further into sub-standards doesn't really seem like a good idea. So maybe we need to think about this some more.

I disagree. In my opinion, WPCS should follow state-of-the-art best practices. If people do not want or are not able to do this, they are free to either choose the legay variant, if it exists, and include rules as they see fit, or start with the state-of-the-art ruleset and then exclude stuff at will.

Summing up:

Ruleset Comment
WordPress WordPress-Docs + WordPress-VIP
WordPress-Best-Practices
WordPress-Core WordPress-Core-Best-Practices + WordPress-Core-Style
WordPress-Docs
WordPress-Style
WordPress-VIP WordPress-Core + WordPress-VIP-Requirements
WordPress-Core-Best-Practices WordPress-Best-Practices + custom rules°
WordPress-Core-Style WordPress-Style + custom rules°
WordPress-VIP-Requirements

°: both excluding (too modern) rules, and including/redefining rules.

Re: Proposal 2: Moving the mentioned sniffs into (new) categories makes perfect sense to me. 👍

Also, applying the changes in a dedicated release without doing anything else makes a lot of sense to me. Also, not sure I am stirring up a hornet's nest here, is there any reason the package is (still) in major version zero? I'd say, it's (way beyond) time to release, 1.0.0, and from now on adhere to Semantic Versioning!?!

Last but not least:

developer preferring to use PSR2 for codestyle, but still wanting the benefits of the WPCS best practice sniffs

While I agree that PSR-2 plugins/developers exist, and thus making life easier for them is a nice thing to be able to offer, I am in the PSR-4 camp, which has problems with the filename-specific sniffs/messages.
It would be good to not force plugin/theme developers to adhere to the WordPress-specific pseudo standard of class-wp-whatever.php/ WP_Whatever.

Thanks for reading.

Cheers,
Thorsten

@Rarst
Copy link
Contributor

Rarst commented Sep 23, 2017

— Do programmers have any superstitions?
— Yes, we call them “best practices”.

I am happy to see new use cases rise with increased adoption and I fully support increasing flexibility to accommodate them.

However I find multiple issues with specific suggested expansion, especially:

  • verbosity, we already have a lot of moving parts, seven more is incredibly complicated
  • semantics, what is Modern ? what is not modern? what is Style precisely?
  • overreach, Core code style works on foundation of written and maintained rules; I don’t consider purpose of this project to dictate what is "proper" or "best practice", especially in such murky areas like interoperability with non–WordPress styles

To accommodate described use cases my first thought was — subsplit WordPress-Core-Whitespace from WordPress-Core. This enables people to combine remainder with different white space styles (such as PSR ones) as well as exclude it for code quality rather than code style checks. From quick look through the issues this seems same/similar/close to WordPress-Core-Style in principle, but I don't like that name.

I think WordPress-Extra is, so far, reasonable container for sniffs outside of Core and VIP. Splitting it seems to add, rather than reduce confusion. From my experience in personal and work projects current structure is still quite reasonable to build custom ruleset on top of.

Proposal 1 👎 as currently written, 👍 for valid use cases to improve for
Proposal 2 👀

@JDGrimes
Copy link
Contributor

👋 @tfrommen Thanks for weighing in on this, and it is great to hear that you'd like to get more involved!

I like your idea of WordPress-Best-Practices and WordPress-Style, instead of qualifying them with Modern, Next, or whatever. Then only the Core rulesets need to be qualified with Core.

In regard to 1.0, this was last discussed in #718, but really should have a dedicated issue (previously #519, but we should open a new one).

@JDGrimes
Copy link
Contributor

The original proposal didn't mention this, but IMO the WordPress ruleset is both useless and confusing. I don't think we can completely get rid of it (for technical reasons), but many newbies assume that it is the one to use, so it should probably be a reasonable default (WordPress-Best-Practices + WordPress-Style) rather than including everything. Or is there actually some case in which it is useful as it is?

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

@tfrommen @Rarst Thank you both for adding your thoughts.

Based on the comments so far regarding including versus excluding sniffs, I think I need to clarify something about how rulesets work:

A ruleset is read from top to bottom and each standard/sniff/directive is added to PHPCS in order.

That also means that standards with conflicting directives - i.e. standard 1 excludes sniff A and error code B, while standard 2 includes sniff A and the sniff where errorcode B comes from, will lead to unpredictable results, or rather, will make the loading order of standards something everyone would need to learn about in detail to create their custom rulesets.

The short of it is: it's much easier to work with standards which include rules, than with standards which exclude rules/errorcodes.

In addition to this, while PHPCS 3.x supports including a single errorcode from a sniff, PHPCS 2.x does not and WPCS has chosen to continue support for PHPCS 2.x until summer 2018.
This means that the only way open to us to exclude something in ruleset 1 and overrule include it in ruleset 2 is currently to work with the severity of the sniff.

The above include vs exclude logic, has, of course, played a large part in how I came to the current proposal for the ruleset split.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

The original proposal didn't mention this, but IMO the WordPress ruleset is both useless and confusing. I don't think we can completely get rid of it (for technical reasons), but many newbies assume that it is the one to use, so it should probably be a reasonable default (WordPress-Best-Practices + WordPress-Style) rather than including everything. Or is there actually some case in which it is useful as it is?

Yes, I realized late that I didn't mention that ruleset in the original post.

IMHO the WordPress ruleset should stay as it is: everything.

There are two main reasons for that:

  1. Don't break expectations by re-purposing an existing ruleset
  2. I know of quite some projects - including quite a few I'm involved with myself - who purposely choose to use the WordPress ruleset and selectively exclude some sniffs. It saves time on ruleset maintenance as you will automatically get everything WPCS adds, in contrast to having to keep up with what's happening in this repo to figure out whether there are new sniffs you want to include.

@Rarst
Copy link
Contributor

Rarst commented Sep 23, 2017

@jrfnl I can't think of a single time this had been an issue for me in practice. Could you please provide a specific example maybe?

For the record I think my rulesets tend to be quite exclusion–centric, as it makes sense to me, e.g. my personal local ruleset basically starts with:

<rule ref="WordPress">
		<exclude name="WordPress.VIP" />
...
</rule>

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

@tfrommen I appreciate you taking the time to write down your thoughts and look forward to you getting more involved 👍 .

There is some background behind the Core and Extra rulesets which you might not be familiar with, so let me just try and add it into the mix:

I never understood the Extra ruleset. To me, this always sounded like stuff that doesn't really belong somewhere else, or rather: you are not sure about where it does belong.

The Core ruleset is only supposed to cover that what's literally stated in the WP PHP Coding Standards handbook. Nothing more.

However, on the one hand the handbook is far from comprehensive, there are a lot of areas which are not covered or only implied. On the other hand, there are industry standards and both PHP as well as WP best practices.

Tongue in cheek, I would go as far as saying that Extra currently contains everything we wish would be covered by the handbook, but isn't.

I disagree. In my opinion, WPCS should follow state-of-the-art best practices.

We can only hope that one day WP will, but until there is agreement on what those are - and even FIG can't seem to get agreement on a lot of these things - and the WP Core handbook is adjusted to that point, we will need separate rulesets.

@tfrommen
Copy link
Member

I only have the same experience as @Rarst (see the MultilingualPress links in my comment). However, I also always include only WordPress, and not two or more WPCS rulesets. And I add (and redefine) individual Sniffs (e.g., to allow dots in hook names).

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

@Rarst

For the record I think my rulesets tend to be quite exclusion–centric, as it makes sense to me

And you can do that in your custom ruleset without issue, because the current WPCS rulesets are inclusion based ;-)
That's the whole point. If the WPCS rulesets would be exclusion based, the chances that people will run into trouble when creating their custom rulesets (and the amount of time we'd need to spend on support and debugging) would be significantly higher.

@Rarst
Copy link
Contributor

Rarst commented Sep 23, 2017

If the WPCS rulesets would be exclusion based

Let me put it tad differently — I don't quite follow which part of discussion covers "exclusion-based" and so how original suggestion is preferable as opposed to it?

Does anything about my take on starting with separating WordPress-Core-Whitespace touch this?

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

Is anything about my take on starting with separating WordPress-Core-Whitespace touches on this?

I don't think WordPress-Core-Whitespace is an acceptable name as code style covers more than just and only whitespace, think "comma after each array item in a multi-line array".

Separating out just the style sniffs from Core is not enough as there are also style related rules in Extra.

If I understand you correctly, you propose something along the lines of:

  • Add WordPress-Core-Style ruleset
  • Let WordPress-Core ruleset include that ruleset + the individual best practice sniffs.

The sniffs used for the Core code style come both from WPCS as well as the PHPCS native upstream standards.

So if you are thinking that you could then do the below, you are mistaken as that would not exclude anything in practice.

<rule ref="WordPress-Core">
    <exclude name="WordPress-Core-Style"/>
</rule>

Excluding does not work for compound standards, only for actual sniff standards.

Exclusions like the below do work, but you would then need to manually exclude everything which is contained in Core-Style, so what's the point then of having that as a separate ruleset ?
This example basically just proves the need for separating the rulesets out.

<rule ref="WordPress-Core">
    <exclude name="Squiz"/>
    <exclude name="WordPress.Whitespace"/>
</rule>

@GaryJones
Copy link
Member

GaryJones commented Sep 23, 2017

For the record I think my rulesets tend to be quite exclusion–centric, as it makes sense to me, e.g. my personal local ruleset basically starts with:

That's also in my boilerplate as well.

Version numbering

We already do follow semantic versioning, and I'd consider 1.0.0 to be suitable once 41057 gets merged, as a way of ratifying everything that's been done to date.

Proposal 1 👎

While I like the intent, I do find the increase in rulesets that we'd be providing to be excessive.

I appreciate we want adoption outside of core, but I think we're already seeing that anyway (even WP-CLI just had a big update on using code standards) and don't think a re-organisation to make it more complex serves the purpose of increased adoption.

For those that want best practices, and not code style, or want checks for new PHP syntaxes, or not, or cheese instead of ham (basically, something more than WordPress with VIP excluded), then they can already do that. Don't want whitespaces? Fine, go ahead and amend your ruleset - that's not something we should support, since the handbook is quite specific about what is the WordPress Way when it comes to whitespace (and the opinionated Extra, including for "modern" syntax, covers the rest). A standard isn't much of a standard when there are so many variants out of the box.

What we have now is already simple and easy to follow - what the handbook says for code, what the handbook says for docs, what we consider to be best practice, and what VIP requires.

I don't feel there is sufficient value for the masses in the re-organisation, that those who do want subsets can't already apply themselves. More exemplar rulesets on the wiki ("How to follow best practices and ignore whitespace checks") would be more than sufficient, than actual PHPCS rulesets that we'd need to maintain.

Proposal 2 👍

Despite the BC-break (and another reason we've not yet gone to 1.0.0), I'd be in favour of this.

I love the idea of making some of the VIP sniffs be Extra, and letting VIP bump the severity where needed, so that VIP got slimmed down to the point where Automattic could take over this as a separate Standard / package (we've discussed this before). That's an example of simplifying of WPCS that may make adoption less frustrating for those new to PHPCS/WPCS.

As per my boilerplate, I'm all in favour of just using WordPress, and consider the VIP exclusion to be a hack until such point that it's no longer included.

@grappler
Copy link
Member

Proposal 1: changing the rulesets

Like I have mentioned before I support the separation of coding styles and best practices.

I would like to see the WordPress-VIP ruleset moved to https://github.com/Automattic/VIP-Coding-Standards/ some time in the future.

I do not fully understand all of the sniffs in the "Modern" ruleset but I suppose the sniffs are dependant on the version of PHP that is being supported in the project and code features that are going to used. Could we make sniffs detect the constraints or could could we define the rulesets based on the PHP versions?

Proposal 2: Moving some sniffs to other categories

This gets a 👍 from for the most part. I would like to see XSS.EscapeOutput renamed fully as the way the sniff is set up is to check all echo calls are escaped. Previous discussion at #748

I think there is place for a sniff that checks specific function calls if they are being escaped.

@Rarst
Copy link
Contributor

Rarst commented Sep 23, 2017

So if you are thinking that you could then do the below, you are mistaken as that would not exclude anything in practice.

Are you sure on this? I've just tried the following (note WordPress-VIP standard rather than WordPress.VIP sniffs mask in my earlier example) and exclusion worked:

<rule ref="WordPress">
		<exclude name="WordPress-VIP" />
</rule>
>cls && phpcs --standard=WordPress -e

The WordPress standard contains 121 sniffs
...

>cls && phpcs --standard=WordPress-VIP -e

The WordPress-VIP standard contains 75 sniffs
...

>cls && phpcs --standard=WordPress-Test -e

The WordPress-Test standard contains 46 sniffs
...

@JDGrimes
Copy link
Contributor

Fine, go ahead and amend your ruleset - that's not something we should support, since the handbook is quite specific about what is the WordPress Way when it comes to whitespace (and the opinionated Extra, including for "modern" syntax, covers the rest). A standard isn't much of a standard when there are so many variants out of the box.

This was definitely my thinking before. Am I correct in thinking that most of the proposed rulesets could in theory be maintained in a separate project? In other words, if people actually see the value in this, they could maintain it separately, couldn't they? That would keep WPCS simple, but we could still link to such standards for those who want different options. Any of us who want to help maintain it could do so, but perhaps as @GaryJones says it is not the prerogative of WPCS itself and we should not be adding this complexity here in WPCS directly.

I guess this comes back to what I had said when this was proposed some time ago: I'm willing to contemplate splitting the standards on WPCS's part, but we need to consider whether it is something that WPCS really needs to do itself or not. What are the drawbacks of trying to do this independent from WPCS, and are they significant enough, and the need for sub-standards great enough, to justify the additional complexity here. And I'm still not clear on that: are there any technical drawbacks to maintaining these standards independently (other than the obvious need for coordinated maintenance)?

Maybe it would be better to create a separate repo with the substandards in it, or encourage the community to do so if they think this is helpful, and see whether there is actually enough interest in it/usefulness to make it worth splitting things here. ??

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

Yes, this can be done by individuals in their own ruleset, but they would have to amend their ruleset (nearly) every single time we add a new sniff to a ruleset.
Yes, this can be done in a separate repository, but that would have to closely shadow what is being done here in the rulesets and would have to be updated every single time we change something in WPCS.

Over the last year, I have taken note of what people have told me at conferences, meetups, twitter, what I see happening for theme/plugin reviews etc.
IMHO there is a real need for this.

Am I willing to create a separate repo to maintain a separate set of rulesets shadowing what WPCS does ? Hell no, I'm doing enough as it is, thank you very much.

If this is done within WPCS, this is a one-time change and the maintenance burden on us after the change is no different than it is now.

If this is done in custom rulesets for individual projects and/or in a separate repo, it creates an extra maintenance burden for every single person maintaining such a custom ruleset/repo which would quickly be a lot more person-hours than the one-time change to WPCS would involve.

More than anything, history shows us that projects which shadow other projects very quickly fall into disrepair. That would in effect mean that people would be missing out on new sniffs we're creating and adding and will not be getting the benefits these sniffs bring, which IMHO would be a shame.

@JDGrimes
Copy link
Contributor

Over the last year, I have taken note of what people have told me at conferences, meetups, twitter, what I see happening for theme/plugin reviews etc.

I really appreciate your insight @jrfnl (as it should be fairly obvious by now that I really don't know how other people use these standards 😄).

I think that a part of the issue here is that we are trying to address several different interests all at once. Perhaps it would help to break it down a bit, to make discussion easier:

  • Code style vs best practices
  • In the core handbook vs not ("extra")
  • Modern PHP vs older/legacy

Although we need to take all of these into account in the end, and they do touch at the edges, it is complex to try to think about them all at once. So maybe we could respond to each of these points specifically, rather than the whole proposal in general. (Some of the discussion has already been specifically about each of these aspects, of course, but not always real clear.)

I'm trying to get me latest thoughts together now, and I'll leave a comment addressing each of these after I've considered things a bit more.

@GaryJones
Copy link
Member

Code style vs best practices

I guess the analogy here would be PSR-1 vs PSR-2.

I know for a while there were some developers who were happy to follow PSR-1, but didn't see the benefit in PSR-2 (Laravel was a big one), but most of them now follow PSR-2 as well (including Laravel). I'm sure the split between changes with value, and changes for the sake of pretty and consistent code, helped with their migration, but ultimately, they all took on PSR-2 anyway.

As such, though folks may be saying in person their wish to just have one part of the standard, ultimately, the WordPress standard, as defined in the handbook, incorporates code style too, i.e. there's less value in the long term to split it out (and folks can do that themselves, or from exemplar wiki guidance, if they really do want to break it down).

In the core handbook vs not ("extra")

Do we make it clear what the "Extra" ruleset is all about? That's about all that is needed here, since it's otherwise self-explanatory (beyond emphasising that the "Core" handbook is really what plugin and theme authors should be using as well i.e. standard for the community.

Modern PHP vs older/legacy

I'd like to think that the sniffs added for "modern" code generally have no effect when the modern syntaxes are not found, so making a distinction has less value. There's no definition of "modern" beyond being something later than the minimum version of PHP that WP has - not all of which is modern anyway.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

Are you sure on this? I've just tried the following (note WordPress-VIP standard rather than WordPress.VIP sniffs mask in my earlier example) and exclusion worked:

@Rarst Interesting. I'm going to have to run some tests myself, but it may well be that this has changed with PHPCS 3.x in that case, as I'm pretty sure that didn't work in PHPCS 2.x. Thanks for testing.

@jrfnl
Copy link
Member Author

jrfnl commented Sep 23, 2017

The original Proposal 1 is based on thinking towards the future and offering maximum flexibility to people creating custom rulesets.

Taking the feedback I've received so far into account (and thank you all for joining the discussion, I really do appreciate it!), let me propose the following more minimalistic alternative which would allow for the first and the third usecase and only to a lesser extent for the second:

Proposal 3 (alternative to Proposal 1): changing the rulesets

Adding 3 new (subset) rulesets:

New Ruleset Notes
WordPress-Core-Best-Practices See #740 for an initial proposal
WordPress-Extra-Best-Practices Would contain nearly everything else now in Extra
WordPress-VIP-Requirements Would contain everything now in VIP, except for the inclusion of WordPress-Core

The existing rulesets would not change in functionality, but would now all be (slightly less) compound rulesets:

  • WordPress-Core = individual code style inclusions + WordPress-Core-Best-Practices
  • WordPress-Extra = WordPress-Core + individual code style inclusions+ WordPress-Extra-Best-Practices
  • WordPress-VIP = WordPress-Core + WordPress-VIP-Requirements

I would like to also propose deprecating the WordPress-VIP ruleset with an eye to removing it altogether in the not too distant future. As @grappler pointed out: it would be much better if this was maintained in https://github.com/Automattic/VIP-Coding-Standards/ instead of having a semi-duplicate effort going on.

Usecases 1 and 3 can now be addressed as people can chose to include the WordPress-Core-Best-Practices + WordPress-Extra-Best-Practices subsets in their custom ruleset rather than including the supersets.

As for "Modern" code: this would for now mean that only non-blocking modern code sniffs would be accepted and only for Extra.

@jrfnl jrfnl added this to the 1.0.0 milestone Dec 14, 2017
@jrfnl
Copy link
Member Author

jrfnl commented Dec 14, 2017

Ok, so PR #1242 has been merged in the mean time.

Has anyone had anymore bright ideas on how to move forward regarding Proposal 1 ?

@JDGrimes
Copy link
Contributor

I would still like to see something like Proposal 1 go into this release. I am very flexible as far as naming goes, although since we're renaming things already it would be nice to get the ruleset naming just right.

Though we've dropped consideration of Modern for now, we are still dealing with two different concerns, formatting/non-formatting and handbook/non-handbook. (And with VIP thrown into the mix for good measure.) I think this is making it difficult to pinpoint a solution, because the discussion regarding the two different aspects is so easily confused.

In the interest of moving forward, I propose that we first focus on the naming regarding handbook/non-handbook. This seems logical, because we already have this distinction in our rulesets now (Core/Extra). Then, after that is settled, we can move on to introducing something new (the distinction between formatting/non-formatting).

While making formatting/non-formatting split is the ultimate purpose of Proposal 1, and offers the most benefit, it may need to be postponed to a later release until the naming is figured out. If it is done with sub-rulesets then it will not break backward compatibility, so it doesn't have to go in with the current naming changes. (Of course, if we can get the naming issue resolved, then it can go into this release.)

In addition, we want to ultimately get rid of the VIP ruleset, and have that be maintained entirely by Automattic. We need to deprecate it in preparation for that. Any changes (particularly naming ones) related to its deprecation should accompany this release as well, IMO.

👉 So what I am suggesting is that our focus right now would be on settling naming/handling for handbook vs non-handbook things, and deprecating VIP. Getting that out of the way might make it easier to just focus on naming around formatting/non-formatting sub-rulesets.

I'd say new issues should be opened for each of these, with a summary of the discussion so far. This issue has become difficult to follow.

If nobody has any objections, I can create the issues (some likely exist for VIP already anyway), and we can go from there.

🕐 As far as timing goes, I think it is worth noting that at this time of year people often have less time/attention to devote to things like this. As such, I think a breaking release like this over the next few weeks would be out of the question anyway. So I do not see a need to rush to get this out yet. I don't see the next release happening until sometime after mid-January.

@GaryJones
Copy link
Member

I was trying to think of pairs of synonyms for handbook vs opinionated non-handbook, but a more controversial idea hit - it may not be viable, but may as well mention it.

Although the documented coding standards are in the Core handbook, it does explicitly say that it's for the whole WP space (a great thing):

Keep the following points in mind when writing PHP code for WordPress, whether for core programming code, plugins, or themes.

Right now, WordPress-Extra is a more guiding ruleset based on the opinionated experience of a few of the admins here, but it doesn't need to be. For a long while, the flow of implementation has pretty much all been one way - from the Handbook into the WPCS. But, with WP Core now more involved, we have the opportunity to make that two-way, with WordPress-Extra feeding back into the Handbook.

So here's the suggestion:

  • Review all bits of WordPress-Extra with an aim of getting the powers that be to agree that each bit is suitable for the WP community as a whole.
  • Get it all documented in the Handbook.
  • Merge WordPress-Extra into WordPress-Core ruleset (since it would then all be in the Handbook).
  • Have WP Core's phpcs.xml.dist exclude whatever current bits of WordPress-Extra are not yet suitable for WP Core. It already excludes some WordPress-Core per its needs, the same as other projects do for their needs.

It would take some effort on the part of the key people to agree that the parts are Handbook-worthy, and anything that isn't may still be left in some WordPress-Extra-style ruleset (how that is handled would depend on how much is not added to the Handbook), but consolidating the two main standards down to benefit the whole community removes this fracture that we currently have.

(Aside: I'd like to see WordPress-Docs ultimately be merged in as well - folks could exclude WordPress.Docs if they don't want it. Keeping it separate for now makes sense until it matures - a bit like a feature plugin.)

The benefit is a more unified appearance to those who want to follow the WP coding standards. For those who already are, it gives them new opportunities to tighten up their code. For the maintainers here, it's a bit of short-term pain, but should make things simpler in the longer term.

To summarise, for 1.0 we'd have:

  • WordPress
  • WordPress-Docs
  • WordPress-VIP (Deprecated)

But if VIP was passed on to Automattic, and WordPress-Docs was improved and merged, then for 2.0 (be it a year or five years from now) we'd be left with:

  • WordPress

Wouldn't that be a nice goal to aim for?

@tfrommen
Copy link
Member

tfrommen commented Dec 14, 2017

I also mentioned the idea to have dedicated rulesets for Core and plugins/themes. But in a different way than @GaryJones did. As a plugin developer, I don't like all of what WordPress-Core requires. Sure, there are lots of things that make sense everywhere, but there are also things that don't (to be honest, not even for Core, if it was rewritten today). Which PSR's to use, how to name files and so on - nothing that should be a general rule, in my opinion.

So, one could go one of three routes:

  • have Core-specific ruleset inherit the general (plugins/themes) one and adapt things as necessary;
  • have the general (plugins/themes) ruleset inherit the Core-specific one and adapt (and null) things as necessary;
  • have a base ruleset, and then have the two above rulesets extend that and customize.

Just thinking out loud here...

@GaryJones
Copy link
Member

Core-specific ruleset

This puts the emphasis back on plugins and themes being somewhat secondary to WP Core.

WP Core is just yet another piece of software that uses the WordPress [Community] Coding Standards.

@jrfnl
Copy link
Member Author

jrfnl commented Dec 15, 2017

Regarding @JDGrimes' remark about the timing:

I agree, there is no rush, but it would be good to keep this ticket (or the sub-tickets) moving.

As the next release will now be called 1.0.0 as per #1247, it no longer needs to be an isolated release and other new sniffs/features can come into the release, which would be released "when it's ready", not necessarily straight after this ticket has been sorted.

Regarding @GaryJones' approach to simplify and consolidate:

While I very much applaud and encourage the efforts to move individual rules from Extra into the handbook and into the Core ruleset, there are a couple of things with the proposal which are problematic:

  1. It talks about excluding things from the ruleset. This has been discussed before (somewhere above) and makes it more difficult, if not impossible, for custom rulesets based upon WPCS to include certain things anyway, so should be avoided as much as possible.
  2. It doesn't address or leave room for the main concern this ticket wants to address, which is to make it easier for devs to just use the best practices without the WP code style (and naming) rules.

Also, while the handbook claims the rules are for "all WordPress projects", IMO this is just not true. The "community" has AFAICS never had a say in what rules there should be and most of what's there is - again AFAICS - pragmatically based on "what's currently the prevailing trend in Core", which is the wrong way around for standard-design.
It would be interesting to have a wider community discussion on what the CS for WP should be, but that's outside the scope of this issue and until that discussion has been had, I don't think merging Extra into Core and calling it "WordPress Community Coding Standards" is in order.

Regarding merging Docs with Core/WordPress:

I kind of prefer for the Docs sniffs to stay separate as that will allow devs who are so inclined to more easily switch it out in favour of using a PSR-5-based docs ruleset instead.

@ntwb
Copy link
Member

ntwb commented Dec 15, 2017

🕐 As far as timing goes, I think it is worth noting that at this time of year people often have less time/attention to devote to things like this. As such, I think a breaking release like this over the next few weeks would be out of the question anyway. So I do not see a need to rush to get this out yet. I don't see the next release happening until sometime after mid-January.

I'd like to see a release before then, I'd like to update the handbooks and get various other changes into core without having to have committers and contributors shuffle around composer configs by having to install dev-master, branches or even worse commit.

If this involves shipping a 0.15.0 release as master stands now and bumping this to the following 1.0.0 release that works for me though I'm not sure what needs to happen here to get said package 0.15.0 out the door soonishly, thoughts?

p.s. There are various committers and contributors waiting for me/us for the above

@jrfnl
Copy link
Member Author

jrfnl commented Dec 15, 2017

I'd like to update the handbooks and get various other changes into core without having to have committers and contributors shuffle around composer configs by having to install dev-master, branches or even worse commit.

@ntwb Could you elaborate on this ? What changes to the handbook do you want to make ? And why would this have to wait for the release ? WPCS - at least for the Core ruleset - follows the handbook, not the other way around. There are things in the handbook already which are not (yet) covered by WPCS.

If this is about the doc-alignment sniff, that would not be in a 0.15.0 release anyway as in that case 0.15.0 would be an isolated release with only the sniff and ruleset name changes. It could, however, - when I have time to finish it - make it into a 1.0.0 release.

@ntwb
Copy link
Member

ntwb commented Dec 15, 2017

Sorry, not any of the coding standard handbook changes, instructions to install PHPCS, WPCS, adding docs on the new (yet to be committed) grunt phpcs and grunt phpcbf task workflows and adding these to Travis CI.

Pages such as:
https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/
https://make.wordpress.org/core/handbook/testing/patch/
https://make.wordpress.org/core/handbook/about/getting-started-at-a-contributor-day/#tools
https://make.wordpress.org/core/handbook/best-practices/commit-messages/#before-a-commit

There are committers and contributors patiently, eagerly even, waiting for this documentation to be updated and the Grunt tasks to be committed so that PHPCS can be included in their workflow.

Currently, committers have no way to test the code they are committing, adding in these Grunt tasks will aid that and save on code churn.

The install and configuration of the above needs to be as easy and stable as possible and avoiding moving targets such as having to use WPCS dev-master which is not ideal.

@ntwb
Copy link
Member

ntwb commented Dec 16, 2017

@jrfnl
Copy link
Member Author

jrfnl commented Dec 16, 2017

@ntwb I totally get where you are coming from, but as I've been conference hopping for the past month and a half, I was already glad to get the principle of the sniff ready for the core patch. It'll need some more work + a sister-sniff before it can be pulled here and that's independent of the discussion in this issue.
Let's move the discussion about that to the ticket dealing with introducing that sniff #1120 to prevent muddying the waters in this issue even further.

@tomjn
Copy link
Contributor

tomjn commented Feb 27, 2018

Noting here that it's VIPs intention on the longterm to move the VIP ruleset out of WPCS and into our own repository. It's confusing that we have a ruleset that depends on the wpcs VIP ruleset, but we don't use the WPCS VIP ruleset directly

@GaryJones
Copy link
Member

Noting here that it's VIPs intention on the longterm to move the VIP ruleset out of WPCS and into our own repository. It's confusing that we have a ruleset that depends on the wpcs VIP ruleset, but we don't use the WPCS VIP ruleset directly

Just noting for readers, that this was done - WPCS deprecated the VIP-category sniffs in WPCS 1.0, and removed them completely with WPCS 2.0.

@azaozz
Copy link

azaozz commented Apr 7, 2020

Just noting for readers, that this was done - WPCS deprecated the VIP-category sniffs in WPCS 1.0, and removed them completely with WPCS 2.0.

That's great!

Then both of the above proposals are out of date and will need to be either dropped or redone:

  • Proposal 1: changing the rulesets. Basically this means that WPCS will be enforcing rules that are not in the WordPress Core PHP Coding Standards. Sounds like an external project to me, as an extension to WPCS.
  • Proposal 2: Moving some sniffs to other categories. As there's no VIP in WPCS, most of these don't make sense.

@jrfnl
Copy link
Member Author

jrfnl commented Apr 8, 2020

Proposal 2: Moving some sniffs to other categories. As there's no VIP in WPCS, most of these don't make sense.

Proposal 2 was already implemented ahead of removing the VIP standard nearly two years ago and released in WPCS 1.0.0.
Refs:

Proposal 1: changing the rulesets. Basically this means that WPCS will be enforcing rules that are not in the WordPress Core PHP Coding Standards. Sounds like an external project to me, as an extension to WPCS.

That has always been the case, that's why there is the WordPress-Core (aligned with the handbook) and the WordPress-Extra ruleset.

As there is no movement on proposal 1, I'm closing this issue now.

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