avoid-long-functions
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.
dart_code_metrics:
...
rules:
...
- avoid-long-functions:
max-length: 80
ignored-names:
- some
- name
Example
❌ Bad:
void someLongFunction(...) { // LINT
...
}
✅ Good:
void someFunction() {
firstMovedOutFunction();
secondMovedOutFunction();
...
}
void firstMovedOutFunction() {
...
}
void secondMovedOutFunction() {
...
}