Skip to main content
interlace
Plugin: import-nextRules

max-dependencies

Enforce the maximum number of dependencies a module can have

💼 This rule is enabled in the following configs: recommended, typescript.

Rule Details

A module that depends on too many external packages is doing too much. The rule counts the distinct external packages a file loads or re-exports (import, side-effect import, export … from, export * from, require(), import() and TypeScript's import x = require()) and reports the file when the count exceeds max (default 10). Packages are counted by name: lodash and lodash/get are one package, as are @scope/pkg and @scope/pkg/x.

Not counted: relative and absolute paths, # subpath imports (the package's own files), Node.js builtins in any spelling (Node's own list, subpaths included, or the node: scheme), specifiers listed in ignoreImports (exact match), and - with ignoreTypeImports (default true) - import type / export type. Files matching an ignoreFiles pattern (a substring, or * wildcards) are skipped.

❌ Incorrect

// { max: 2 }
import a from 'pkg-a';
import b from 'pkg-b';
export * from 'pkg-c';

✅ Correct

// { max: 2 }
import a from 'pkg-a';
import get from 'pkg-a/get';
import b from 'pkg-b';
import fs from 'node:fs';
import helper from './helper';

Options

[
  {
    "type": "object",
    "properties": {
      "max": {
        "type": "number",
        "minimum": 1,
        "default": 10,
        "description": "Maximum number of dependencies allowed."
      },
      "ignoreTypeImports": {
        "type": "boolean",
        "default": true,
        "description": "Ignore type-only imports."
      },
      "ignoreImports": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Import sources to ignore."
      },
      "ignoreFiles": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "File patterns to ignore."
      }
    },
    "additionalProperties": false
  }
]

Implementation

OWASP Foundation

  • Category: A00:2021 - General Security

Use this rule

npm install -D oxlint-plugin-import-next
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-import-next"],  "rules": {    "import-next/max-dependencies": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-import-next'],    rules: {      'import-next/max-dependencies': 'error',    },  },});

oxlint-plugin-import-next re-exports eslint-plugin-import-next/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.