avoid-types-as-parameter-names

Same as avoid_types_as_parameter_names in Dart lints

Path
lint/suspicious/avoid-types-as-parameter-names
Default
On (recommended)
Origin
Dart lints
Rule
149 of 512
recommended

Flags implicit formal parameters, catch variables, and type parameters that shadow a type in their enclosing scope.

Invalid

example.dartdart
// @dart = 3.13

typedef Callback = void Function(int value);
class Widget {}
void primitive(int) {}
void alias(Callback) {}
void localType(Widget) {}
void shadowType<Widget>() {}
void outer<T>() {
  void inner<T>() {}
  final Object Function<T>(T) callback = <T>(T value) => value;
}
void catches() {
  try {} catch (Widget) {}
}

class Primary(Widget);
typedef void LegacyTypeName(Widget);
void nestedImplicit(void cb(Widget)) {}
Avoid using an existing type as a parameter name.
4class Widget {}
5void primitive(int) {}
Avoid using an existing type as a parameter name.
5void primitive(int) {}
6void alias(Callback) {}
Avoid using an existing type as a parameter name.
6void alias(Callback) {}
7void localType(Widget) {}
Avoid using an existing type as a type parameter name.
7void localType(Widget) {}
8void shadowType<Widget>() {}
Avoid using an existing type as a type parameter name.
9void outer<T>() {
10 void inner<T>() {}
Avoid using an existing type as a type parameter name.
10 void inner<T>() {}
11 final Object Function<T>(T) callback = <T>(T value) => value;
Avoid using an existing type as a type parameter name.
10 void inner<T>() {}
11 final Object Function<T>(T) callback = <T>(T value) => value;
Avoid using an existing type as a parameter name.
13void catches() {
14 try {} catch (Widget) {}
Avoid using an existing type as a parameter name.
16
17class Primary(Widget);
Avoid using an existing type as a parameter name.
17class Primary(Widget);
18typedef void LegacyTypeName(Widget);
Avoid using an existing type as a parameter name.
18typedef void LegacyTypeName(Widget);
19void nestedImplicit(void cb(Widget)) {}

Valid

example.dartdart
// @dart = 3.13

typedef Callback = void Function(int value);
void callback(Callback callback) {}
class Widget {}
void explicitFunction(void Function(int) int) {}
void explicitAlias(Object Callback) {}
void explicitClass(Object Widget) {}
class Box<T> {
  void method<T>() {}
}
void implicitFunction(int()) {}

// Declaring primary-constructor parameters have field-formal elements.
class DeclaringFinal(final Widget);
class DeclaringVar(var Widget);
class WildcardTypeParameter<_> {
  var _;
  WildcardTypeParameter(this._, _);
}

Configure avoid-types-as-parameter-names

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "suspicious": {
        "avoid-types-as-parameter-names": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/suspicious/avoid-types-as-parameter-names: <reason>