Skip to content

linter: import/max-dependencies rule counts individual import specifiers instead of unique module sources #19120

@connorshea

Description

@connorshea

What version of Oxlint are you using?

1.43.0

What command did you run?

oxlint

What does your .oxlintrc.json config file look like?

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": [
    "import"
  ],
  "categories": {
    "correctness": "off"
  },
  "rules": {
    "import/max-dependencies": ["error", { "max": 2 }]
  }
}

What happened?

The import/max-dependencies rule currently counts each entry in import_entries rather than counting unique module sources. This means import { x, y, z } from './foo' is counted as 3 dependencies instead of 1.

This differs from the behavior of the original rule, which counts unique module sources.

With config { "max": 2 }, the following should be valid (2 unique dependencies: ./foo and ./bar):

import { w } from './foo';
import { x, y, z } from './bar';

But oxlint counts it as a violation:

eslint-plugin-import(max-dependencies): File has too many dependencies (4). Maximum allowed is 2.

Per the docs of the original rule, multiple named imports from the same module should count as a single dependency. The example above has 2 dependencies, not 4.

I discovered this problem while working on #19119

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions