Skip to main content

avoid-long-functions

added in: 1.2.0
⚙️
Pro+

Warns when a function or method length (number of lines) exceeds the configured maximum.

Long blocks of code are difficult to reuse and understand because they are usually responsible for more than one thing. Separating those to several short ones with proper names helps you reuse your code and understand it better without reading the whole function body.

⚙️ Config

Set max-length (default is 50) to configure the line length number after which the rule should trigger.

Set ignored-names (default is build) to ignore specific function / method names.

analysis_options.yaml
dart_code_metrics:
rules:
- avoid-long-functions:
max-length: 50
ignored-names:
- some
- name
- build

Example

❌ Bad:

// LINT: Avoid long functions. This function has 60 lines of code.
void someLongFunction(...) {
...
...
// more than 50 lines
}

✅ Good:

void someFunction() {
firstMovedOutFunction();
secondMovedOutFunction();
...
}

void firstMovedOutFunction() {
...
}

void secondMovedOutFunction() {
...
}