avoid-complex-arithmetic-expressions

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

example.dartdart
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);
Expression has 4 arithmetic terms (max 3). Extract intermediate values.
1int compute(int a, int b, int c, int d) => a + b * (c - d);
Expression has 4 arithmetic terms (max 3). Extract intermediate values.
1int compute(int a, int b, int c, int d) => a + b * (c - d);
2int calls(int a) => a + helper(a * a * a * a);
Expression has 4 arithmetic terms (max 3). Extract intermediate values.
3int helper(int x) => x;
4double doubles(double a, double b, double c, double d) => a / b + c * d;
Expression has 4 arithmetic terms (max 3). Extract intermediate values.
4double doubles(double a, double b, double c, double d) => a / b + c * d;
5num numbers(num a, num b, num c, num d) => a + b * (c % d);

Valid

example.dartdart
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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "complexity": {
        "avoid-complex-arithmetic-expressions": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/complexity/avoid-complex-arithmetic-expressions: <reason>