Add stylelint CSS linting - #12934
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Nice, given the new |
|
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:
|
9d6e06f to
f14b5fb
Compare
|
The bundled themes The one for
Although there are working forks of the Even after making them work, the linting for both themes reports several errors, mostly because of outdated configuration:
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 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 |
| "lint-fix:scss": "stylelint **/*.scss --fix" | ||
| "build": "run-s build:style build:style-editor build:style-dark-mode build:rtl build:dark-rtl build:print postbuild", | ||
| "postcss": "postcss --use autoprefixer --no-map --replace style.css style-rtl.css assets/css/*.css assets/css/*-rtl.css", | ||
| "stylelint": "wp-scripts lint-style **/*.css --fix --config ../../../../.stylelintrc.js", |
There was a problem hiding this comment.
This path to the config isn't nice. To my understanding, the lint-style script from Gutenberg only auto-detects config in the current firectory while normally Stylelint would walk up to the repo root untile it finds a config.
This can be reviewed later.
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:
grunt precommit:css.For now, it is important to check the following:
npm run lint:cssgrunt lint:cssDon't forget to run
npm installbefore testing.As of Core revision 63157, the Stylelint scan reports the following:
Most of these errors are trivial fixes.
The scan also reports one occurrence of the
orderproperty and one of therow-reversevalue, which confirms the custom rules work as expected.Nest steps: Add a related GitHub Action.
Use of AI Tools
None.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.