Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Our CSS standards have a recommendation about the order of property declarations so we should apply it to core.
Proposed resolution
Add https://www.npmjs.com/package/stylelint-order and use the existing CSScomb config to configure it and use the --fix option to generate a patch.
Blocked on #3024518: Upgrade stylelint to the latest version
Once that has landed you can:
$ cd core
$ yarn add stylelint-order --dev
- Apply the patch here to
core/.stylelintrc.json
For example:$ curl https://www.drupal.org/files/issues/2019-03-08/3024527-4-28.patch | git apply --index --include=core/.stylelintrc.json
$ yarn run lint:css --fix
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
CSS standards for ordering is now enforced using the stylelint-order plugin.
Comment | File | Size | Author |
---|---|---|---|
#56 | 3024527-10-56.patch | 504.62 KB | alexpott |
#49 | 3024527-9-49.patch | 504.71 KB | alexpott |
#42 | 3024527-8-42.patch | 504.71 KB | alexpott |
#41 | 3024527-7-41.patch | 501.73 KB | alexpott |
#40 | 3024527-6-40.patch | 498.54 KB | alexpott |
Comments
Comment #3
alexpottThis was brought to my attention in #2992635: Pass all Umami CSS files through CSScomb to Ensure they Follow our CSS Coding Standards - so crediting @markconroy
Personally I think we should change the rule to be alphabetical because then at least human beings can know when it is correct. Or maybe not have a rule at all.
Comment #4
alexpottComment #5
lauriii+1 on automating coding standards checks to reduce manual work developers have to do.
I'd like to express my opinions without wearing any hats since I don't think there's a right or wrong way to order selectors. I don't think ordering selectors alphabetically makes it much better than having properties in random order, whereas grouped by type actually makes it easier to read the CSS. It is also not as commonly used as grouping by type at least according to this poll.
Comment #6
alexpottOkay given @lauriii's position in #5 I'm +1 on this patch. It makes it easy to enforce our standard.
Comment #7
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedHi Folks,
Great to see this progressing. I'm adding two patches for consideration here:
object-fit
andobject-position
object-fit
andobject-position
and also@include breakpoint
. Not sure if we want the breakpoint support in a core linter, but many people using sass use the breakpoint package for easier to write/read media queries, and like the$media
property, we need these after our other declarations for mobile-first theming.Comment #8
alexpottRerolled now the dependency has landed. Let's add breakpoint support there's not harm in making everything consistent even if core does not specifically use it.
No interdiff break this is a reroll.
Comment #9
alexpottRe-rolled
Comment #10
occupant#9 applied cleanly, passes linting.
Further to #8 and @alexpott's comment about breakpoint support, I'm wondering if there is a place here to add some additional rules for properties that aren't currently included in core, most notably
grid
,grid-area
,grid-template
, etc? These aren't used atm, but that could conceivably change considering the current state of support - caniuse grid support.I guess this comes down to, should new properties be added when they come up as a failsafe, or should it just be focussed on what's currently in core?
If so, some additional properties (not including prefixes) could include:
all
All @ MDNperspective
perspective @MDN perspective @ caniuseperspective-origin
There may be more, but that's what I've noticed with this pass.
Happy to make a patch with these if there's a place for the additional properties.
Comment #11
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commented@occupant,
Thanks.
I would be 100% for adding grid support. I think anything that helps developers to use the tools from core (such as this linting set-up) without having to extend or fork it is a great help in getting everyone (automatically) following the coding standards.
If people have to extend or fork, we run a real risk of people just adopting some other standards in their own work because the things they want are in them, and then finding core/contrib harder to work with when they have to change tack.
So, for me, given the prevalence of CSS Grid, I think that should certainly be a part of this file.
Comment #12
occupant@markconroy
I'd love to see this in there too. Here's a patch with the properties added. I had to change the order of
align-self
, as it's used in grid as well. I've also attempted adding the-ms
prefixes as per how they're added by autoprefixer.Comment #13
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedCan you add an interdiff between this patch and the last one please, so we can see exactly what has changed?
Comment #14
occupantWhoops, I should have done that. I've rerolled it again and created an interdiff between this and patch #3.
Edit: hmm, not sure I did that right. are the
/core/package.json
and/core/yarn.lock
changes supposed to be in there?Comment #15
alexpottAre you sure that moving align-self is correct? And also is this really where justify-self belongs?
Comment #16
occupant@alexpott they’re used by css grid and flexbox - css grid guide @css tricks, so my thinking was it doesn’t make sense to come before the
grid
property. I see I did missalign-content
andjustify-content
however, which are both grouped above with flexbox atm. I would expect that these should appear lower as well.That said, the exact order could very well be different than what I’ve proposed.
Comment #17
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedLet's put
align-self
back where it was, as it is a property of flexbox. https://developer.mozilla.org/en-US/docs/Web/CSS/align-selfAnd let's move
justify-self
to either directly above or directly below the flex properties as it is an alignment property that is not strictly part of flex or grid, can be used withposition
anddisplay
https://developer.mozilla.org/en-US/docs/Web/CSS/justify-selfComment #18
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedAdding new patch for what I propsed above in #17
Comment #19
occupant@markconroy I think it's actually a shared property, as per your link:
So I think, as a shared property, I'd argue these should come either before or after both flex and grid properties to normalize the expected order.
I propose the following ordering of these shared properties:
Thoughts?
Comment #20
occupantJust looking through the flex properties, and it seems that the syntax is outdated.
Deprecated
flex-order // replaced by order
https://developer.mozilla.org/en-US/docs/Web/CSS/flex-orderflex-pack // replaced by justify-content
https://developer.mozilla.org/en-US/docs/Web/CSS/flex-packflex-align // replaced by justify-items
https://developer.mozilla.org/en-US/docs/Web/CSS/flex-alignalign // not found
https://developer.mozilla.org/en-US/docs/Web/CSS/alignAlso, the
flex-flow
shorthand property is missing. With this and #19 in mind, I'd propose updating the flex properties to:Comment #21
waako CreditAttribution: waako at Annertech commentedNew patch with following changes:
Added "order/order" config to match CSSComb so that variables (and one-line sass @at-rules) sit before declarations but at-rules with blocks (@media, @supports, sass @include breakpoint) sit after declarations and before rules.
Worth noting that "order/properties-order" ignores variables ($sass, @less, --custom-property).
This means I don't think it's possible to have certain at-rules like @keyframe name {} block in between transform and animation declarations like it is in CSSComb.
Removed "$charset", "$import", "$namespace", "$extend", "$variable", "$include" from beginning of "order/properties-order" and "$media", "$include breakpoint", "$supports", "$document", "$page" and "$viewport" from end of "order/properties-order" as they area now dealt with by the "order/order" rules before.
However left other "$declaration" for reference in case we want to look at ordering them in a specific place.
Based on comments in #19 and #20 I've updated the flex properties, and moved the flexbox & grid shared alignment properties to below both, that does seem to make sense.
Comment #23
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedSetting back to 'Needs review' to get the tests to run again. I don't think the failures are anything to do with the patch (which looks great).
Comment #24
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedI did a screenshare with @waako a few minutes ago and got him to show me this working. I'm _very_ impressed with it.
I'm happy with the ordering of items, the spacing between block sets, how custom variables (--black: #000;) are placed at the top of our rules, followed by any $dollar variables (for SASS, etc - $c-black: #000), then our general css (color: #000;), and then any media queries/supports/etc at the end.
Here's a screenshot of some made-up code before we run the stylelint:
And here's a screenshot of this mess all cleaned up:
I think this will make a great addition to Drupal core, and will mean sooo many developers across the world can use it as the base for their linting when developing Drupal websites, without having to fork it or extend it, given how it works for CSS/SCSS/etc.
Thanks @waako for this and @occupant for adding the grid stuff.
Comment #25
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedComment #26
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedThe tests are passing now. Looks like Drupal Infra had an issue.
I'm marking this as RTBC, it's a great improvement.
We might want to postpone running the linters until later in Beta/RC phase.
Comment #27
waako CreditAttribution: waako at Annertech commentedSmall change in "order/order" placing at-rule blocks after rules.
This doesn't impact on Drupal core CSS, but will help with preprocessors and nested rules being overriden inside @supports or @include breakpoint statements.
Without this change the @supports block would be placed before the nested rules it aims to override and be overriden themselves, defeating the purpose of the @supports altogether.
Updated 8.7.x branch locally, hence the large interdiff.
Comment #28
alexpott@waako the interdiff at least contains unrelated change. Looks like the patch doesn't though so that's good - but confusing.
I wonder why we get a warning. Happens why you add stylelint-order anyway so /shrug.
Importantly #27 doesn't include the stylelint-order library so that needs fixing.
Comment #29
alexpottI've opened https://github.com/hudochenkov/stylelint-order/issues/80 about the warning.Comment #30
alexpott#3038562: Update stylelint to 9.10.1 will resolved the warning.
Comment #31
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commented@alexpott, can we mark this RTBC again? You happen with this new patch - bigger, better, newer!!!
Comment #32
alexpott@markconroy a review of https://www.drupal.org/project/drupal/issues/3038562 would be great too as that takes away a warning generated when we do this one.
Comment #34
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedHi @alexpott
#3038562: Update stylelint to 9.10.1 is RTBC now as well.
Comment #35
waako CreditAttribution: waako at Annertech commentedThank you @alexpott for fixing those issues in #27.
I definitely got myself mixed up with my local git branches considering it was such a small change, compared to correct patch & interdiff I did in #21. I live and learn.
Comment #36
alexpott@waako thank you for your contribution. I've messed up many patches - tools like composer and yarn make reviewing changes hard because there's a lot of noise.
Comment #37
alexpottRe-made the patch due to conflicts as the per the instructions in the issue summary.
Comment #38
alexpottComment #39
alexpottI've added the necessary change record - see https://www.drupal.org/node/3041002
Comment #40
alexpottrerererererereroll.....
Comment #41
alexpottrerererererererererereerererererererereRerollll.......
Comment #42
alexpottRererererererererererererererererererererererererererererererolll....
Comment #43
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedI am having the errors while testing the patch to the 8.8.x branch
error1:
error2:
Comment #44
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedWe may need to re-patch the css files for quickedit styles
https://github.com/drupal/drupal/blob/8.8.x/core/modules/quickedit/css/q...
Comment #45
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedComment #46
xjmThe deadline for this for 8.7.x has passed, so untagging 'til next time. Thanks!
Comment #47
joelpittet@xjm If this is not the right time to commit this kind of disruptive patch when is?
Comment #48
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commented@xjm,
I'm adding back in the 8.7.0 release notes tag.
We deliberately didn't commit this early in the 8.7.x branch phase because it would be very disruptive to many CSS-based patches. We were leaving it until feature-freeze/beta/rc so it has as little disruption as possible, and then people working on CSS-based patches can use this when we transition to the 8.8.x branch.
@alexpott and @lauriii discussed this with me on Slack a few months back.
@Joseph Zhao - CSS files are broken. That's why we need this patch, so the coding standards will be automated. quickedit.css et all will be fixed automatically once this patch is committed. It won't apply directly against the quickedit module per se, it'll be run and that will update the quickedit.css file for us. Then when people do their next
git pull
, they'll have CSS files that follow our coding standards.Comment #49
alexpottA release manager has made a decision. So let's not put this in 8.7.x. Let's get this in 8.8.x now. That means we have the whole release cycle to find an issues (however unlikely or lilely that is - feels unlikely) and because we commit patches to 8.8.x first 8.7.x gets the benefit anyway!
Here's yet another reroll.
Comment #50
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commentedThat seems very strange. This has been RTBC pretty much for a month, but we held back on it then for no good reason it seems.
I hope the same doesn't happen in 6 months when we are trying to get it into 8.8.x
Comment #51
joelpittet@xjm I don't mean to go against the decision. I'm just looking for clarity because I know these can be disruptive so timing is key so I just want to get it correct. Also for contrib projects I'm maintaining there is similar disruptive patches that would be nice to have a message for when the patch can make it in.
Comment #52
alexpott@markconroy I'm suggesting we add the library now in 8.8.x and then we can choose whether to backport the allowed CSS changes to 8.7.x. That way 8.7.x benefits because we commit to 8.8.x first so all new patches will comply because 8.8.x has the library.
Comment #53
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commented@markconroy
thanks for the clarification.
Commit to 8.8.x then backported to 8.7.x makes sense
Comment #54
lauriiiIs the proposal to commit #49 to 8.8.x, and after that, we would create another patch where the library addition has been removed, but it still contains the same CSS changes and commit that to 8.7.x? I like the plan except I would prefer if we would create both patches at the same time, and only commit this to 8.8.x if we also commit the CSS changes to 8.7.x. If we end up in a situation where we committed these CSS changes only to 8.8.x, backporting CSS changes to 8.7.x would in most cases require a separate patch.
Comment #55
alexpott@lauriii for 8.7.x you can do
No need to another patch atm :)
Comment #56
alexpottRerolled.
Comment #59
lauriiiLooks good for me. I talked with @catch on Slack who is another release manager and he didn't express any particular concerns on this approach. So committed the change with the library addition to Drupal 8.8.x with the CSS changes and only the CSS changes to 8.7.x
Comment #60
markconroy CreditAttribution: markconroy as a volunteer and at Annertech commented@lauriii
Thanks for committing this. It'll be a great help to people to follow the coding standards.
I'm a little confused at the specific reason why we wouldn't include it in 8.7. if we are including the CSS that it generates. I don't see how anything would break and it will make following coding standards to be a lot easier for an extra six months.
Comment #61
alexpottSetting to 8.7.x as a version of the patch did make it into 8.7.x.
@markconroy the reason the library did not make it into 8.7.x is because the release managers have decided to not make library changes whilst in beta in order for stability both of production and development environments. A new library potentially means that someone might have to change their development pipeline in some way. Personally whilst I agree that PHP and JS dependencies (those in core/misc) should be treated this way I'm not 100% convinced the same is true for dependencies managed by core/package.json because these dependencies describe only the core JS build process. That said we do have a problem at the moment because DrupalCI treats core's dev tools as the baseline for all Drupal contrib dev tools so disruption to the toolchain can have unexpected effects. Again we've only seen this for PHP dev dependencies such as PHPCS but it is worth bearing in mind. Ideally things would not be so closely coupled.
Comment #62
xjmWhere's the separate issue for the library addition?
Comment #63
xjm@lauriii clarified that he manually fixed 8.7.x without backporting the library rather than committing a separate patch, so the commit message there misled me.
WRT not backporting the library after beta, this is not an arbitrary release manager decision. It is documented core policy: library additions are only allowed in minor versions, and as such need to be completed before beta, as per:
I'd prefer not to make exceptions based on what kind of library it is because we have to explain or justify them; the whole point of the alpha and beta phases is that alpha is "with exceptions" and beta is "no exceptions".
In an ideal world, the library would have been added, but not used, before the beta deadline, and the cleanup would have been scheduled during beta.
Thanks!