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

Coding standards v3 #70

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open

Coding standards v3 #70

wants to merge 6 commits into from

Conversation

danepowell
Copy link
Collaborator

@danepowell danepowell commented Jul 1, 2024

The goal of v3 is to simplify and decouple the standards, as described in the readme:

  • Projects (e.g., Drupal modules) targeting the Drupal community should adopt a Drupal ruleset. This will no longer be based on AcquiaPHP, but on the Drupal standard. All others should adopt a general PHP ruleset, which will be based on PSR-12.
  • Public projects (e.g., open-source Drupal modules) should adopt a non-strict ruleset to facilitate external collaboration. Non-strict rulesets will be nearly identical to their base standards. All others should adopt a more opinionated internal/strict ruleset.

To do:

  • Should we rename these to match their intended audience (public/private projects) instead of describing the ruleset itself (strict/non-strict)?
  • Test on a representative set of projects to gauge the LOE for migration from v2

References:

Copy link
Contributor

@TravisCarden TravisCarden left a comment

Choose a reason for hiding this comment

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

This is great. I have some suggestions in the comments. I also have one concern related to stability:

Firstly

If we're including whole upstream rulesets indiscriminately (as opposed to rule-by-rule), we run the risk that upstream changes and additions will cause sudden, unexpected failures when projects update their dependencies.[1] We could pin to specific versions to avoid that, but then we expose our users to version conflicts. I wonder if we shouldn't do this:

  1. Literally copy the entire upstream rulesets into ours so that we can release breaking changes on our own schedule.
  2. Create separate "Edge" standards for Drupal and PHP and add new upstream rules there so that changes are completely predictable.
  3. Possibly create a CI job to detect upstream additions so we're sure to notice and add them.

Secondly

As to whether we should rename these to public/private, that's a different way of thinking about the whole distinction than we've used in the past. We previously implied that "Strict" was better if you could manage it, whereas now it seems like we're saying they're actually appropriate or inappropriate based on context. I'm fine with the shift, but public vs. private doesn't seem quite right to me. It seems more like open source vs. proprietary. This represents late developing on my part and conflicts with some of my comments on the actual code, but I think it might actually address some of the discomfort I was expressing there.


[1] Unless all of our upstream dependencies carefully observe Semver, which we can scarcely hope for, much less depend on.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
Comment on lines 29 to 32
* [AcquiaPHP](src/Standards/AcquiaPHP/ruleset.xml) is based on PSR-12 and is intended for use on all public non-Drupal projects.
* [AcquiaPHPStrict](src/Standards/AcquiaPHPStrict/ruleset.xml) is based on AcquiaPHP and adds additional more opinionated standards. It is intended for use on all internal non-Drupal projects.
* [AcquiaDrupal](src/Standards/AcquiaDrupal/ruleset.xml) is based on the Drupal coding standard and is intended for use on all public Drupal projects.
* [AcquiaDrupalStrict](src/Standards/AcquiaDrupalStrict/ruleset.xml) is based on AcquiaDrupal and adds the more opinionated DrupalPractice standard. It is intended for use on all internal Drupal projects.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we sort this list in the same order wherever it appears? It would make sense to me to either sort it in ascending order of framework-specificity and strictness or just alphabetically.


* [AcquiaPHP](src/Standards/AcquiaPHP/ruleset.xml) contains sniffs applicable to all PHP projects.
* [AcquiaDrupalStrict](src/Standards/AcquiaDrupalStrict/ruleset.xml) incorporates AcquiaPHP and adds all Drupal coding standards and best practices sniffs. Recommended for new Drupal projects and teams familiar with Drupal coding standards.
* [AcquiaDrupalTransitional](src/Standards/AcquiaDrupalTransitional/ruleset.xml) incorporates AcquiaPHP and adds Drupal core's own phpcs configuration, which is less strict than the official standards. Recommended for legacy Drupal codebases or teams new to Drupal coding standards.
* [AcquiaEdge](src/Standards/AcquiaEdge/ruleset.xml) incorporates AcquiaPHP and adds backwards-incompatible sniffs that will be included in AcquiaPHP with the next major release of this package.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should briefly explain how to use this. For example, should it be periodically be run manually? Should it be run separately on CI and allowed to fail? I haven't even really thought about this, to be honest--which might actually mean it would be better as a conversation for another time. ¯\_(ツ)_/¯

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a good question but probably out of scope for this README. More relevant to ORCA / RCAT I'd think?

