Skip to content

Conversation

im3dabasia
Copy link
Contributor

@im3dabasia im3dabasia commented Mar 18, 2025

Work in Progress

Closes: #48992

What?

Stylelint: Relax at-rule-empty-line-before rule for SCSS syntax

Why?

In Gutenberg, the at-rule-empty-line-before rule is set to null in the root .stylelintrc.js configuration file, effectively disabling it. However, the @wordpress/stylelint-config package 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 @media without empty lines before them.

How?

This PR updates the at-rule-empty-line-before rule 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-config package directly without Gutenberg's overrides, we can properly verify that our changes resolve the issues that other developers would experience.

In a fresh project:

  1. Create a new project and install @wordpress/stylelint-config
  2. Set up a basic .stylelintrc.js file with the below configurations.
module.exports = { extends: ['@wordpress/stylelint-config/scss-stylistic'] };
  1. Create an SCSS file with nested at-rules (like the example above)
  2. Observe the linting errors
  3. Update your config to include the relaxed rule settings
/** @type {import('stylelint').Config} */
module.exports = {
  extends: '@wordpress/stylelint-config/scss-stylistic',
  rules: {
    'at-rule-empty-line-before': [
      'always',
      {
        except: ['blockless-after-blockless', 'after-same-name'],
        ignore: ['after-comment', 'first-nested'],
        ignoreAtRules: [
          'else', 'if', 'include', 'mixin', 'extend', 'media',
          'warn', 'for', 'each', 'content',
        ],
      },
    ],
  },
};
  1. Verify that the errors are resolved

This change ensures that the @wordpress/stylelint-config package 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

@im3dabasia im3dabasia marked this pull request as ready for review March 18, 2025 10:15
@im3dabasia im3dabasia requested a review from ntwb as a code owner March 18, 2025 10:15
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: ahegyes <ahegyes@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Tool] stylelint config /packages/stylelint-config labels Mar 19, 2025
@im3dabasia im3dabasia force-pushed the try/relax-stylelint-rules branch from bab0b6b to 40e937e Compare April 15, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] stylelint config /packages/stylelint-config [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SCSS linting errors for @if and other "@"-prefixed SCSS commands like @warn
2 participants