Make WordPress Core

Opened 12 years ago

Last modified 4 weeks ago

#29792 assigned defect (bug)

Grunt: Add a stylelint precommit task to check for CSS syntax errors

Reported by: helen Owned by: afercia
Priority: normal Milestone: 7.2
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch
Cc: Focuses: accessibility, css, coding-standards

Description

We need to do a better job of catching sad syntax errors and problems in our CSS before commit - things like parse errors, empty rules, units on zero values, and possibly duplicate properties (when alone, not as a part of a group). There may also be a thing or two that we could enforce per our own standards, such as requiring a comment to follow any declaration with !important.

CSSLint seems to do most of these, provided we turn off the majority of its checks. Many of those checks (vendor prefixes, selector specificity, etc.) either are not relevant to our set up (due to Autoprefixer, for example) or are just not feasible given our current CSS and possibly not desirable for this project.

Interested to know if there are any other tools out there that perhaps fit the job better, and defining the parameters of what we would like to check.

Attachments (9)

patch​ (15.0 KB ) - added by x2048 12 years ago.
Adds CSSLint and a small custom WP CSS style checker as grunt tasks. Removes space around parens in media queries.
29792.patch​ (4.4 KB ) - added by netweb 12 years ago.
wp-css-check.patch​ (14.9 KB ) - added by x2048 12 years ago.
A new version of the wp-css-check tool. Now also checks for CSS property syntax (e.g. mistakes like "width :100px"). Also checks for !imporant properties without comments.
29792.1.diff​ (1.2 KB ) - added by netweb 11 years ago.
29792.2.diff​ (1.6 KB ) - added by netweb 11 years ago.
29792-warnings-with-vendor-prefix.txt​ (88.6 KB ) - added by netweb 11 years ago.
29792-warnings-without-vendor-prefix.txt​ (14.2 KB ) - added by netweb 11 years ago.
29792-css-patch.diff​ (182.9 KB ) - added by netweb 11 years ago.
29792.3.diff​ (5.0 KB ) - added by netweb 11 years ago.

Download all attachments as: .zip

Change History (117)

#1 follow-up: @x2048
12 years ago

I tried adding csslint to grunt and ran into the following problems:

โ€‹http://stackoverflow.com/questions/15626062/getting-errors-in-the-css-linter-when-using-media-queries
โ€‹https://github.com/CSSLint/csslint/issues/295

These problems occur even with all linting settings set to false.

To use CSSLint:
1) all media queries will need to be rewritten to not include spaces between parentheses, or CSSLint will show errors.
2) the @ms-keyframes styles will need to be moved to a separate file (that doesn't get linted), or added to the auto-prefixer.

#2 @x2048
12 years ago

It appears that @-ms-keyframes is not actually used in any browser, and can safely be deleted:
โ€‹http://css-tricks.com/snippets/css/keyframe-animation-syntax/

I put together a really small library that parses CSS and reports errors according to the WP guidelines.
Currently it handles "camelCaseSelectors", "selectors_with_underscores", and ".multiple, .selectors, .on-one-line".
Would this be useful, and should I add more things(like "!important requires comments")?

There's a patch that installs these two grunt tasks.
Try them out with "grunt csslint" and "grunt wp-css-check".

(btw, I'm new to WordPress core development - I only started this week. Please tell me if I'm doing something wrong)

Last edited 12 years ago by x2048 (previous) (diff)

@x2048
12 years ago

Adds CSSLint and a small custom WP CSS style checker as grunt tasks. Removes space around parens in media queries.

#3 follow-up: @GaryJ
12 years ago

โ€‹grunt-wp-css is a wrapper for CSSComb (and โ€‹currently CSSBeautify until an issue in csscomb.js is fixed) and includes a couple of configs (same, other than default vs alphabetical sort order).

Whether it's csslint or csscomb, I'd like to see a standalone grunt package ( like grunt-wp-css) which then core and plugins and themes could use, with minimal configuration, rather than have to set up csslint / csscomb grunt packages with duplicitous configs.

#4 in reply to: ↑ 3 @helen
12 years ago

  • Keywords has-patch added

Replying to GaryJ:

Specifically not tackling standards here, rather syntax checking, but good to know for future reference.

#5 @helen
12 years ago

I realized that the mention of our standards in the ticket description is probably a little misleading, but in essence I'd like to start with error checking here and then move on to tasks that would actually make changes separately.

#6 follow-up: @x2048
12 years ago

@helen What steps do I need to take in order to have โ€‹https://github.com/x1024/wp-css-check be considered as a solution for the task?

#7 follow-up: @GaryJ
12 years ago

CSSComb does have a -l or --lint option, but it's not very helpful at the moment, not reporting lines and columns etc. CSSLint would be favourable over CSSComb just for error checking of specific non-standards issues.

#8 in reply to: ↑ 6 @helen
12 years ago

Replying to x2048:

@helen What steps do I need to take in order to have โ€‹https://github.com/x1024/wp-css-check be considered as a solution for the task?

Mention it here, as you've done :)

#9 @x2048
12 years ago

Nice :)

So, I started building this after looking over the WP issues at "Contributor Day" at WordCamp 2014.
The submitted patch installs a grunt task that calls wp-css-check.

I'd be happy to continue developing it, if there's interest.

#10 @jorbin
12 years ago

Thanks for the start on this x2048!

I think error checking is something we can do just by using something like โ€‹https://github.com/reworkcss/css to see if the AST is built properly and if it errors, we know that we have an error. This seems to be the base of what you are using x2048.

Having a style checker seems like a separate issue and thus should be a separate ticket.

#11 in reply to: ↑ 1 ; follow-ups: @nacin
12 years ago

Replying to x2048:

1) all media queries will need to be rewritten to not include spaces between parentheses, or CSSLint will show errors.

No thanks. :) I patched CSSLint for this: โ€‹https://github.com/CSSLint/parser-lib/pull/125

I think CSSLint is actually feasible here. Here's what I'm using, with good effect:

{
	// I used jQuery UI as a starting point
	"adjoining-classes": false,
	"box-sizing": false,
	"compatible-vendor-prefixes": false,
	"duplicate-background-images": false,
	"import": false,
	"important": false,
	"outline-none": false,
	"overqualified-elements": false,
	"text-indent": false,
	// Additional
	"ids": false,
	"box-model": false,
	"qualified-headings": false,
	"unique-headings": false,
	"universal-selector": false,
	"regex-selectors": false,
	"floats": false,
	"font-sizes": false
}

With my patch applied to parserlib, this results in:

  • errors for unknown moz-document and ms-keyframes
  • no other errors
  • 65 warnings

The warnings all seem like good things to fix:

  • non-adjacent duplicate properties (5)
  • unknown property values (3)
  • no fallback colors for RGBA usage (18)
  • one vendor-prefixed property without the standard property
  • one verbose property usage when shorthand will do (1)
  • zero units (17)
  • some display property grouping warnings (19)
  • one unqualified attribute (this one may be a bug)

#12 in reply to: ↑ 11 ; follow-up: @jorbin
12 years ago

Replying to nacin:

With my patch applied to parserlib, this results in:

  • errors for unknown moz-document and ms-keyframes
  • no other errors
  • 65 warnings

The warnings all seem like good things to fix:

  • non-adjacent duplicate properties (5)
  • unknown property values (3)
  • no fallback colors for RGBA usage (18)
  • one vendor-prefixed property without the standard property
  • one verbose property usage when shorthand will do (1)
  • zero units (17)
  • some display property grouping warnings (19)
  • one unqualified attribute (this one may be a bug)

That seems less like syntax checking to me and more like stylistic checking. Much like we use jsvalidate and jshint separately, I think this is two different separate tasks.

#13 in reply to: ↑ 12 @nacin
12 years ago

Replying to jorbin:

That seems less like syntax checking to me and more like stylistic checking. Much like we use jsvalidate and jshint separately, I think this is two different separate tasks.

Hence the difference between ERROR and WARNING in CSSLint.

#14 @michael-arestad
12 years ago

CSSlint is pretty handy for error-checking. I use it in Atom with several of the checks turned off. It's a good thing to include.

What would really be handy: A tool that tracked the number of each type of selector, the speed of each page, and potentially framerate, and the slowest selectors. I will buy whoever builds/implements this a nice bottle of your favorite type of alcohol.

#15 in reply to: ↑ 11 @netweb
12 years ago

Replying to nacin:

Replying to x2048:

1) all media queries will need to be rewritten to not include spaces between parentheses, or CSSLint will show errors.

No thanks. :) I patched CSSLint for this: โ€‹https://github.com/CSSLint/parser-lib/pull/125

Media Queries are currently defined in WP Core CSS coding standards as to not include spaces between parentheses:
Source: โ€‹https://make.wordpress.org/core/handbook/coding-standards/css/#media-queries

@media all and (max-width: 699px) and (min-width: 520px) {
 
        /* Your selectors */
}

Note: This WP Core CSS Standard will need updating once safe to do so, currently updates/changes to the CSS Handbook are not allowed, see โ€‹Core Contributor Handbook spreadsheet. CC: Ping @samuelsidler

This ticket was mentioned in IRC in #wordpress-dev by jorbin. โ€‹View the logs.


12 years ago

#17 in reply to: ↑ 11 @netweb
12 years ago

In 29792.patch:

  • Adds .csslintrc file with the rules per Nacin's suggested settings in comment 11, also explicitly declares the other available โ€‹rules as true for completeness/verbosity
  • New Grunt task grunt csslint
  • Grunt sub tasks grunt csslint:core and grunt csslint:build to lint CSS files in respective /src and /build folders
    • wp-admin/css/*.css
    • wp-content/themes/twenty{ten,eleven,twelve,thirteen,fourteen,fifteen}/**/*.css
    • wp-includes/css/*.css
  • Adds grunt csslint:core to precommit task grunt precommit
  • Adds grunt csslint:build to both grunt rtl and grunt colors tasks as a psuedo CSS validator after CSSJanus, SASS, and AutoPrefixer compilers have parsed existing CSS/SASS files.
  • Adds grunt csslint:core to Grunt build task grunt/grunt build before other CSS tasks are run
  • Adds grunt csslint:build to Grunt build task grunt/grunt build after other CSS tasks have ran

Notes:

  • If testing this patch in your workflow you may need to add --force to the task grunt precommit to get past any current errors until Core patches existing CSS issues per the CSS Lint rules here
  • A few tweaks are needed to existing Grunt watch tasks to include support for this, including it in this 29792.patch kind of made things rather funky as most of the existing CSS tasks need updating also to accommodate this.
  • Included in the patch are all WordPress Core themes, Twenty Ten, Eleven, Twelve, Thirteen, Fourteen, and Fifteen

@x2048
12 years ago

A new version of the wp-css-check tool. Now also checks for CSS property syntax (e.g. mistakes like "width :100px"). Also checks for !imporant properties without comments.

#18 @ocean90
12 years ago

  • Keywords 4.2-early added
  • Milestone 4.1 โ†’ Future Release

#19 @iseulde
12 years ago

  • Milestone Future Release โ†’ 4.2

has-patch 4.2-early so moving to 4.2.

This ticket was mentioned in โ€‹Slack in #core by drew. โ€‹View the logs.


12 years ago

#21 @F J Kaiser
12 years ago

Some notes I got for this ticket as my workflow involves all those tools.

  • Use one Grunt plugin for one task. Linters are good for linting, cleaners for cleaning, etc.
  • CSSComb should be used to define the order or CSS definitions per class, id, etc.
  • Linters are best used after each task has finished. Tasks can go wrong - seriously wrong. And Linters are there for the rescue. A stepped process with Linters running after each step helps debugging such problems in seconds. Without that: Happy debugging, there goes your beer with friends.

Summed up, the "no headaches" workflow is:

Clean CSS files in dev folder
Lint original files (SCSS/SASS/LESS Linter)
Preprocess (SCSS/SASS/LESS task) to current folder
Lint resulting CSS > Run CSSComb in current folder
Lint CSS
Run Minification to .cache folder
Lint CSS
Concatenate all resulting files to dist folder
Optionally remove unused CSS definitions

Tools like this are best served as git hooks. I know SVN, etc., but for those who are interested, here's โ€‹our Git PHP Hooks tool, the โ€‹accompanying library and โ€‹our Grunt GitHooks task.

Version 0, edited 12 years ago by F J Kaiser (next)

#22 follow-up: @nacin
12 years ago

Quick update on โ€‹https://github.com/CSSLint/parser-lib/pull/125. They want some changes to it, but it requires re-doing how a bunch of the tests currently work (not just the ones I added), so I think it'll get merged. Waiting to hear back. If anyone wishes to play with the tests over there, though, feel free.

#23 in reply to: ↑ 7 ; follow-up: @lkraav
12 years ago

Replying to GaryJ:

CSSComb does have a -l or --lint option, but it's not very helpful at the moment, not reporting lines and columns etc. CSSLint would be favourable over CSSComb just for error checking of specific non-standards issues.

Yes, this is โ€‹https://github.com/csscomb/csscomb.js/issues/245

I did extensive research on csslint vs csscomb yesterday for my own company. I found csscomb to be significantly further along for being able to define an exact detailed coding standard configuration and then having the tool not only lint to it, but automatically beautify your source and it actually coming out nearly 100% right. Yandex guys have built csscomb on โ€‹gonzales-pe, an AST generator which looks like a building block sitting at the same level where โ€‹parser-lib is sitting for csslint.

Both are very good tools and might very likely coexist in the build chain, but both also have a number of outstanding bugs that could really use attention. If there was a crowdfund for getting work done on them, I'd contribute in an instant. csscomb is the current choice for my team setup here, but as I'm understanding both a lot better now, I will be contributing to both and re-evaluating periodically. Wasn't able to find anything else at the same maturity level.

#25 in reply to: ↑ 23 @netweb
12 years ago

Replying to lkraav:

... both also have a number of outstanding bugs that could really use attention.

This is becoming an important issue for us, our tools need to be both functional and maintained and is one part of the reasoning for the change in #31332

Replying to lkraav:

โ€‹https://github.com/postcss/postcss may also be of interest here.

The proposed RTLCSS change in #31332 also uses POSTCSS also :)

This ticket was mentioned in โ€‹Slack in #core by netweb. โ€‹View the logs.


12 years ago

#27 in reply to: ↑ 22 ; follow-up: @nacin
12 years ago

Replying to nacin:

Quick update on โ€‹https://github.com/CSSLint/parser-lib/pull/125.

This was merged.

#28 in reply to: ↑ 27 @netweb
12 years ago

Replying to nacin:

Replying to nacin:

Quick update on โ€‹https://github.com/CSSLint/parser-lib/pull/125.

This was merged.

It was, sadly a new version, v0.2.6 that includes these changes is still yet to be released:
โ€‹https://github.com/CSSLint/parser-lib/issues/135 โ€‹https://github.com/CSSLint/parser-lib/releases

Peering into the rabbit hole, we then need v0.2.6 merged into a new release of CSSLint before grunt-contrib-csslint can be updated to include these changes...

The latest release of CSSLint is v0.10.0 released ~18 months ago, I couldn't find anything readily available as a roadmap of determining when the next release is scheduled though.

Edit: CSSLint v0.11.0 outstanding issues: โ€‹https://github.com/CSSLint/csslint/milestones/0.11.0 of which many have not been updated in quite a few months, I think we may need to seek an alternative to CSSLint, just as I noted in comment:25 above we are need to use projects that are routinely maintained and updated.

Last edited 12 years ago by netweb (previous) (diff)

#29 follow-up: @helen
12 years ago

  • Milestone 4.2 โ†’ Future Release

Punting - @netweb (or anyone else), if you have a chance to look for more maintained CSS linters, that would be wonderful.

#30 @obenland
12 years ago

  • Owner set to netweb
  • Status new โ†’ assigned

#31 @obenland
12 years ago

  • Keywords 4.2-early removed
  • Milestone Future Release โ†’ 4.3

#32 in reply to: ↑ 29 @netweb
11 years ago

  • Milestone 4.3 โ†’ Future Release

Current situation still stands, looking for a more maintained CSS linter

#33 @netweb
11 years ago

The following which is based on PostCSS (We like PostCSS tools) looks very promising as a replacement:

โ€‹https://github.com/stylelint/stylelint โ€‹https://stylelint.github.io/

Notes: It has not yet been released, actively being worked on as a replacement for CSSLint and CSSComb

#34 @netweb
11 years ago

Using โ€‹https://github.com/stylelint/stylelint with โ€‹https://github.com/stylelint/stylelint-config-wordpress

Modern CSS linter.
A PostCSS plugin
Drops in seamlessly alongside our existing Autoprefixer PostCSS plugin

Available rules โ€‹https://github.com/stylelint/stylelint/blob/master/docs/rules.md
Currently defined WordPress CSS rules โ€‹https://github.com/stylelint/stylelint-config-wordpress/blob/master/index.js

In 29792.1.diff

In 29792.2.diff an extra two rules are disabled:

To test either of these patches, first run npm install then running grunt precommit, grunt postcss:core, grunt postcss:colors, or grunt postcss (combined core and colors) should be enough to get you overwhelmed in CSS rule errors ;)

The rules in โ€‹https://github.com/stylelint/stylelint-config-wordpress were created based on our CSS coding standards
โ€‹https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/.

Now to test, tweak, and iterate these stylelint rules, our handbook CSS coding standards, and of course our CSS :)

This ticket was mentioned in โ€‹Slack in #core by netweb. โ€‹View the logs.


11 years ago

#36 @netweb
11 years ago

I've just refreshed 29792.1.diff and 29792.2.diff now that v0.1.0 of the config is released and published on npmjs.org

โ€‹https://www.npmjs.com/package/stylelint-config-wordpress

This ticket was mentioned in โ€‹Slack in #design by helen. โ€‹View the logs.


11 years ago

#38 @netweb
11 years ago

Related: #26905 Follow CSS coding standards for SASS/SCSS files

#39 @netweb
11 years ago

  • Keywords has-patch removed

Iโ€™ll refresh the patch here in a day or two once the direction on a couple of bug fixes upstream are known.

For the moment some quick stats compared my previous comments above where we had 4,000/5,000 warnings this is now down to ~200 warnings 29792-warnings-without-vendor-prefix.txt or 1,000 warnings (29792-warnings-with-vendor-prefix.txt) when including vendor prefixes (waiting on upstream bug fix for vendor prefixes).

A preliminary CSS patch 29792-css-patch.diff is also attached that shows what weโ€™ll be looking to commit in core. Iโ€™m attaching this CSS file now for review, if there are changes in this that you donโ€™t think should be there and we should have more rules to allow for that particular CSS formatting let me know and we can create more rules or iterate on the existing rules to allow these changes.

Bonus Points: The above also now includes SCSS linting and fixes that will be part of #26905

@Helen and @Nacin, if you'd be so kind to take a peek inside 29792-css-patch.diff and let me know any pain points you can foresee I can then continue on iterating these rules :)

#40 follow-ups: @nacin
11 years ago

  • Milestone Future Release โ†’ 4.4

This looks great, @netweb!

Rule questions:

  • src/wp-admin/css/colors/_admin.scss:83 uses // as a commenting style. I know this is allowed in SCSS, but do these rules mandate // over /* */? Should we always use /* */, since it's ultimately CSS? I don't see what stylelint rule this corresponds to.
  • I noticed the removal of spaces within parentheses. Spacing within parentheses is a thing WP likes to do. Can we keep them? I wonder if enforcing them ends up being less changes. (This would mean function-parentheses-space-inside: always.)
  • The requirement for a leading 0 for a decimal value (.1s or .25) seems weird. They get minified out anyway. And, it seems, we omit them all over the place. Which is more common in our codebase? What's common in the real world? (This would mean function-parentheses-space-inside: always).
  • string-quotes -- What is more common in our CSS, single quotes or double quotes? We already prefer single quotes in JS (unlike the jQuery project) and in PHP, so should we just keep using it in CSS too? Is there a reason to not be consistent? (I think double quotes look more natural when surrounding a font name, I'm just asking.)

Where we should change our CSS to conform to the rules, rather than add ignore rules:

  • We should only ignore declaration-block-semicolon-newline-after in L10n, and even then, I don't care. (It's actually done on purpose to group declarations together, so it's fine.)
  • For @-webkit-keyframes dice-color-change, we don't align things the way we do for @-webkit-keyframes customize-reload. We might as well make them standardized so they ignore the same things.
  • We shouldn't ignore number-zero-length-no-unit. Remove the units.

#41 in reply to: ↑ 40 @GaryJ
11 years ago

Replying to nacin:

  • src/wp-admin/css/colors/_admin.scss:83 uses // as a commenting style. I know this is allowed in SCSS, but do these rules mandate // over /* */? Should we always use /* */, since it's ultimately CSS? I don't see what stylelint rule this corresponds to.

// gets removed by default during the SCSS->CSS compiling, so it never makes it into CSS. There's a functional difference at play here, not just a code style preference.

  • The requirement for a leading 0 for a decimal value (.1s or .25) seems weird.

That's part of the documented โ€‹WP coding standards for CSS: "Use a leading zero for decimal values, including in rgba()."

  • string-quotes -- What is more common in our CSS, single quotes or double quotes? We already prefer single quotes in JS (unlike the jQuery project) and in PHP, so should we just keep using it in CSS too? Is there a reason to not be consistent? (I think double quotes look more natural when surrounding a font name, I'm just asking.)

Already documented in the CSS standards as: "Use double quotes rather than single quotes, and only when needed, such as when a font name has a space.". Custom fonts, using a single name, don't technically need any quotes, but some folks favour them for some reason.

#42 in reply to: ↑ 40 ; follow-up: @helen
11 years ago

Squee. :)

Replying to nacin:

  • src/wp-admin/css/colors/_admin.scss:83 uses // as a commenting style. I know this is allowed in SCSS, but do these rules mandate // over /* */? Should we always use /* */, since it's ultimately CSS? I don't see what stylelint rule this corresponds to.

Per @GaryJ, they are functionally different, but I'm not sure if/when we would have rules in our very limited use of SCSS that shouldn't be in the unminified compiled CSS.

  • I noticed the removal of spaces within parentheses. Spacing within parentheses is a thing WP likes to do. Can we keep them? I wonder if enforcing them ends up being less changes. (This would mean function-parentheses-space-inside: always.)

Let's please keep them and allow minification to strip them for minified files. As with PHP and JS, it's great for readability, which is extremely important for development files.

  • The requirement for a leading 0 for a decimal value (.1s or .25) seems weird. They get minified out anyway. And, it seems, we omit them all over the place. Which is more common in our codebase? What's common in the real world?

My recollection of why we went this route in our coding standards was also for human readability: . is easy to miss, 0. less so. I'd prefer to add them in where missing.

  • string-quotes -- What is more common in our CSS, single quotes or double quotes? We already prefer single quotes in JS (unlike the jQuery project) and in PHP, so should we just keep using it in CSS too? Is there a reason to not be consistent? (I think double quotes look more natural when surrounding a font name, I'm just asking.)

Double quotes somehow "feel" more right in CSS, I think possibly because it's a standard in many other projects. It's not just voodoo personal preference, promise :)

  • We shouldn't ignore number-zero-length-no-unit. Remove the units.

Patch seems to remove them - did I miss something?

This ticket was mentioned in โ€‹Slack in #core by jorbin. โ€‹View the logs.


11 years ago

#44 @netweb
11 years ago

@Helen

Could you please update both the description and example for "multiple comma-separated values" in the CSS handbook โ€‹https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/#values

Description: (Bold emphasis is mine and I'm seeking to clear up any ambiguity here)

Multiple comma-separated values for one property should be separated by either a space or a newline, including within rgba(). Newlines should be used for lengthier multi-part values such as those for shorthand properties like box-shadow and text-shadow. Each subsequent value after the first should then be on a new line, indented to the same level as the selector and then spaced over to left-align with the previous value.

Example: (I've copied and pasted verbatim the example source, white space for the last two lines should be updated)

.class { /* Correct usage of quotes */
        background-image: url(images/bg.png);
        font-family: "Helvetica Neue", sans-serif;
}

.class { /* Correct usage of zero values */
        font-family: Georgia, serif;
        text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5),
                                           0 1px 0 #fff;
}

Updated Example 1: (This example is based on the current description as it stands)
( 2 tabs and 5 spaces for that 2nd last line, but whitespace is weird here on Trac)

.class { /* Correct usage of quotes */
        background-image: url(images/bg.png);
        font-family: "Helvetica Neue", sans-serif;
}

.class { /* Correct usage of zero values */
        font-family: Georgia, serif;
        text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5),
                     0 1px 0 #fff;
}

Your commit message in r34637:

Normally when there are multiple comma-separated values in CSS, each one would go on its own indented line. However, Autoprefixer appears to be tripping up on gradients at the moment, so it's going to stay on one line until we investigate upstream.

As such, what I actually expect the example to be is, and is also what the majority of WordPress' CSS code base uses:
( 2 tabs indentation for the 2nd and 3rd last lines)

.class { /* Correct usage of quotes */
        background-image: url(images/bg.png);
        font-family: "Helvetica Neue", sans-serif;
}

.class { /* Correct usage of zero values */
        font-family: Georgia, serif;
        text-shadow: 
                0 -1px 0 rgba(0, 0, 0, 0.5),
                0 1px 0 #fff;
}

And finally the CSS handbook docs I believe should also match this and be something like this: (Emphasis mine)

Multiple comma-separated values for one property should be separated by either a space or a newline, including within rgba(). Newlines should be used for lengthier multi-part values such as those for shorthand properties like box-shadow and text-shadow. Each value should be on a new line, indented to the next tab indentation level of the parent selector and then left-aligned for each line.

If the above is not the case then we'll need to update both the Autoprefixer issue (โ€‹527) and pull request (โ€‹528) opened upstream by @Ocean90 to match our CSS standards.

Edit: See also the Stylelint โ€‹declaration-colon-newline-after and โ€‹declaration-colon-space-after rules.

Edit: Support for this was added to stylelint-config-wordpress in โ€‹stylelint/stylelint-config-wordpress/pull/12

Last edited 11 years ago by netweb (previous) (diff)

#45 in reply to: ↑ 43 ; follow-up: @netweb
11 years ago

Replying to slackbot:

This ticket was mentioned in โ€‹Slack in #core by jorbin. โ€‹View the logs.

Following up on questions raised in the above chat log:

jorbin [6:33 AM] For one: I donโ€™t know if I like having the rules live in a separate repository. That seems counter to how we have all our other tooling

helen [6:33 AM] i would agree.

First up I'll note that I am an "owner" of both the โ€‹https://github.com/stylelint/stylelint-config-wordpress and โ€‹https://www.npmjs.com/package/stylelint-config-wordpress repos and adding other maintainers such as yourselves Jorbin, Helen, Nacin etc has always been part of my greater plan as this WordPress and Stylelint project moves forward so that timely updates, pull requests, and deployments etc can be made by many and not be stuck waiting on any one individual.

Currently the only way to define Stylelint rules are in said separate repository, there are future plans to add support for a .stylelintrc file, similar to .jshint and the like though this has yet to be implemented.

I personally also see the separate repository as an advantage that allows similar shared benefits as the WordPress PHP Coding Standards project โ€‹here where a "shared" configuration is used by the wider WordPress community as a whole.

#46 in reply to: ↑ 43 @netweb
11 years ago

Replying to slackbot:

This ticket was mentioned in โ€‹Slack in #core by jorbin. โ€‹View the logs.

jorbin [6:34 AM] Have you given a thorough review to all the rules? Are you ok with them?

The full list of Stylineline rules is here: โ€‹https://github.com/stylelint/stylelint/blob/master/docs/rules.md

helen [6:35 AM] iโ€™m taking a second look right now, always hard to digest all at once

I still am, and have looked at all of these soooo many times ;)

