prefer-named-parameters

Group
Style
Path
lint/style/prefer-named-parameters
Default
Off, opt in
Origin
Falcon
Rule
390 of 512

Prefer named parameters when a declaration exceeds max-number (default 1).

Checks top-level functions, constructors, and methods on classes without inheritance. Overrides, operators, setters, closures, function types, main, external/annotated declarations, redirects and super-parameter constructors are excluded because their signatures can be imposed by another declaration.

Invalid

example.dartdart
void configure(int width, int height, String label) {}
class Box {
  Box(int width, int height, String label);
  void resize(int width, int height, bool animate) {}
}
This declaration has more than 2 positional parameters; convert the excess parameters to named parameters.
1void configure(int width, int height, String label) {}
This declaration has more than 2 positional parameters; convert the excess parameters to named parameters.
2class Box {
3 Box(int width, int height, String label);
This declaration has more than 2 positional parameters; convert the excess parameters to named parameters.
3 Box(int width, int height, String label);
4 void resize(int width, int height, bool animate) {}

Valid

example.dartdart
void configure(int width, int height, {required String label}) {}
void optional(int width, [int height = 0]) {}
class Base {
  void resize(int width, int height) {}
}
class Child extends Base {
  @override
  void resize(int width, int height) {}
  void inheritedContext(int a, int b, int c) {}
}
final callback = (int a, int b, int c) {};
typedef Callback = void Function(int a, int b, int c);
void main(List<String> args, Object? message) {}
external int nativeFunction(int a, int b, int c);
@deprecated
void annotated(int a, int b, int c) {}
class Redirect {
  factory Redirect(int a, int b, int c) = Target;
}
class Target implements Redirect {
  @deprecated
  Target(int a, int b, int c);
}
class Parent {
  @deprecated
  Parent(int a, int b, int c);
}
class SuperChild extends Parent {
  SuperChild(super.a, super.b, super.c);
}

Configure prefer-named-parameters

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-named-parameters": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/style/prefer-named-parameters: <reason>