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

[import/no-extraneous-dependencies] Doesn't properly clear the dependency cache #2838

Open
martonperei opened this issue Jul 23, 2023 · 1 comment

Comments

@martonperei
Copy link

martonperei commented Jul 23, 2023

The dependencies from package.json are cached for this rule, but it looks like when eslint is running as a daemon, like an IDE (VSCode or IntelliJ IDEA), the cache is not cleared properly, causing errors to keep showing if package.json is modified.
It looks like Program:exit is defined in the wrong place in the rule. I'm not sure what the intended behavior was, but to me it looks like a simple bug, as Program:exit should be returned from create like so:

create(context) {
  [...]
  return {
    ...moduleVisitor((source, node) => {
      reportIfMissing(context, deps, depsOptions, node, source.value);
    }, { commonjs: true }),
    'Program:exit'() {
      depFieldCache.clear();
    },
  }
}

instead, Program:exit is defined on the same level as create, causing it to be ignored.
Though as Program:exit is ran for each file, the cache would be quite useless in this case. Perhaps the file modified time could be checked to trigger a reload, but I'm also not seeing any slowdowns from not caching at all, but that might just be for my use case. (the bulk of the time is spent in reportInMissing ~677ms (because of the typescript resolver) vs ~30ms in getDependencies (uncached))
Can anyone confirm?

@ljharb
Copy link
Member

ljharb commented Jul 23, 2023

Looks like the Program:exit visitor was added in 7f251b2 / #2374, and I agree with you that it should be inside the create, object-assigned onto the moduleVisitor return value - however, as you note, fixing this would cause the cache to be cleared after every file, and probably slow down the lint rule significantly.

eslint isn't designed to run as a daemon, and thus shouldn't be - there's no signalling built into eslint that would enable a long-running cache to clear things efficiently.

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

No branches or pull requests

2 participants