jorbin [6:35 AM] Have we tested to make sure it will catch parse errors in the CSS correctly?

The current count for Stylinelints 87 rules is 7,068 tests

#47 @netweb
11 years ago

I'll work up a fresh patch that should give us an idea of where we're sitting in relation to both what we're looking at for the tooling side and for the CSS changes.

At the same time, I'll include feedback from both your Helen and Nacin comments comment:42 and comment:40 respectively with some answers and/or stats based on the issues/questions you both raised.

#48 @DrewAPicture
11 years ago

  • Keywords needs-patch added

@netweb Any word on an updated patch per your comment:47? 4.4 Beta1 is looming (Oct. 21).

#49 in reply to: ↑ 42 @netweb
11 years ago

Rule questions: String Quotes
Replying to nacin:

  • string-quotes -- What is more common in our CSS, single quotes or double quotes? We already prefer single quotes in JS (unlike the jQuery project) and in PHP, so should we just keep using it in CSS too? Is there a reason to not be consistent? (I think double quotes look more natural when surrounding a font name, I'm just asking.)

Replying to GaryJ:

Already documented in the CSS standards as: "Use double quotes rather than single quotes, and only when needed, such as when a font name has a space.". Custom fonts, using a single name, don't technically need any quotes, but some folks favour them for some reason.

Replying to helen:

Double quotes somehow "feel" more right in CSS, I think possibly because it's a standard in many other projects. It's not just voodoo personal preference, promise :)

Indeed, defined in our CSS Standards as Use double quotes rather than single quotes, and only when needed, such as when a font name has a space. โ€‹here

