Skip to main content

prefer-stylelint-fix

Prefer enabling Stylelint's top-level fix option in authored Stylelint config files.

Targeted pattern scopeโ€‹

This rule targets Stylelint config modules such as stylelint.config.ts, stylelint.config.mjs, and .stylelintrc.js.

It focuses on top-level exported config objects, including configs wrapped in defineConfig(...).

What this rule reportsโ€‹

This rule reports Stylelint config objects that omit fix, or configure it with a disabled value.

Why this rule existsโ€‹

If your repository expects Stylelint autofix to be on by default, an explicit top-level fix setting makes that operational choice visible and consistent.

This rule is intentionally opinionated and best suited for repositories that want shared Stylelint config files to declare autofix-on behavior directly.

This rule is intentionally excluded from stylelint2.configs.recommended because it encodes an opinionated operational default rather than a broadly applicable config-hygiene rule.

โŒ Incorrectโ€‹

export default {
rules: {},
};

โœ… Correctโ€‹

export default {
fix: true,
rules: {},
};

Behavior and migration notesโ€‹

  • This rule auto-fixes missing or disabled top-level fix configuration to fix: true.
  • Existing enabled values such as "strict" and "lax" are accepted.
  • Use this rule only when enabling autofix in shared config is an intentional repository policy.

Additional examplesโ€‹

โœ… Correct โ€” execution controls autofixโ€‹

{
"scripts": {
"lint:styles": "eslint \"src/**/*.{css,scss}\""
}
}

ESLint flat config exampleโ€‹

import stylelint2 from "eslint-plugin-stylelint-2";

export default [stylelint2.configs.configuration];

When not to use itโ€‹

Do not use this rule if your team wants autofix to stay an invocation-only decision or needs different fix modes across environments.

Package documentationโ€‹

Stylelint package documentation:

Rule catalog ID: R011

Further readingโ€‹