Skip to content

avoid_long_files

v1.0.0WarningConfigurableCode Quality

This rule flags a file longer than the configured line budget.

A long file is where a module stops having a single subject: the name at the top no longer describes everything below it, and finding the right place to add something becomes a scroll rather than a decision.

Blank lines and comments are not counted by default — a file is not hard to navigate because it is well documented. Lines are counted from the token stream, so a // inside a string literal is never mistaken for a comment.

Generated files are the obvious exception, and per-rule exclude handles them:

rules:
avoid_long_files:
exclude: ["**/*.g.dart", "**/*.freezed.dart"]

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

// user_page.dart — 800 lines holding the page, its three dialogs,
// a formatter, and the API client it calls.
// user_page.dart — the page
// user_page_dialogs.dart — its dialogs
// user_formatting.dart — the formatter
// user_api.dart — the client

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

many_lints.yaml
rules:
avoid_long_files:
enabled: true
analysis_options.yaml
many_lints:
rules:
avoid_long_files:
max_lines: 300
count_comments: false
Option Type Default Description
max_lines int 300 How many code lines a file may hold
count_comments bool false Whether blank lines and comments count toward the budget

To disable this rule:

many_lints.yaml
rules:
avoid_long_files: false

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