max_imports
v1.0.0WarningConfigurableCode Quality
many_lints.yaml
analysis_options.yaml many_lints.yaml
many_lints.yaml
This rule flags a file that imports more libraries than the configured budget.
Why use this rule
Section titled “Why use this rule”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.Enabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: max_imports: enabled: trueOptions
Section titled “Options”many_lints: rules: max_imports: max_imports: 15 count_exports: falserules: 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 |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: max_imports: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_long_files— Keep a file within a line budget.avoid_long_parameter_list— Keep parameter lists within a budget.avoid_too_many_methods— Keep a class within a method budget.max_statements— Keep a function within a statement budget.