prefer_initializing_formals

Group: style

Maturity: stable

Linter v0.1.30

Since info is static, may be stale
recommendedflutter

View all Lint Rules

Using the Linter

DO use initializing formals when possible.

Using initializing formals when possible makes your code more terse.

BAD:

class Point {
  num x, y;
  Point(num x, num y) {
    this.x = x;
    this.y = y;
  }
}

GOOD:

class Point {
  num x, y;
  Point(this.x, this.y);
}

BAD:

class Point {
  num x, y;
  Point({num x, num y}) {
    this.x = x;
    this.y = y;
  }
}

GOOD:

class Point {
  num x, y;
  Point({this.x, this.y});
}

NOTE This rule will not generate a lint for named parameters unless the parameter name and the field name are the same. The reason for this is that resolving such a lint would require either renaming the field or renaming the parameter, and both of those actions would potentially be a breaking change. For example, the following will not generate a lint:

class Point {
  bool isEnabled;
  Point({bool enabled}) {
    this.isEnabled = enabled; // OK
  }
}