As far as a consumer is concerned, I'd only expect early adopters like myself to use it.

Honestly... maybe we should just kill AcquiaEdge? If I'm the only early adopter that every used it, I can track standards in other ways.

Comment on lines 6 to 9
name="AcquiaDrupalTransitional"
name="AcquiaDrupal"
>

<description>Acquia's transitional Drupal coding standards.</description>
<description>Acquia's Drupal coding standards.</description>
Copy link
Contributor

Choose a reason for hiding this comment

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

The apparent lack of symmetry of AcquiaDrupal with AcquiaDrupalStrict makes me wonder if it doesn't need a modifier still. When you read it on this line, you see that we actually lose meaning--we don't just change it--by the omission of an adjective.

On a more pragmatic level (to reason from effects rather than semantics), it's always helpful for text searches to not have one concept not be represented by a sub-string of another concept. It's an imperfect example, but if you wanted to find every mention of AcquiaDrupal in the codebase, unless you used advanced search features, you'd also find every instance of AcquiaDrupalStrict.

What would you think of one of these adjectives?

  • Basic
  • Standard
  • Foundational
  • Minimal

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like basic or minimal. How about:

  • AcquiaPHPMinimal
  • AcquiaPHPStrict
  • AcquiaDrupalMinimal
  • AcquiaDrupalStrict

My original intention was to mirror Drupal and DrupalPractice, but who outside the Drupal community would understand that pattern or what "practice" means 🤷

Comment on lines 32 to 33
<!-- Drupal Practice sniffs -->
<rule ref="DrupalPractice.Commenting.ExpectedException"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

It's kind of curious to have only and exactly one rule from a stricter standard. I know it was already here, but the seeming incongruity is really highlighted now. (It's the only case where we tighten the requirements instead of loosening them.) Should we remove it? Or otherwise add an explanatory comment so future users don't have to search the codebase to figure out what it does like I did? 🙂

@@ -8,11 8,4 @@

<description>Acquia's Edge (backwards-incompatible) coding standards.</description>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to break this into AcquiaPHPEdge and AcquiaDrupalEdge? If it's really inclusive of both, I foresee the same conceptual conflicts here that we're eliminating everywhere else by this refactoring. See my overall review comment for more detailed thinking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. Let's resolve the overall discussion of whether we want to delete the Edge standards first.

<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<!-- PSR-12 has no opinion on comments, leading to unpredictable indentation. -->
Copy link
Contributor

Choose a reason for hiding this comment

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

PSR-12 has no opinion on comments, leading to unpredictable indentation.

Therefore... ? I can't tell from looking at the name what ignoreIndentationTokens = array does, so it's not clear what this does to help.

Copy link
Collaborator Author

@danepowell danepowell Jul 3, 2024

Choose a reason for hiding this comment

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

Sorry... specifically, the problem is this. When you upgrade from v2 to v3 and run cbf, literally every line of your project will change from 2-space indents to 4-space indents, except inline comments, because PSR-12 explicitly ignores comment spacing/styling using the ignoreIndentationTokens array. So you get bastardized code like this:

function foo() {
  // Call method bar().
    $this->bar();
}

By redeclaring this as an empty array, we persuade cbf to treat inline comments like all other code and indent them accordingly.

I wasn't sure how to express that succinctly...

src/Standards/AcquiaPHPStrict/ruleset.xml Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants