Skip to content

feat: respect suppressions during autofix#146

Open
sethamus wants to merge 3 commits intoeslint:mainfrom
sethamus:2026-respect-suppressions-during-autofix
Open

feat: respect suppressions during autofix#146
sethamus wants to merge 3 commits intoeslint:mainfrom
sethamus:2026-respect-suppressions-during-autofix

Conversation

@sethamus
Copy link
Copy Markdown

Summary

This RFC proposes that ESLint should stop applying autofixes for a rule in any file where that rule is suppressed via the suppressions file.

Related Issues

eslint/eslint#20062

Comment thread designs/2026-respect-suppressions-during-autofix/README.md
@jfmengels
Copy link
Copy Markdown

In elm-review we don't apply automatic fixes for a rule when a file contains suppressions for that rule. I therefore wholeheartedly agree with this proposal. It works very well for us and I've never heard a complaint of this behavior (though we do have CLI options to ignore suppressions, I haven't checked if ESLint has similar flags).


The implementation would likely touch the following files:

- `lib/cli.js`: for CLI runs that use suppressions, resolve the active suppressions file before linting and make that suppressions context available to the `ESLint` instance used for fix generation.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could clarify this point? I'm having a hard time figuring out what a "suppressions context" will include that isn't already available to the ESLint instance.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 9317351.


- `lib/cli.js`: for CLI runs that use suppressions, resolve the active suppressions file before linting and make that suppressions context available to the `ESLint` instance used for fix generation.
- `lib/eslint/eslint.js`: initialize `SuppressionsService` when suppressions are needed for fix filtering as well as reporting, and load suppressions early enough in `lintFiles()` and `lintText()` for fix-producing runs.
- `lib/eslint/eslint-helpers.js`: compose the existing fixer created in `lintFile()` and `verifyText()` with a suppressions-aware predicate. For the current file, if `message.ruleId` appears in that file's suppressions entry, return `false` so the fix is skipped.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that a fixer is only created in lintFile(). verifyText() receives it as a parameter.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 9317351.


## Open Questions

Should ESLint provide any user-facing indication that fixes were skipped because the corresponding file-and-rule pairs are suppressed?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying that fixes were skipped because of suppressions doesn't imply they would have been applied otherwise, so the information may be less interesting to users than it sounds at first.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes for suppressed lint problems are already available to custom formatters and API consumers in LintResult#suppressedMessages. I don't think there should be an additional indication provided by ESLint CLI. ESLint API, or built-in formatters, because the lint problems they are fixing are effectively ignored.

stevezhu added a commit to stevezhu/letuscook that referenced this pull request Apr 7, 2026
Copy link
Copy Markdown
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together. Generally I'm in favor of the behavior described in this RFC. I left a note about the technical implementation as I'm not quite following what you're envisioning.

Comment on lines +103 to +104
- `lib/cli.js`: for CLI runs with `--fix` or `--fix-dry-run`, resolve the active suppressions file before linting, load its current contents, and pass that suppressions snapshot into the `ESLint` instance used for fix generation. This makes autofix depend on the suppressions file contents loaded before linting begins.
- `lib/shared/translate-cli-options.js`: pass that internal suppressions snapshot through CLI option translation so it reaches the `ESLint` instance.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what the "suppressions snapshot" is?

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

Labels

feature Initial Commenting This RFC is in the initial feedback stage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants