avoid-complex-arithmetic-expressions
- Group
- Complexity
- Path
lint/complexity/avoid-complex-arithmetic-expressions- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 34 of 512
Reports arithmetic expressions containing too many terms.
max-terms (integer, default: 6) limits connected +, -, *, /, ~/, and %
operands. Parentheses do not reset the count; calls are opaque operands.
Invalid
int compute(int a, int b, int c, int d) => a + b * (c - d);
int calls(int a) => a + helper(a * a * a * a);
int helper(int x) => x;
double doubles(double a, double b, double c, double d) => a / b + c * d;
num numbers(num a, num b, num c, num d) => a + b * (c % d);int compute(int a, int b, int c, int d) => a + b * (c - d);int compute(int a, int b, int c, int d) => a + b * (c - d);int calls(int a) => a + helper(a * a * a * a);int helper(int x) => x;double doubles(double a, double b, double c, double d) => a / b + c * d;double doubles(double a, double b, double c, double d) => a / b + c * d;num numbers(num a, num b, num c, num d) => a + b * (c % d);Valid
int compute(int a, int b, int c) => a + b * c;
int helper(int x) => x;
int calls(int a) => helper(a + a) + helper(a * a);
String concatenate(String a, String b, String c, String d) => a + b + c + d;
String literals() => 'a' + 'b' + 'c' + 'd';
class Vector {
Vector operator +(Vector other) => this;
Vector operator -(Vector other) => this;
Vector operator *(Vector other) => this;
}
Vector overloaded(Vector a, Vector b, Vector c, Vector d) => a + b * (c - d);
dynamic unknown(dynamic a, dynamic b, dynamic c, dynamic d) => a + b + c + d;Configure avoid-complex-arithmetic-expressions
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"complexity": {
"avoid-complex-arithmetic-expressions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/complexity/avoid-complex-arithmetic-expressions: <reason>More complexity rules
- avoid-complex-conditions
Flags boolean expressions with more logical operands than the configured threshold.
- avoid-complex-loop-conditions
Flags loop conditions with more logical operands than the configured threshold.
- avoid-function-literals-in-foreach-calls
avoid_function_literals_in_foreach_callsFlags a function literal passed to an Iterable's
forEach. - avoid-if-with-many-branches
Reports long if/else-if chains; replace them with a switch or extracted helpers.
- avoid-inverted-boolean-expressions
avoid_inverted_boolean_expressionsrecommendedFlags a doubly-negated boolean expression such as
!!x. - avoid-long-records
Reports record values and record types with too many fields.
- avoid-nested-conditional-expressions
avoid-nested-conditional-expressionsFlags a ternary conditional expression nested inside another ternary.
- avoid-nested-if
avoid_nested_ifFlags an
ifstatement whose then-branch contains nestedifstatements.