Skip to content

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

@martonperei

Description

@martonperei

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions