Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disableFix secondary option #5460

Merged
merged 10 commits into from Sep 16, 2021
22 changes: 22 additions & 0 deletions docs/user-guide/configure.md
Expand Up @@ -158,6 +158,28 @@ For example:

The report is considered to be a lint error.

### `disableFix`

You can set the `disableFix` secondary option to disable autofix _on a per rule basis_.

For example:

```json
{
"rules": {
"indentation": [
2,
{
"except": ["value"],
"disableFix": true
}
]
}
}
```

The error in the report will not be automatically fixed, we can decide whether to fix it manually.

kuangrs marked this conversation as resolved.
Show resolved Hide resolved
## Disable Errors

These configurations provide extra validation for `stylelint-disable` comments. This can be helpful for enforcing useful and well-documented disables.
Expand Down
3 changes: 3 additions & 0 deletions lib/lintPostcssResult.js
Expand Up @@ -88,6 +88,8 @@ function lintPostcssResult(stylelintOptions, postcssResult, config) {

// Log the rule's severity in the PostCSS result
const defaultSeverity = config.defaultSeverity || 'error';
// disableFix in secondary option
const disableFix = (secondaryOptions && secondaryOptions.disableFix === true) || false;

postcssResult.stylelint.ruleSeverities[ruleName] =
(secondaryOptions && secondaryOptions.severity) || defaultSeverity;
Expand All @@ -98,6 +100,7 @@ function lintPostcssResult(stylelintOptions, postcssResult, config) {
postcssRoots.map((postcssRoot) =>
ruleFunction(primaryOption, secondaryOptions, {
fix:
!disableFix &&
stylelintOptions.fix &&
// Next two conditionals are temporary measures until #2643 is resolved
isFileFixCompatible &&
Expand Down