Skip to content

Stylelint: extract the shared rule set into a reusable "project" preset - #81369

Draft
i-am-chitti wants to merge 2 commits into
WordPress:trunkfrom
i-am-chitti:feature/81349-extract-stylelint
Draft

i-am-chitti wants to merge 2 commits into
WordPress:trunkfrom
i-am-chitti:feature/81349-extract-stylelint

Conversation

@i-am-chitti

Copy link
Copy Markdown
Contributor

What?

Closes #81349

Adds a project preset to @wordpress/stylelint-config holding the Stylelint rules Gutenberg and WordPress Core share, and switches tools/stylelint/config.js over to it so the set has a single source.

Why?

wordpress-develop#12934 proposes adding Stylelint to Core, and its .stylelintrc.js is currently a copy of Gutenberg's config. The overlap is exact: Core's file is tools/stylelint/config.js minus declaration-property-value-disallowed-list, plugin-wpds/no-token-fallback-values and the overrides section — the other ~22 rules and both report*Disables options are identical. Keeping two copies in sync by hand is the maintenance problem the issue describes.

How?

The shared set becomes a fourth preset in the already-published @wordpress/stylelint-config, alongside scss / stylistic / scss-stylistic, rather than a new package. It extends scss-stylistic and carries the shared rules plus reportNeedlessDisables and reportDescriptionlessDisables.

tools/stylelint/config.js drops from 173 to 122 lines and keeps only Gutenberg's own configuration:

extends: '@wordpress/stylelint-config/project',
plugins: [ 'stylelint-plugin-logical-css' ],
rules: { /* wp-components-color / font-weight / cursor only */ },
overrides: [ /* CSS modules + routes/ */ ],

Core's config then becomes extends: '@wordpress/stylelint-config/project' plus its ignorePath.

Two incidental cleanups fall out: the file was re-registering the no-token-fallback-values plugin and re-enabling its rule, both already no-ops given the base config, and tools/stylelint no longer needs its @wordpress/theme dependency.

Note for reviewers: plugin-wpds/no-token-fallback-values is excluded from the extracted set per the issue, but that does not actually keep it out of Core — it is enabled in the base index.js that Core already extends, along with no-unknown-ds-tokens and no-setting-wpds-custom-properties. They are inert there (Core has no --wpds-* tokens), so this PR leaves the base preset alone; excluding WPDS rules from Core entirely would be a separate, more disruptive change.

Testing Instructions

This is a no-op refactor for Gutenberg — the goal is proving the resolved config did not change.

  1. npm run lint:css
  2. npm run test:unit packages/stylelint-config
  3. Optional, to confirm equivalence directly — compare npx stylelint --print-config <file> on this branch against trunk for each file shape in the repo:
    • packages/components/src/button/style.scss (plain SCSS)
    • packages/components/src/angle-picker-control/style.module.scss (CSS module, SCSS)
    • widgets/hello-world/style.module.css (CSS module, CSS)
    • routes/template-list/style.scss (routes/)

Output is semantically identical for all four; only key ordering shifts, so sort keys before diffing.

Testing Instructions for Keyboard

N/A — build tooling only, no UI changes.

Use of AI

Claude Code Opus 5
Purpose - compare configs, extract shared rules, verify equivalence, write tests

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract the Stylelint set of rules so that it can be reused in Core

1 participant