Stats: ~280 were changed to double quotes in r34011 with 14 new proposed changes here in this ticket versus 977 if we were to change to single quotes

#50 @netweb
11 years ago

Rule questions: Leading Zero

Replying to nacin:

  • The requirement for a leading 0 for a decimal value (.1s or .25) seems weird. They get minified out anyway. And, it seems, we omit them all over the place. Which is more common in our codebase? What's common in the real world? (This would mean number-leading-zero: always).

Replying to GaryJ:

That's part of the documented โ€‹WP coding standards for CSS: "Use a leading zero for decimal values, including in rgba()."

Replying to helen:

My recollection of why we went this route in our coding standards was also for human readability: . is easy to miss, 0. less so. I'd prefer to add them in where missing.

Per the above, it is listed as one of our standards, a quick straw poll of WP Australia was to also include the leading zero, primarily for readability per Helen's explanation above.

Stats: We would have to remove 399 leading zeros if we changed our standards to not include leading zeros versus adding 185 instances where leading zeros are currently missing.

#51 @netweb
11 years ago

Rule questions: SCSS Comments
Replying to nacin:

  • src/wp-admin/css/colors/_admin.scss:83 uses // as a commenting style. I know this is allowed in SCSS, but do these rules mandate // over /* */? Should we always use /* */, since it's ultimately CSS? I don't see what stylelint rule this corresponds to.

Replying to GaryJ:

// gets removed by default during the SCSS->CSS compiling, so it never makes it into CSS. There's a functional difference at play here, not just a code style preference.

Replying to helen:

Per @GaryJ, they are functionally different, but I'm not sure if/when we would have rules in our very limited use of SCSS that shouldn't be in the unminified compiled CSS.

My patch 29792-css-patch.diff and this specific line src/wp-admin/css/colors/_admin.scss:83 was a hack/test I had added but hadn't removed for the patchto workaround upstream node-sass issue โ€‹here that turns out to be a libsass issue โ€‹here and will ship as part of libsass 3.3 โ€‹https://github.com/sass/libsass/issues/1453

Per the above there is functional differences between both comment types and there shouldn't be any changes to existing SCSS for any comments making this a non-issue for now :)

#52 @netweb
11 years ago

Rule questions: Parentheses and whitespace

Replying to nacin:

  • I noticed the removal of spaces within parentheses. Spacing within parentheses is a thing WP likes to do. Can we keep them? I wonder if enforcing them ends up being less changes. (This would mean function-parentheses-space-inside: always.)

Replying to helen:

Let's please keep them and allow minification to strip them for minified files. As with PHP and JS, it's great for readability, which is extremely important for development files.

This is defined in our CSS handbook as: Do not pad parentheses with spaces โ€‹here with examples:

  • background-image: url(images/bg.png);
  • text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5),
  • @media all and (max-width: 699px) and (min-width: 520px) { <- Note see addendum below

Per the above the current rule configuration is: "function-parentheses-space-inside": [ 2, "never" ], and the full concise rule definition is โ€‹here

Stats: 394 changes required to remove this whitespace versus 816 changes to include this whitespace.


Circling back to comment 11 above:
Replying to nacin:

No thanks. :) I patched CSSLint for this: โ€‹https://github.com/CSSLint/parser-lib/pull/125

That pull request created for CSSLint would make the use of whitespace valid in media queries to coincide with the existing CSSLint rule that disallowed whitespace in media queries, as such both of the following would be valid CSSLint:

  • @media all and (max-width: 699px) and (min-width: 520px) {
  • @media all and ( max-width: 699px ) and ( min-width: 520px ) {

We can do the same to both allow and disallow whitespace by not defining the function-parentheses-space-inside rule.

This is indeed the case in why the media-query-parentheses-space-inside rule (โ€‹definition) has not been defined in the current stylelint-config-wordpress ruleset as Nacin had explicitly created a pull request to allow with and without whitespace in media queries and I was not going to define that rule because that decision had already been made in this ticket ;)

EDIT: My bad, turns out indeed media-query-parentheses-space-inside is currently defined as never i.e "media-query-parentheses-space-inside": [ 2, "never" ],, rule definition โ€‹here

Stats: To change our CSS to include this whitespace will be 262 changes or 74 changes to remove the white space in these media queries

Last edited 11 years ago by netweb (previous) (diff)

#53 @netweb
11 years ago

Alignment via Whitespace

Replying to nacin:

Where we should change our CSS to conform to the rules, rather than add ignore rules:

  • For @-webkit-keyframes dice-color-change, we don't align things the way we do for @-webkit-keyframes customize-reload. We might as well make them standardized so they ignore the same things.

I haven't changed any of these currently, all I have done is added comments so that Stylelint skips the rules that would cause failures, some examples of these are below, no doubt they are more "readable" using the extra whitespace formatting but at this stage we there are no Stylelint rules defined to allow this.

Do we want to remove the extra whitespace to match currently available rules or have new Stylelint rules added to allow whitespace for alignment and readability?

src/wp-admin/css/customize-controls.css

/* stylelint-disable block-opening-brace-newline-after, block-closing-brace-newline-before */
@-webkit-keyframes dice-color-change {
        0% { color: #d4b146; }
        50% { color: #ef54b0; }
        75% { color: #7190d3; }
        100% { color: #d4b146; }
}

@keyframes dice-color-change {
        0% { color: #d4b146; }
        50% { color: #ef54b0; }
        75% { color: #7190d3; }
        100% { color: #d4b146; }
}
/* stylelint-enable */

src/wp-admin/css/customize-controls.css

/* stylelint-disable block-opening-brace-newline-after, block-opening-brace-space-before, block-closing-brace-newline-before */
@-webkit-keyframes customize-reload {
        0%   { opacity: 0; }
        100% { opacity: 1; }
}

@keyframes customize-reload {
        0%   { opacity: 0; }
        100% { opacity: 1; }
}
/* stylelint-enable */

src/wp-admin/css/nav-menus.css

/* stylelint-disable block-opening-brace-newline-after, number-zero-length-no-unit, block-closing-brace-newline-before */
/* WARNING: The factor of 30px is hardcoded into the nav-menus JavaScript. */
.menu-item-depth-0 { margin-left: 0px; }
.menu-item-depth-1 { margin-left: 30px; }
.menu-item-depth-2 { margin-left: 60px; }
.menu-item-depth-3 { margin-left: 90px; }
.menu-item-depth-4 { margin-left: 120px; }
.menu-item-depth-5 { margin-left: 150px; }
.menu-item-depth-6 { margin-left: 180px; }
.menu-item-depth-7 { margin-left: 210px; }
.menu-item-depth-8 { margin-left: 240px; }
.menu-item-depth-9 { margin-left: 270px; }
.menu-item-depth-10 { margin-left: 300px; }
.menu-item-depth-11 { margin-left: 330px; }

.menu-item-depth-0 .menu-item-transport { margin-left: 0px; }
.menu-item-depth-1 .menu-item-transport { margin-left: -30px; }
.menu-item-depth-2 .menu-item-transport { margin-left: -60px; }
.menu-item-depth-3 .menu-item-transport { margin-left: -90px; }
.menu-item-depth-4 .menu-item-transport { margin-left: -120px; }
.menu-item-depth-5 .menu-item-transport { margin-left: -150px; }
.menu-item-depth-6 .menu-item-transport { margin-left: -180px; }
.menu-item-depth-7 .menu-item-transport { margin-left: -210px; }
.menu-item-depth-8 .menu-item-transport { margin-left: -240px; }
.menu-item-depth-9 .menu-item-transport { margin-left: -270px; }
.menu-item-depth-10 .menu-item-transport { margin-left: -300px; }
.menu-item-depth-11 .menu-item-transport { margin-left: -330px; }

body.menu-max-depth-0 { min-width: 950px !important; }
body.menu-max-depth-1 { min-width: 980px !important; }
body.menu-max-depth-2 { min-width: 1010px !important; }
body.menu-max-depth-3 { min-width: 1040px !important; }
body.menu-max-depth-4 { min-width: 1070px !important; }
body.menu-max-depth-5 { min-width: 1100px !important; }
body.menu-max-depth-6 { min-width: 1130px !important; }
body.menu-max-depth-7 { min-width: 1160px !important; }
body.menu-max-depth-8 { min-width: 1190px !important; }
body.menu-max-depth-9 { min-width: 1220px !important; }
body.menu-max-depth-10 { min-width: 1250px !important; }
body.menu-max-depth-11 { min-width: 1280px !important; }
/* stylelint-enable */

src/wp-admin/css/customize-nav-menus.css

/* stylelint-disable block-opening-brace-newline-after, block-opening-brace-space-before, selector-combinator-space-before, block-closing-brace-newline-before */

/* WARNING: The 20px factor is hard-coded in JS. */
.menu-item-depth-0  { margin-left: 0;     }
.menu-item-depth-1  { margin-left: 20px;  }
.menu-item-depth-2  { margin-left: 40px;  }
.menu-item-depth-3  { margin-left: 60px;  }
.menu-item-depth-4  { margin-left: 80px;  }
.menu-item-depth-5  { margin-left: 100px; }
.menu-item-depth-6  { margin-left: 120px; }
.menu-item-depth-7  { margin-left: 140px; }
.menu-item-depth-8  { margin-left: 160px; } /* Not likely to be used or useful beyond this depth */
.menu-item-depth-9  { margin-left: 180px; }
.menu-item-depth-10 { margin-left: 200px; }
.menu-item-depth-11 { margin-left: 220px; }

/* @todo handle .menu-item-settings width */
.menu-item-depth-0  > .menu-item-bar { margin-right: 0;     }
.menu-item-depth-1  > .menu-item-bar { margin-right: 20px;  }
.menu-item-depth-2  > .menu-item-bar { margin-right: 40px;  }
.menu-item-depth-3  > .menu-item-bar { margin-right: 60px;  }
.menu-item-depth-4  > .menu-item-bar { margin-right: 80px;  }
.menu-item-depth-5  > .menu-item-bar { margin-right: 100px; }
.menu-item-depth-6  > .menu-item-bar { margin-right: 120px; }
.menu-item-depth-7  > .menu-item-bar { margin-right: 140px; }
.menu-item-depth-8  > .menu-item-bar { margin-right: 160px; }
.menu-item-depth-9  > .menu-item-bar { margin-right: 180px; }
.menu-item-depth-10 > .menu-item-bar { margin-right: 200px; }
.menu-item-depth-11 > .menu-item-bar { margin-right: 220px; }

/* Submenu left margin. */
.menu-item-depth-0  .menu-item-transport { margin-left: 0;      }
.menu-item-depth-1  .menu-item-transport { margin-left: -20px;  }
.menu-item-depth-3  .menu-item-transport { margin-left: -60px;  }
.menu-item-depth-4  .menu-item-transport { margin-left: -80px;  }
.menu-item-depth-2  .menu-item-transport { margin-left: -40px;  }
.menu-item-depth-5  .menu-item-transport { margin-left: -100px; }
.menu-item-depth-6  .menu-item-transport { margin-left: -120px; }
.menu-item-depth-7  .menu-item-transport { margin-left: -140px; }
.menu-item-depth-8  .menu-item-transport { margin-left: -160px; }
.menu-item-depth-9  .menu-item-transport { margin-left: -180px; }
.menu-item-depth-10 .menu-item-transport { margin-left: -200px; }
.menu-item-depth-11 .menu-item-transport { margin-left: -220px; }

/* WARNING: The 20px factor is hard-coded in JS. */
.reordering .menu-item-depth-0  { margin-left: 0;     }
.reordering .menu-item-depth-1  { margin-left: 15px;  }
.reordering .menu-item-depth-2  { margin-left: 30px;  }
.reordering .menu-item-depth-3  { margin-left: 45px;  }
.reordering .menu-item-depth-4  { margin-left: 60px;  }
.reordering .menu-item-depth-5  { margin-left: 75px;  }
.reordering .menu-item-depth-6  { margin-left: 90px;  }
.reordering .menu-item-depth-7  { margin-left: 105px; }
.reordering .menu-item-depth-8  { margin-left: 120px; } /* Not likely to be used or useful beyond this depth */
.reordering .menu-item-depth-9  { margin-left: 135px; }
.reordering .menu-item-depth-10 { margin-left: 150px; }
.reordering .menu-item-depth-11 { margin-left: 165px; }

.reordering .menu-item-depth-0  > .menu-item-bar { margin-right: 0;     }
.reordering .menu-item-depth-1  > .menu-item-bar { margin-right: 15px;  }
.reordering .menu-item-depth-2  > .menu-item-bar { margin-right: 30px;  }
.reordering .menu-item-depth-3  > .menu-item-bar { margin-right: 45px;  }
.reordering .menu-item-depth-4  > .menu-item-bar { margin-right: 60px;  }
.reordering .menu-item-depth-5  > .menu-item-bar { margin-right: 75px;  }
.reordering .menu-item-depth-6  > .menu-item-bar { margin-right: 90px;  }
.reordering .menu-item-depth-7  > .menu-item-bar { margin-right: 105px; }
.reordering .menu-item-depth-8  > .menu-item-bar { margin-right: 120px; }
.reordering .menu-item-depth-9  > .menu-item-bar { margin-right: 135px; }
.reordering .menu-item-depth-10 > .menu-item-bar { margin-right: 150px; }
.reordering .menu-item-depth-11 > .menu-item-bar { margin-right: 165px; }
/* stylelint-enable */
Last edited 11 years ago by netweb (previous) (diff)

#54 @netweb
11 years ago

Disallow units for zero lengths
Replying to nacin:

Where we should change our CSS to conform to the rules, rather than add ignore rules:

  • We shouldn't ignore number-zero-length-no-unit. Remove the units.

Replying to helen:

Patch seems to remove them - did I miss something?

Indeed Disallow units for zero lengths is included in the patch using the number-zero-length-no-unit rule , full definition โ€‹here

#55 @netweb
11 years ago

Summarising the above comments for feedback from @nacin, @helen, and @jorbin:

[ ] Comment 44: Multiple comma-separated values
[ ] Comment 45: NPM module stylelint-config-wordpress configuration
[ ] Comment 46: Stylelint rule unit tests
[ ] Comment 49: String Quotes
[ ] Comment 50: Leading Zero
[ ] Comment 51: SCSS Comments
[ ] Comment 52: Parentheses and whitespace
[ ] Comment 53: Alignment via Whitespace
[ ] Comment 54: Disallow units for zero lengths

#56 in reply to: ↑ 45 ; follow-up: @helen
11 years ago

Replying to netweb:

First up I'll note that I am an "owner" of both repos

Who "owns" the repository doesn't erase the fact that it's separate AND external. I'm still not very excited about the prospect of having this be external, especially while we're still working things out. Having it external AND used in core makes it "blessed", when it's not something I'd be comfortable calling final for some time yet.

Currently the only way to define Stylelint rules are in said separate repository, there are future plans to add support for a .stylelintrc file, similar to .jshint and the like though this has yet to be implemented.

That's too bad. I would rather punt on this, then.

By the way, you don't need to keep citing the WP CSS Coding Standards as a biblical source - it is a living/evolving document that has very little to do with our long-existing mess of CSS, and I wrote them in the first place. :)

#57 @jorbin
11 years ago

I think it might make sense to bring this ticket back to just focussing on syntax checking, rather than also focusing on style linting. If we had a tool that could tell developers that a css files lacks an expected semi colon or you are attempting to set the magin property instead of margin, I would support getting that committed quickly. Full on linting for style clearly is bound to get bogged down and take much longer to get committed.

#58 in reply to: ↑ 56 @netweb
11 years ago

Replying to helen:

Replying to netweb:

First up I'll note that I am an "owner" of both repos

Who "owns" the repository doesn't erase the fact that it's separate AND external. I'm still not very excited about the prospect of having this be external, especially while we're still working things out. Having it external AND used in core makes it "blessed", when it's not something I'd be comfortable calling final for some time yet.

Right, I see your point, see below, maybe in the future we can revisit this and bless it if deserved ;)

Currently the only way to define Stylelint rules are in said separate repository, there are future plans to add support for a .stylelintrc file, similar to .jshint and the like though this has yet to be implemented.

Over the weekend Stylelint 2.0.0 was released with full support for .stylelintrc, patch 29792.3.diff uses this new configuration file rather than the previous "external repo".

That's too bad. I would rather punt on this, then.

I'm updating the CSS patch based on the rules defined in 29792.3.diff and we can go from there on punting decisions

By the way, you don't need to keep citing the WP CSS Coding Standards as a biblical source - it is a living/evolving document that has very little to do with our long-existing mess of CSS, and I wrote them in the first place. :)

I linked to these because I needed to cite "something" for any decisions I had made in regard to the rules I'd chosen was the only reason :)

Edit Note: Patch 29792.3.diff also includes the following patch as these updated dependancies are required 34177-autoprefixer-postcss.diff

Run npm install to update dependancies and run either grunt precommit or grunt postcss:lint to run the Stylelint linter :)

Last edited 11 years ago by netweb (previous) (diff)

#59 @jorbin
11 years ago

  • Milestone 4.4 โ†’ Future Release

I tested and stylint doesn't detect syntax errors. It does a great job of detecting formatting errors, but it misses things like argin: 20px; AKA, I can still jorbin my css.

Punting this from 4.4 while work continues.

This ticket was mentioned in โ€‹Slack in #core by helen. โ€‹View the logs.


11 years ago

#61 @helen
11 years ago

In 37363:

Revive grunt-rtlcss, which does not appear to enjoy syntax errors.

props netweb.
see #36753, #29792.

This ticket was mentioned in โ€‹Slack in #core by netweb. โ€‹View the logs.


9 years ago

This ticket was mentioned in โ€‹Slack in #core-editor by netweb. โ€‹View the logs.


8 years ago

This ticket was mentioned in โ€‹Slack in #core-css by dd32. โ€‹View the logs.


7 years ago

This ticket was mentioned in โ€‹Slack in #core-css by peterwilsoncc. โ€‹View the logs.


7 years ago

#66 @netweb
5 years ago

  • Summary Grunt: Add a precommit task to check for CSS syntax errors โ†’ Grunt: Add a stylelint precommit task to check for CSS syntax errors

This ticket was mentioned in โ€‹Slack in #core-css by ryelle. โ€‹View the logs.


5 years ago

#68 @afercia
3 months ago

  • Focuses css coding-standards added

This ticket was mentioned in โ€‹PR #12930 on โ€‹WordPress/wordpress-develop by โ€‹@sukhendu2002.


3 months ago
#69

  • Keywords has-patch added; needs-patch removed

#70 @afercia
3 months ago

  • Focuses accessibility added
  • Milestone Future Release โ†’ 7.2
  • Owner changed from netweb to afercia
  • Type enhancement โ†’ defect (bug)

12 years later, I'd really like to revive this ticket and try it for the next release cycle.

I'm concerned by the lack of focus in implementing modern tooling to test and maintain Core. A clear technical vision in a modern project should prioritize any tools that make the developers experience better and help maintenance.

To me, in modern web development the lack of any CSS coding standards enforcement is a bug. Raising the ticket type accordingly.

Stylelint isn't just about syntax checking and enforcing coding standards. It also allows to add custom rules. Worth reminding postcss already performs some basic syntax checking.

Gutenberg uses Stylelint since a few years. It added custom rules to disallow โ€‹the order property and all โ€‹the *-reverse values, which are in most of the cases harmful for accessibility. As such I'm going to add the accessibility focus to this ticket.

I'm going to link a 'work in progress' pull request soon.

Last edited 3 months ago by afercia (previous) (diff)

#71 @afercia
3 months ago

@sukhendu2002 thank you for your first PR. It was helpful to me but I'm going to link another one that brings in the rules we'd like to use and some more things.

This ticket was mentioned in โ€‹PR #12934 on โ€‹WordPress/wordpress-develop by โ€‹@afercia.


3 months ago
#72

Trac ticket: https://core.trac.wordpress.org/ticket/29792

Work In Progress (WIP) to add Stylelint CSS coding standards rules enforcement to Core.

So far, this PR adds:

  • An NPM script with the same set or rules used in Gutenberg.
  • A Grunt task that can be run individually and is also part of grunt precommit:css.

For now, it is important to check the following:

  • Whether the excluded paths make sense.
  • Whether there is the need to add more files to scan.
  • Make sure that the results are consistent when running:
    • npm run lint:css
    • grunt lint:css

As of Core revision 63157, the Stylelint scan reports the following:

โœ– 2823 problems (2823 errors, 0 warnings)
  2135 errors potentially fixable with the "--fix" option.

Most of these errors are trivial fixes.

The scan also reports one occurrence of the order property and one of the row-reverse value, which confirms the custom rules work as expected.

Nest steps: Add a related GitHub Action.

## Use of AI Tools

None.

โ€‹@afercia commented on โ€‹PR #12934:


3 months ago
#73

Nice, given the new lint:css grunt task is added to grunt precommit:css, it already runs on the GitHub Actions and the Run SASS precommit tasks step of the update-built-files job fails.

#74 @afercia
3 months ago

I'd like to point out that, as @helen said in #comment:56, โ€‹the WordPress CSS Coding Standards are a living document. To me, it is way more important having a consistent set of rules between Core and Gutenberg. If something in the CSS coding standards needs to be changed, let's change it.

โ€‹@afercia commented on โ€‹PR #12934:


3 months ago
#75

The first run of โ€‹the css linter job on this PR reports 2746 errors while locally I get 2823 errors. Will look into it. At a first check it appears some files aren't scanned in the job:

  • All files within src/wp-includes/js/ are missing.
  • All admin color schemes files except one are missing. For example:
    • src/wp-admin/css/colors/midnight/colors.css is missing
    • src/wp-admin/css/colors/sunrise/colors.scss is there instead

โ€‹@afercia commented on โ€‹PR #12934:


3 months ago
#76

The bundled themes twentytwenty and twentytwentyone have their own Stylelint configuration.

The one for twentytwenty is broken:

  • It uses the stylelint-config-wordpress package, which is now deprecated.
  • It uses the stylelint-a11y plugin, which is unmaintained and imcompatible with latest versions of Stylelint.

Although there are โ€‹working forks of the stylelint-a11y plugin, I'd rather entirely remove the Stylelint configuration for both themes.

Even after making them work, the linting for both themes reports several errors, mostly because of outdated configuration:

  • twentytwenty: 372 errors
  • twentytwentyone: 135 errors

It appears the linting scripts of these two themes haven't been used for a long time. Likely, they have been intensively used during the themes development but now they are way behind.

Also, bundled themes are part of Core. To me, it makes sense to have a ceentralized tool to lint everything.

In the latest commit I added a npm run lint:css:themes script that only scans the themes directory, which is excluded from the main npm run lint:css. It reports 15570 errors :)

As said earlier, for now it's best to focus on the functionality. The set of rules can be refined later. It will need some adjustments as some rules aren't applicable in Core, for example selector-class-pattern and selector-id-pattern are specific to Gutenberg.

This ticket was mentioned in โ€‹Slack in #accessibility by afercia. โ€‹View the logs.


3 months ago

โ€‹@afercia commented on โ€‹PR #12934:


3 months ago
#78

Regarding the a11y rules that were used in twentytwenty, I tried to re-add them to the Core Stylelint configuration by using โ€‹the compatible stylelint-a11y plugin fork. It's a useful experiment to check a few CSS patterns that are potentially harmful for accessibility:

a11y/no-outline-none
Only 5 occurrences detected. This rule attempts to detext the removal of the outline for a cofus style without an alternative e.g. a border or box-shadow change, While it can't be fully trusted, I'd find useful adding in to the configuration.

a11y/selector-pseudo-class-focus
92 occurrences. This one is a little trickier. It considers invalid any 'hover' style that is not accompanined by a :focus style. For example, it expects that .nav-tab:hover is used together with :focus`.
I tend to think this rule would produce too many false positives. In core, the focus style is often provided by styles that are not paired with the :hover style.

Among other rules provided by the plugin, this one might be useful:

โ€‹media-prefers-reduced-motion
It tries to detect when an animation is used outside of a media-prefers-reduced-motion media query, which is something we observed it is sometimes missed during development.

I would suggest to experiment these rules at a later stage, after the initial configuration is proved to be stable and reliable,

#79 @afercia
3 months ago

I think the PR at โ€‹https://github.com/WordPress/wordpress-develop/pull/12934 is ready for a first round of testing and feedback.

It adds four NPM scripts, plus a Grunt task:

npm run lint:css
npm run lint:css:fix
npm run lint:themes
npm run lint:themes:fix
grunt lint:css 

More details on the PR.

Suggestion: to get a better sense of the auto-fixes Stylelint can apply, you can test fixing one CSS file at a time, for example:

npx stylelint src/wp-admin/css/common.css --fix 

I'd like to start actually linting the CSS files, to reduce the amount of errors before the Stylelint configuration gets into Core. I will create a new ticket.

โ€‹@afercia commented on โ€‹PR #12934:


2 months ago
#80

I would appreciate some feedback on โ€‹the threshold mechanism implemented for the rule selector-no-qualifying-type which I downgraded to severity: warning.

This rule, accordingly to the CSS coding standards, flags all the over-qualified selectors like, for example:

  • div.container
  • p.popular-tags
  • input[type="text"]

These are all violations. The problem with it is that there are 1815 such violations. We can't change these selectors otherwise we would trigger a storm of CSS-specificity issues all over. That's the reason why I set them to 'warning'. However, I also want this type of violation to not increase in the future. So the idea is:

  • When a new violation is introduced, trigger an error.
  • When an existing violation gets fixed, trigger an error to require updating the threshold limit.
  • No change: nothing happens.

โ€‹@afercia commented on โ€‹PR #12934:


2 months ago
#81

Regarding this point:

Also, I'd love to find ways to utilize the related scripts already maintained within gutenberg, expanding if necessary rather than adding new scripts

I would have loved that too. That's why I started a conversation on a new Gutenberg issue. Looks like things aren't as ideal as necessary to do that. You can read the relevant parts of the conversation starting from โ€‹this comment.

expanding if necessary

Thats what this PR does. It uses @wordpress/stylelint-config/scss-stylistic and expands or disables rules as necessary to meet the WordPress CSS Coding Standards.

โ€‹@afercia commented on โ€‹PR #12934:


2 months ago
#82

The following is a recap of the differences in the Stylelint configuration between the one in this PR for Core and the one โ€‹used here in Gutenberg. Note that, as I learned from this comment โ€‹https://github.com/WordPress/gutenberg/issues/81349#issuecomment-5396606954 it appears that in Gutenberg different packages may use different rulesets so the comparison can't be fully accurate as on Gutenberg it varies depending on the analyzed package.

Methodology:
Used the Stylelint --print-config option to print the configuration for a couple example files in Core and Gutenberg. The output was then compared to identify any differences or customizations.

Commands used:
From the wordpress-develop project root:
npx stylelint src/wp-admin/css/common.css --print-config
From the gutenberg project root:
npx stylelint packages/editor/src/style.scss --print-config

Rule Core Gutenberg WP CSS Coding Standards
โ€‹at-rule-empty-line-before always except: blockless-after-blockless / ignore: first-nested, after-comment null one empty line between any block
โ€‹declaration-property-value-disallowed-list none custom regex to disallow some gutenberg-specific values N/A
โ€‹declaration-property-unit-allowed-list "line-height": [] "line-height": px unitless values
โ€‹font-family-no-missing-generic-family-keyword true with ignore dashicons true WP needs to ignore dashicons
โ€‹font-weight-notation numeric null numeric values
โ€‹function-disallowed-list rgb none rgb not allowed
โ€‹rule-empty-line-before always except: first-nested / ignore: after-comment null one empty line between any block
โ€‹selector-no-qualifying-type true/warning none avoid over-qualified selectors
โ€‹value-keyword-case lower ignoreKeywords: currentColor, optimizeLegibility null all values must be lowercase
โ€‹@stylistic/max-empty-lines 1 2 Changed to 1 in the proposal to update the standards
โ€‹@stylistic/selector-descendant-combinator-no-non-space true none needed to properly handle indentation later
โ€‹@stylistic/selector-list-comma-space-after always-single-line none needed to properly handle indentation later

โ€‹@afercia commented on โ€‹PR #12934:


8 weeks ago
#83

Latest commit reverts all changes related to themes.
Any improvement for themes should be addressed separately, including the broken configuration for twentytwenty.

#84 @afercia
8 weeks ago

A couple weeks ago in the Gutenberg repository โ€‹https://github.com/WordPress/gutenberg/pull/80738 upgraded the Stylelint version to ^17.14.1 togeher with other relevant Stylelint plugins for example stylelint-plugin-logical-css was upgraded to ^2.1.0.

Stylelint 17 adds a few more default rules so that โ€‹https://github.com/WordPress/wordpress-develop/pull/12934 will need to be updated at some point.

Ideally, there should be only one, unique, source of truth for the CSS linting rules WordPress uses for both Core and Gutenberg. Ideally, Core should just use what is provided by the @wordpress/scripts package.

However, the Stylelint rules configuration in Gutenberg deviates from the WordPress CSS Coding Standards. This creates an alignment issue between the two projects that will have to be addressed sooner or later.

โ€‹@afercia commented on โ€‹PR #12934:


8 weeks ago
#85

A couple weeks ago the Stylelint version was upgraded to 17 in โ€‹https://github.com/WordPress/gutenberg/pull/80738.
See comment on the Trac ticket at https://core.trac.wordpress.org/ticket/29792#comment:84

#86 @lancewillett
7 weeks ago

In an attempt to move this along, here's how I see the two suggested fixes. I applied each to current trunk and ran grunt lint:css.

โ€‹PR 12930: a minimal check that passes today. Three rules: block-no-empty, length-zero-no-unit, and property-no-unknown. It catches a typo'd property like argin, units on zero values, and empty blocks. Syntax errors such as a missing semicolon or an unclosed block fail too, which was the original ask here.

โ€‹PR 12934: the full rule set, aligned with Gutenberg, but not ready yet. On trunk it reports 2,745 errors. The selector-no-qualifying-type count is now 1,823 against a threshold of 1,819. Because lint:css runs inside precommit:css, "Core running from src" fails on all three OSes. The Stylelint 17 update from comment:84 is still to come.

They don't conflict. PR 12934's config flags everything PR 12930 does. The one overlap is the config file: if both .stylelintrc.json and .stylelintrc.js exist, Stylelint reads the .json one, so PR 12934 would need to delete it.

My suggestion: commit PR 12930 now so trunk gets a passing check in 7.2, and keep this ticket open for PR 12934.

@afercia, does that work for you? @sukhendu2002, thank you for the patch.

โ€‹@lancewillett commented on โ€‹PR #12930:


7 weeks ago
#87

Thanks for this, @Sukhendu2002. I applied it to current trunk and grunt lint:css passes.

I've posted how I see this PR and #12934 fitting together on Trac #29792. The short version: I'd like to commit this one first as a minimal check, with #12934 building on it. Discussion is best kept on the ticket.

โ€‹@lancewillett commented on โ€‹PR #12934:


7 weeks ago
#88

@afercia, I've posted how I see this PR and #12930 fitting together on Trac #29792.

The short version: on current trunk this PR reports 2,745 errors and the warning threshold has drifted to 1,823 against 1,819. #12930's three rules are a subset of this config, so I'd like to commit it first and keep the ticket open for this one. Would you be OK with that?

โ€‹@afercia commented on โ€‹PR #12934:


6 weeks ago
#89

The short version: on current trunk this PR reports 2,745 errors and the warning threshold has drifted to 1,823 against 1,819. #12930's three rules are a subset of this config, so I'd like to commit it first and keep the ticket open for this one. Would you be OK with that?

@lancewillett thanks for your review!

the warning threshold has drifted to 1,823

That means contributors (including myself!) keep introducing overqualified CSS selectors that go against the CSS Coding Standards. To me, that's one more reason to prioritize enforcing the coding standards.

I see a few problems with โ€‹https://github.com/WordPress/wordpress-develop/pull/12930

  • First, the Stylelint configuration should extend what we have now in the WordPress packages, like this PR does by extending @wordpress/stylelint-config/scss-stylistic. The rationale is that, ideally, in the future the rules in Core and in the Gutenberg repo should converge and use the same ruleset. Ideally, WordPress should use a unique 'source of truth' to enforce its coding standards.
  • The config in #12930 is in json format, while in this PR is in JS, which is more flexible.
  • Minor: the configuration of the rule length-zero-no-unit isn't equivalent:
    • in #12930 is just true. -in this PR, it inherits from stylelint-config/scss-stylistic and it is:
"length-zero-no-unit": [
	true,
	{
	"ignore": [
		"custom-properties"
	],
	"ignoreFunctions": [
		"var"
	]
	}
],
  • #12930 doesn't lint .scss files, which are now used in Core.
  • The grunt task in #12930 uses npx and passes wp-scripts' as arg, not sure that's the best option.
  • The --ignore-pattern' in #12930 is very limited while this PR uses .stylelintignore with more comprehensive ignore patterns.

More importantly, I don't see much point in enforcing only three rules as #12930 does. The goal of this PR is _enforcing the CSS coding standards. It's not about checking for syntax errors.

Reminder that the concerns you posted on the ticket related to syntax errors such as a missing semicolon are already caught by postcss. Just run precommit:css on current trunk and it will fail for basic syntax errors.

That said, if you feel strongly with merging #12930, I have no objections, but:

  • What is the real value by merging #12930 ? Personally, I don't see much value.
  • It will require more work when configuring Stylelint to be more useful.

#90 @afercia
6 weeks ago

@lancewillett thanks for your review, much appreciated. I posted my reply on the โ€‹PR 12934, I think it is automatically visible here as well.

Regarding your concern about syntax errors:

Syntax errors such as a missing semicolon or an unclosed block fail too, which was the original ask here.

Reminder that syntax errors such as a missing semicolon are already caught by postcss. Just run precommit:css on current trunk and it will fail for basic syntax errors.

The goal of โ€‹PR 12934 is enforcing the WordPress CSS Coding Standards, it's not about syntax checking.

โ€‹@lancewillett commented on โ€‹PR #12930:


6 weeks ago
#91

Thanks @Sukhendu2002. Per the discussion on Trac #29792, PR 12934 now covers these three rules and more, so I'm closing this one. I've added you as a reviewer there; props will include you.

#92 @lancewillett
6 weeks ago

@afercia you're correct about syntax errors, postcss already catches them. PR 12930's 3 rules are all in PR 12934's config, so I closed PR 12930 and moved this forward on your suggested change instead.

I pushed three commits to PR 12934:

  1. Ran Stylelint's auto-fix over the core CSS. Formatting only.
  2. Swapped the custom warning-threshold scripts for Stylelint's own suppressions file. It records today's remaining problems, so the check only fails on new ones. Fixing old problems needs no bookkeeping.
  3. Made the precommit task treat the Stylelint config files as configuration.

The build now passes. What's left in the baseline, mostly old class and ID names we can't rename, can be follow-up tickets.

@sukhendu2002 thank you for the first patch. If you can test PR 12934, that would help a lot. Props to both of you when this lands.

AI use: I used Claude Code for the analysis and a first draft of the lint runner. I reviewed and ran every commit myself.

โ€‹@lancewillett commented on โ€‹PR #12934:


6 weeks ago
#93

@afercia I pushed 3 new commits to this branch: autofix pass, Stylelint's own suppressions file instead of the threshold scripts, and the precommit config-file list.

What else is needed to move this closer to landing? @Sukhendu and I can help test & review.

#94 @afercia
6 weeks ago

@lancewillet thank you for working on โ€‹PR 12934, much appreciated.
Sharing some thoughs on how to move on. Pardon the long comment.

1
The most important missing piece is a proposal to update the CSS Coding Standards, to be published on Make. I did prepare a draft a few weeks ago. I also submitted โ€‹a PR to update the coding standards in the WordPress Coding Standards Docs repository.

The most impactful change in PR 12934 is the proposal to change the CSS class selector naming convention to use the BEM-like convention that is already used in Gutenberg (although it's based on the components names there). Other changes are minor. Still, there is the need to publish an official proposal and wait for it to be approved.

I'm not an English native speaker so any help with prose, language, and tone in the proposal post would be appreciated.

2
Treating the Stylelint config files as configuration and run the prerelease task when modified makes much sense, thanks for that.

3
I did not realize we could use the Stylelint's built-in suppressions file although I did see it in use on Gutenberg. That's way cleaner, thanks for that. However, I believe the current baseline isn't as clean as it could be. See following point.

4
PR 12934 now contains auto-fixed files. It is worth noting that I did prepare โ€‹a series of PRs to lint all the CSS files. Some of them (18) are already merged. The remaining ones contain stylelint-disable* comments and need to wait.

In that series of PRs:

  • I manually fixed all the fixable violations that the auto-fixer can't fix. That would give us a much cleaner baseline.
  • I did add local stylelint-disable* comments where necessary.

I'm not sure we should start with a baseline that suppresses many fixable violations. I believe the only rules that should go in the suppressions list are the ones that we can't fix because of backwards compatibility issues. All the other ones should be fixed either with the auto-fixer or manually. I believe we should 'globally' suppress only these rules:

  • selector-class-pattern
  • selector-id-pattern
  • selector-no-qualifying-type

5
How to move on? I would prefer to:

  • Remove from PR 12934 all the auto-fixed files (23, which matches the remaining PRs in my series).
  • Merge all the PRs from my series as they contain also many manual fixes. With the following changes:
    • They need to be rebased on top of current trunk.
    • Remove all the stylelint-disable* comments related to the 3 rules above except where it make sense to disable them locally to have also a disable description comment in place.
    • Keep other stylelint-disable* comments where the description clarifies the disable reason.
    • I'd really, really like that in the future any contributor will be required to take ownership when they add a disable comment. Inline disable comments should be used for that purpose and the current Stylelint configuration requires a description. I'm very attached to this pattern especially for rules that may potentially impact accessibility, like the order property. The global suppressions in stylelint-suppressions.json won't allow adding disable reason descriptions.
  • This way, we can start with a much cleaner baseline.
  • After that, we can rebase PR 12934 and re-generate the suppressions file making sure it only contains suppressions for hte 3 rules above.
  • Alternatively, we could incorporate the PRs from my series in PR 12934 but it's already a huge PR that touches many files, I'd rather make it as small as possible and lint the files one at a time.

6
If no objections, I can start merging the 23 PRs from my series. Still, an official proposal needs to be published on Make to complete this task.

โ€‹@afercia commented on โ€‹PR #12934:


6 weeks ago
#95

I will detail further in a following comment.

See https://core.trac.wordpress.org/ticket/29792#comment:94

#96 @afercia
6 weeks ago

If and when this gets merged, as a final step I would like to report a suggestion I received about the documentation handbooks.

The CSS Coding Standards for the block editor, which are published separately on โ€‹the Block Editor Handbook, should instead be published on the WordPress Coding Standards Handbook page at โ€‹https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/

The Block Editor Handbook should only link to the WordPress Coding Standards Handbook page, which is the canonical source for the coding standards.

This would help avoiding confusion and the split of documentation sources which is part of how we ended up with not-aligned coding standards.

โ€‹@afercia commented on โ€‹PR #12934:


6 weeks ago
#97

Summarizing a new plan to help this task move on:

  • Update the class selector pattern to match the _current_ WordPress CSS Coding Standards, which only allows lowercase letters, numbers, and single hyphens.
  • As such, there won't be major updates to the CSS Coding Standards. โ€‹Only very minor ones.
  • Remove from this PR all the changed css/scss files.
  • Instead, merge โ€‹the series of PRs that already fix the fixable pending violations. They contain also manual fixes. The starting baseline will be much cleaner.
  • Note that those PRs contain stylelint-disable* comments. The comments will be actually used with the last commit that merges this PR.
  • Once all the PRs are merged, regenerate the suppressions file on this PR.
  • Make sure the suppressions file only contains suppressions for the following rules:
    • selector-class-pattern
    • selector-id-pattern
    • selector-no-qualifying-type
  • Merge this PR.

At that point, we will have a 'snapshot' of the state of the CSS Coding Standards across the codebase. With this data available, a discussion on how to address the pending issues should start based on actual data. A post published on Make is required for this public discussion.

The most challenging issue will be how to address the selector-class/id-pattern naming convention. The current violations (hundreds) can't be fixed because of backward compatibility. The selector-no-qualifying-type issue will need a decision as well.

I believe that for the greater good of this project this is the best path forward. A public discussion on the future CSS coding standard will allow to establish the best solution for the CSS in Core and its future maintenance.

#98 @afercia
6 weeks ago

After โ€‹the latest changes of the Core CSS files, the โ€‹PR 12934 build passes.

The Stylelint suppressions list has been updated to only contain suppressions across 32 files for the following rules:

Rule Violations count
selector-class-pattern456
selector-id-pattern165
selector-no-qualifying-type1883
Total2504

I believe this is the best configuration that can be implemented at this moment.

Any change to โ€‹the current CSS Coding Standards to address the 3 rules above should be discussed separately, accompanied by a proposal on the Make blog.

โ€‹A separate PR on the WP coding standards docs repository reflects the very minor changes (e.g. number of empty lines allowed) required to align the CSS Coding Standards with the Stylelint configuration. Pending approval.

โ€‹@afercia commented on โ€‹PR #12934:


5 weeks ago
#99

I pushed some adjustments. Pending issues from latest CR:

1
How to update stylelint-suppressions.json and who is allowed to update it, what are the policies about it.

In the meantime, I added a simple npm script lint:css:update-suppressions that does the job. Same script name of the one in Gutenberg.
However, I'd be in favor of automating the regeneration _only_ if it fails when the counts are increased.
I really don't want contributors to start increasing the amount of suppressions.

2

Fixing a violation doesn't lower the stored count, so the baseline never tightens.

Somewhat related to the first point. Any local script or CI step should only allow _decreasing_ the counts.
If really necessary, stylelint-disable* comments can be added in the source, which leverages clarity and owneership for the disable reason.

3

test-build-processes.yml ignores tools/**, so a change to anything under tools/stylelint/ alone won't run CSS lint in CI. Adding tools/stylelint/ to the paths list would cover it.

I really can't provide a direction here. Why one would ever want to change tools/stylelint/lint-css.js and then not run / adjust the script and config?

โ€‹@lucatume commented on โ€‹PR #12934:


5 weeks ago
#100

I pushed some adjustments. Pending issues from latest CR:

1 How to update stylelint-suppressions.json and who is allowed to update it, what are the policies about it.

In the meantime, I added a simple npm script lint:css:update-suppressions that does the job. Same script name of the one in Gutenberg. However, I'd be in favor of automating the regeneration _only_ if it fails when the counts are increased. I really don't want contributors to start increasing the amount of suppressions.

2

Fixing a violation doesn't lower the stored count, so the baseline never tightens.

Somewhat related to the first point. Any local script or CI step should only allow _decreasing_ the counts. If really necessary, stylelint-disable* comments can be added in the source, which leverages clarity and owneership for the disable reason.

Automating sounds like a good idea. Did you look into this to have an idea of how much work that would require? If it's a small amount of work, it could be included in this PR, else I think it should be a follow-up one.

3

test-build-processes.yml ignores tools/**, so a change to anything under tools/stylelint/ alone won't run CSS lint in CI. Adding tools/stylelint/ to the paths list would cover it.

I really can't provide a direction here. Why one would ever want to change tools/stylelint/lint-css.js and then not run / adjust the script and config?

The idea is to add tools/stylelint/ to the list of paths that will trigger CSS lint in CI to make sure that a PR changing only a file in that directory will run CSS lint in CI. Currently it would be skipped.

โ€‹@afercia commented on โ€‹PR #12934:


5 weeks ago
#101

Automating sounds like a good idea. Did you look into this to have an idea of how much work that would require? If it's a small amount of work, it could be included in this PR, else I think it should be a follow-up one.

With AI assistance, 30 minutes ๐Ÿ˜† And one day to re-check everything. Proof o fconcept available at โ€‹https://github.com/WordPress/wordpress-develop/pull/14010

However, Auto-regenereating the suppressions file on CI would require the workflow to have write access, which could be an issue. Also, not sure it would work for fork PRs.

In any case, contributors could always commit a change to the suppressions file directly. To make auto-regeneration meaningful, repository settings should protect the target branch; I'm not an expert but some rules or CODEOWNERS should require approval for changes to the workflow and script.
That means: require approval for changes to the workflow and the checker script. I can't make this decision alone and I guess it would worth some discussion.

For now, I'd just like to close a 12-years old ticket.

โ€‹@afercia commented on โ€‹PR #12934:


4 weeks ago
#102

Note to myself and for history: at the moment of writing this, the CSS selector with the highest specificity in the codebase is โ€‹in the admin-bar.css file (duplicated in colors.scss) with a specificity of 5, 2, 1. Way too high.
For future consideration of the Stylelint rule selector-max-specificity.

โ€‹@afercia commented on โ€‹PR #12934:


4 weeks ago
#103

@mikeybinns thank you for your feedback, much appreciated.

What I would really like to see is Core and Gutenberg using the same configuration or, at least, the same _base_ configuration with _minimal_ adjustments for the specific needs of the two projects. I believe that, sooner or later, Core and Gutenberg should converge towards a unique, shared, ruleset. Any step in that direction would be a progress.

I was a little surprised to learn that Gutenberg uses more than one configuration and โ€‹different packages use different rulesets. While I understand the historical reasons behind that, I'd argue the current implementation in Gutenberg isn't ideal. I would love to see _one_ config that can be just imported and used in Core but when I asked for it, โ€‹the Gutenberg team seemed a little unresponsive to the idea.

If you can manage to get the Gutenberg implementation to a better state and reduce the number of configurations (ideally have just one), that would be great and I'd be glad to use it in Core. It can also be considered for future iterations, it doesn't necessarily need to happen now.

For the Prettier part, I'll look into it. That could explain why I had to override some rules in a very specific order. So far, thatโ€™s something I had attributed to the chaos of the various imports / chained extends in Gutenberg.

The main goal is closing a 12 years old ticket though. So that also this latest point could be considered for a future iteration.

โ€‹@mikeybinns commented on โ€‹PR #12934:


4 weeks ago
#104

@afercia Okay this sounds like a good compromise, as long as we don't end up with a catch 22 where we can't change the gutenberg config later because it now matches what is in Core. If that's a possibility, then we should aim for Core to be correct, then align Gutenberg to Core.

I did note one thing you mentioned in the linked thread

But then, any change to the rules inherited by scss-stylistic or the rules within scss-stylistic itself would impact the configuration used in Core.

Yes, this is the case and should be expected with the way the current config is set up. Currently the configs used in @wordpress/stylelint-config (all of them, including non-stylistic ones) extend from existing Stylelint recommended configs. Stylelint can choose to add/remove or change these rules (as breaking changes) when they want, and so expecting the rules to be exactly the same will not work for this kind of config.

With that in mind, there's two paths forward for the config:

  1. IMO the recommended way, expect changes on an ongoing basis and plan for that. For the stylelint v17 update, it introduced new and changed rules and we passed these changes on in the package as our own breaking change when updating Stylelint. We had to implement fixes across Gutenberg for these new rules, but it was a minimal task compared to other bits of work.
  1. Create a fixed WP config, don't extend other peoples managed configs, and instead create a config only extending rules from external sources. This would not be immune to changes as rules imported from elsewhere may change and require changes, and this would put all the legwork of adding new, usually helpful, rules to the config onto WP maintainers. This is a much more rigid config but would require much more maintenance.

I shall aim to create in the next few days a potential tracking issue for aligning stylelint configs into one config, and also removing conflicting prettier rules from the config, however I suspect this may take some time to implement so I would not wait on it.

โ€‹@afercia commented on โ€‹PR #12934:


4 weeks ago
#105

Re: Prettier: to my understanding, it is not used in Core. There is nothing that runs prettier for css / scss.
It _would_ only be used in VSCode or other IDEs and only if they are properly configured via extensions and settings as by default VSCode doesn't use prettier.

โ€‹@afercia commented on โ€‹PR #12934:


4 weeks ago
#106

  1. Create a fixed WP config, don't extend other peoples managed configs

Yes, at some point I did consider to get rid of the GB imports / extends and craft a separated config for Core only. As you pointed out, that would add significant maintenance cost though. I'd rather go with option 1.

โ€‹@mikeybinns commented on โ€‹PR #12934:


4 weeks ago
#107

Prettier: to my understanding, it is not used in Core.

Ah yeah, I saw the prettier config in the root along with the prettier dep and assumed, but you may be right.

โ€‹@afercia commented on โ€‹PR #12934:


4 weeks ago
#108

Yep, I think โ€‹it was added only for 'editor integrations', whatever that means.

Note: See TracTickets for help on using tickets.