close

max-dependencies

Added in v0.9.4

Configuration

rslint.config.ts
import { defineConfig, importPlugin } from '@rslint/core';

export default defineConfig([
  importPlugin.configs.recommended,
  {
    rules: {
      'import/max-dependencies': 'error',
    },
  },
]);

Rule Details

Limit the number of distinct dependencies in a file. Static imports, re-exports, dynamic import() calls, and direct require() calls count when their module path is a string literal. Repeated paths count once, even across these forms. Paths are compared by their string values without resolving them to files.

The rule reports once on the last module path when the limit is exceeded. That path can be a duplicate or an ignored type import. The rule does not provide automatic fixes or suggestions.

With { "max": 2 }, this code is incorrect:

import a from './a';
const b = require('./b');
import c from './c';

This code is correct:

import a from './a';
const anotherA = require('./a');
import { x, y, z } from './foo';

Template literals and computed paths such as require(name) do not count. TypeScript import assignments (import name = require('module')) and import types (type T = import('module').T) do not count either.

Options

max

The maximum number of distinct dependencies. Defaults to 10 when omitted, including when only ignoreTypeImports is configured.

ignoreTypeImports

Set this to true to exclude declarations using import type. The default is false. Inline type specifiers (import { type T } from 'module') and type re-exports still count.

With { "max": 2, "ignoreTypeImports": true }, this code is correct:

import a from './a';
import b from './b';
import type c from './c';

Differences from upstream

With {} or { "ignoreTypeImports": true }, rslint enforces the default limit of 10. eslint-plugin-import 2.32.0 disables the check when an options object does not specify max.

Setting { "max": -1 } for a file containing only export const value = 1; makes eslint-plugin-import stop with an error. rslint reports no problem for that file. Use { "max": 0 } to forbid dependencies.

Original Documentation