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

[eslint-patch] Improve performance of eslint-bulk-suppressions #5055

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dmichon-msft
Copy link
Contributor

@dmichon-msft dmichon-msft commented Dec 19, 2024

Summary

Fixes #5054
Fixes #5006

Fixes an issue with incorrect computation of scope ids that were resulting in overly broad suppressions.

Details

- Simplifies the patching logic to load ESLint's linter.js into memory and only override Linter.prototype.verify, without generating any temporary files.
- Uses AST traversal to find the relevant node instead of extracting it from the reporter, due to limitations of data visibility. However, the new version only processes reported problems that aren't already suppressed via inline comments.

  • Adds a new environment variable ESLINT_BULK_ESLINTRC_FOLDER_PATH that, if specified, short-circuits the patch searching for .eslintrc.js from every single file.
  • Updates @rushstack/heft-eslint-plugin to set ESLINT_BULK_ESLINTRC_FOLDER_PATH to the parent of its detected ESLint config.
  • Adds a tag eslint-tests to the ESLint test projects to make them easier to run
  • Updates the ESLint bulk suppressions test project to run the suppression tester as well
  • Ensures that issues suppressed by bulk suppressions show up in the getSuppressedMessages() output of the linter, for use by auditing.

Edited:

  • Updates the logic for identifying bulk suppressions to only attach the AST node on the initial walk and defer identification of bulk suppressions until all problems have been collated and inline suppressions have been performed
  • Adds a new flag "disableLintConfigSearch" to the options for heft-lint-plugin that, if configured, prevents the linter from searching for config files based on the location of linted files and tells it to just use the config in the project root.

How it was tested

Ran in the ESLint test projects.
Linked this version of the patch into a repository that has tons of bulk suppressions and ran it there.
Profiled this version vs. the old to ensure no regression.

Impacted documentation

Behavior should be the same, other than ensuring that the suppressions from this feature show up in the output of getSuppressedMessages().

@dmichon-msft
Copy link
Contributor Author

dmichon-msft commented Dec 25, 2024

It looks like it should be possible to get a peek at the ast node by wrapping the create function of all loaded rules. This is a bit silly, but it beats having to produce an alternate version of the linter file.

On closer inspection, this isn't feasible for legacy function-style rules and would be a pain to maintain.

Ideally we should push for ESLint to natively support an astNode property on the Problem object, have scopeId calculation be built-in, or support some manner of additional hook into the system that gets access to the AST node.

@dmichon-msft dmichon-msft changed the title [eslint-patch] Improve performance and correctness of eslint-bulk-suppressions [eslint-patch] Improve performance of eslint-bulk-suppressions Dec 26, 2024
@octogonz
Copy link
Collaborator

@kevin-y-ang FYI

fix: fixFn
fix: fixFn,
// If requested, disable the scan for .eslintrc files relative to linted files
useEslintrc: !disableLintConfigSearch
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this option. According to the ESLint docs, it seems to completely suppress configuration:

To Address: You should be sure to use a configuration whenever you run ESLint. However, you can still run ESLint without a configuration by passing the --no-eslintrc option on the command line or setting the useEslintrc option to false for CLIEngine.

...but then where does the configuration come from? Is the idea that Heft itself locates .eslintrc.js and then provides its path via overrideConfigFile?

If so, then does Heft actually support multiple other files (probed using useEslintrc)? How would that interact with overrideConfigFile?

Without a test project verifying/illustrating how this would work, it might be better to set useEslintrc=false by default (or hardwire it to always be false). My concern is that quite a lot of people may upgrade Heft without realizing that they're supposed to update their rigs to set disableLintConfigSearch=true, and then they'll permanently be invoking heft-lint-plugin in a nonstandard configuration.

"lint": {
"taskPlugin": {
"options": {
"disableLintConfigSearch": true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why isn't the official rig updated to add this setting? (In a separate comment, I'm suggesting to eliminate this entirely.)

Or at the very least, we need some clear documentation explaining when someone should choose "disableLintConfigSearch": true vs false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs triage
2 participants