Stylelint: Relax at-rule-empty-line-before for SCSS
#69606
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work in Progress
Closes: #48992
What?
Stylelint: Relax
at-rule-empty-line-before rulefor SCSS syntaxWhy?
In Gutenberg, the
at-rule-empty-line-beforerule is set to null in the root.stylelintrc.jsconfiguration file, effectively disabling it. However, the@wordpress/stylelint-configpackage enforces a stricter version of this rule, causing numerous linting errors for projects that use the package without Gutenberg's overrides.This discrepancy creates issues when working with SCSS files that use common directives like
@if,@include, and@mediawithout empty lines before them.How?
This PR updates the
at-rule-empty-line-beforerule specifically in the SCSS configuration file (packages/stylelint-config/scss.js), adding more SCSS-specific at-rules to the ignoreAtRules list and improving the except and ignore options. The change is targeted only to the SCSS preset, ensuring it doesn't affect the base configuration or other presets.Testing Instructions
The ideal way to test this is in a fresh project since in Gutenberg itself, the root .stylelintrc.js file already overrides this rule by setting it to null.
Testing within Gutenberg itself wouldn't demonstrate the actual impact of this change because Gutenberg's root configuration already disables the rule completely. Any modifications to the rule in the package would be overshadowed by Gutenberg's override.
By testing in a fresh project that uses the
@wordpress/stylelint-configpackage directly without Gutenberg's overrides, we can properly verify that our changes resolve the issues that other developers would experience.In a fresh project:
@wordpress/stylelint-config.stylelintrc.jsfile with the below configurations.This change ensures that the
@wordpress/stylelint-configpackage provides a more SCSS-friendly configuration by default, aligning better with how Gutenberg itself handles these rules.Screenshots or screencast
Before:
Screen.Recording.2025-03-18.at.3.14.23.PM.mov
After
Screen.Recording.2025-03-18.at.3.15.04.PM.mov