avoid-complex-arithmetic-expressions
Warns when an arithmetic expression has too many terms.
⚙️ Config
Set max-number
(default is 6
) to configure the maximum number of terms.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-complex-arithmetic-expressions:
max-number: 3
Example
❌ Bad:
int calc(int a, int b) {
// LINT: Avoid complex arithmetic expressions. Try splitting it into methods.
return a + a + a + b + b + b + b;
}
✅ Good:
int calc(int a, int b) {
return calcA(a) + calcB(b);
}
int calcA(int a) => a + a + a;
int calcB(int b) => b + b + b + b;