-
-
Couldn't load subscription status.
- Fork 82
feat: Consider bulk suppressions when running Lint via the Node.js API #133
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
base: main
Are you sure you want to change the base?
feat: Consider bulk suppressions when running Lint via the Node.js API #133
Conversation
|
Specific code examples for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the RFC! I left some initial questions about the design.
| Currently, the bulk suppression feature introduced in ESLint 9.24.0 is only available via the CLI. | ||
| This leads to inconsistencies when ESLint is used programmatically via its Node.js API, such as in IDE integrations. | ||
|
|
||
| This leads to inconsistencies when ESLint is used programmatically. Violations suppressed using `eslint-suppressions.json` (especially when using a custom location via the CLI) might not be recognized when using the Node.js API, leading to incorrect error reporting in environments like IDEs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppose someone has a task to fix previously suppressed violations. How will they do this, since the violations no longer appear in their IDE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation for using bulk suppression may be “I want to ignore existing errors and give priority to activating new errors”.
With that assumption, existing errors that should be ignored should not be shown in the IDE either.
To work on reducing the number of ignored errors, we can start by check the suppressed errors in eslint-suppressions.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdjermanovic I think this is the same use case as when running on the CLI. Because the CLI automatically picks up the eslint-suppressions.json file, it's necessary to edit, move, or delete the file if your task is to clean up suppressed violations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that suppressed lints show up in the IDE is a feature not a bug for me. It encourages developers to fix the issues when they're working in those files and not copy the bad patterns. However, I would like to be able to see the suppressed violations in a different color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wagenet
For example, do you mean displaying Diagnostics at the Suggestion level for suppressed warnings?
This would probably be possible by returning information about suppressed violations from the API and writing corresponding processing on the IDE extension side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what IDE integrations generally allow, but for me the ideal situation is to have the IDE integrations show both suppressed and not-suppressed violations in the IDE, but to distinguish between the two, most likely by color. I'm somewhat agnostic as to how this is achieved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wagenet
If that's the case, then we're probably thinking the same thing. Sorry for the unclear explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 +1 to everything @wagenet said - We've been discussing switching to eslint bulk suppressions, and we like that errors show in the IDE. But perhaps a different appearance in IDE to distinguish them would be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some context: the ESLint team does not maintain any ESLint IDE integrations. These are maintained by their respective IDE teams. The only thing we can control is whether or not the suppressions information is available to the IDEs and it's up to the IDEs to determine how to use that information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdjermanovic what do you think of #133 (comment)?
|
@sushichan044 please take a moment to sign the CLA (see first comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks like a good plan to me. Nice work.
| Currently, the bulk suppression feature introduced in ESLint 9.24.0 is only available via the CLI. | ||
| This leads to inconsistencies when ESLint is used programmatically via its Node.js API, such as in IDE integrations. | ||
|
|
||
| This leads to inconsistencies when ESLint is used programmatically. Violations suppressed using `eslint-suppressions.json` (especially when using a custom location via the CLI) might not be recognized when using the Node.js API, leading to incorrect error reporting in environments like IDEs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdjermanovic I think this is the same use case as when running on the CLI. Because the CLI automatically picks up the eslint-suppressions.json file, it's necessary to edit, move, or delete the file if your task is to clean up suppressed violations.
Co-authored-by: Nicholas C. Zakas <[email protected]>
| - The constructor will resolve the final absolute path to the suppression file (using `suppressionsLocation` or the default) and pass it to the `SuppressionsService` constructor. | ||
|
|
||
| 3. Applying Suppressions | ||
| - Within the `lintFiles()` and `lintText()` methods of both classes, *after* the initial linting results are obtained, the `applySuppressions` method of the instantiated `SuppressionsService` will be called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will need to maintain the existing order of processing. In this case, applySuppressions will be invoked before the call to outputFixes, suppress and prune. This will lead to different behavior from the existing implementation. For example, if the CLI is invoked with --prune-suppressions you will still get errors about unmatched suppressions, since the pruning will happen after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am currently organizing the issues related to the order of processing. Please give me a little time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sushichan044 I don't think changing the CLI is the right choice if it leads to a broken experience as @softius described.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good plan to me. 👍
|
|
||
| 1. New Constructor Option (`suppressionsLocation`) | ||
| - Both `ESLintOptions` and `LegacyESLintOptions` will accept a new optional property: `suppressionsLocation`. | ||
| - `suppressionsLocation: string | undefined`: Specifies the path to the suppressions file (`eslint-suppressions.json`). This path can be absolute or relative to the `cwd`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to pass the whole suppressions config and move the whole logic into the classes, similar to the cache? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on that suggestion? I'm not clear on what it is you're imagining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a suggestion in regards to my concern described here at #133 (comment)
Since we are discussing to move the suppression check from CLI to ESLint classes, we would need to bring over the entire code block to maintain the correct order of execution. In that case we would need to pass over all the suppressions args and let the ESLint classes handle the logic including updating the files (similar to cache).
Having said that, I realised that even with this approach we will be doing the suppressions logic before the automated fixes, which means that once again we are changing the execution order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to take another look to see if we can effectively keep the current behavior while allowing API consumers to filter the results through suppressions.
To that end, it seems like the only reasonable approach would be to add an option to the ESLint constructor to indicate whether it should or shouldn't apply suppressions to results when lintText() or lintFiles() is called? That way, the CLI can tell ESLint not to apply suppressions and maintain its current behavior, and any API consumers who want to apply suppressions can do so. (Question remains: what is the default? Should ESLint apply suppressions automatically or not?)
|
@nzakas |
|
@sushichan044 no problem, thanks for letting us know. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@spence-s that's out of scope for this RFC. Please open a separate issue to discuss. |
|
@sushichan044 it looks like the remaining work here it to ensure the functionality works the same as with the CLI. Are you still working on that point? |
| 3. Applying Suppressions | ||
| - Within the `lintFiles()` and `lintText()` methods of both classes, *after* the initial linting results are obtained, the `applySuppressions` method of the instantiated `SuppressionsService` will be called. | ||
| - This method takes the raw linting results and the loaded suppressions (from the resolved file path) and returns the results with suppressions applied, along with any unused suppressions. | ||
| - The final, suppression-applied results will be returned to the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to have the ability to see all violations with a suppressed property on each of them so I can distinguish instead of just having the suppressions skipped.
|
The fact that suppressions are only applied to the CLI is actually a really big feature for me. I want to see the violations in the IDE, but not have them cause my CI to fail. The only change I'd like is the ability for my IDE to show suppressed violations in a different color. Hiding suppressed violations in the IDE would be a regression for me. |
|
I would definitely agree with @wagenet on this. Having suppressions show in IDE is a big improvement IMO over disables. This allows lints to be started, suppressed and team members to know this is a work item. Having IDEs and other tools being able to distinguish between suppressed and not though is also something important. |
|
About displaying diagnostic information for suppressed violations: |
|
@sushichan044 just checking in -- are you still planning on working on this? |
|
Sorry, my academic research has kept me very busy and my response is delayed. What I’m currently thinking is to have Anyway, I’ll make time to reconsider this by the coming weekend. |
|
To match CLI behavior, we’d need to extend |
|
As for changes that impose less burden on the ecosystem, I'm also considering the following ideas. In note: |
|
Thanks for the update, and no worries -- we don't have any time constraints here. :)
We don't currently distinguish between the two types of suppressions, so I'm not sure I understand why the distinction is necessary here. Can you explain your thinking a bit more? We do want to be careful about maintaining existing public interfaces like |
Summary
This RFC proposes integrating bulk suppressions support into the Node.js API via the
ESLintandLegacyESLintclasses, specifically focusing on considering existing bulk suppressions when linting files or text through the API. This change ensures that suppression files (eslint-suppressions.json) created via CLI commands are automatically respected when using the programmatic API, maintaining consistency between CLI and API behavior.The scope is limited to applying existing suppressions during linting and does not include suppression file manipulation features (such as
--suppress-all,--suppress-rule, or--prune-suppressions), which remain CLI-exclusive functionalities.Related Issues