Skip to content

max_imports

v1.0.0WarningConfigurableCode Quality

This rule flags a file that imports more libraries than the configured budget.

The import list is the cheapest available measure of how much a file depends on. A file reaching for twenty libraries is coupled to twenty things that can change under it, and it is usually one that has taken on several jobs.

export directives are not counted by default: a barrel file is exports by definition, and counting them would report every barrel in the project.

This rule is in the pedantic preset: a budget is a house style, and the right number differs per codebase.

// One file importing the router, the theme, four repositories,
// three notifiers, and the whole widget catalogue.
// Split along the seams the imports already reveal: the widget file
// imports widgets, the repository file imports the client.

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
max_imports:
enabled: true
analysis_options.yaml
many_lints:
rules:
max_imports:
max_imports: 15
count_exports: false
Option Type Default Description
max_imports int 15 How many libraries a file may import
count_exports bool false Whether export directives count toward the budget

To disable this rule:

many_lints.yaml
rules:
max_imports: false

To keep the rule on but skip certain paths, use per-rule exclude.