avoid-banned-types

Path
lint/suspicious/avoid-banned-types
Default
Off, opt in
Origin
Falcon
Rule
20 of 512

Ban resolved explicit type annotations, including nested generic arguments. Aliases are expanded; import prefixes and nullability do not change matching. Unknown types are not reported. Match against the declaration's simple name.

Invalid

example.dartdart
class Legacy {}
typedef Alias = Legacy;
Legacy? value;
List<Legacy> values = [];
Alias? alias;

class Wrapper<T> {
  const Wrapper();
}
void genericConstructions() {
  final list = new List<Legacy>.empty();
  final wrapper = const Wrapper<Legacy>();
}
Use the supported alternative.
1class Legacy {}
2typedef Alias = Legacy;
Use the supported alternative.
2typedef Alias = Legacy;
3Legacy? value;
Use the supported alternative.
3Legacy? value;
4List<Legacy> values = [];
Use the supported alternative.
4List<Legacy> values = [];
5Alias? alias;
Use the supported alternative.
10void genericConstructions() {
11 final list = new List<Legacy>.empty();
Use the supported alternative.
11 final list = new List<Legacy>.empty();
12 final wrapper = const Wrapper<Legacy>();

Valid

example.dartdart
class Modern {}
Modern? value;
List<Modern> values = [];
// Unknown types cannot establish a forbidden declaration identity.
Unknown? unknown;

class Legacy {
  const Legacy();
}
class Box<Legacy> {
  Legacy? value;
}
void generic<Legacy>(Legacy value) {
  Legacy? local;
}
void outer() {
  void nested<Legacy>(Legacy value) {}
}
typedef Callback = void Function<Legacy>(Legacy);
void constructors() {
  Legacy();
  new Legacy();
  const Legacy();
}

class Wrapper<T> {
  const Wrapper();
}
void genericConstructions() {
  final list = new List<Modern>.empty();
  final wrapper = const Wrapper<Modern>();
}

Configure avoid-banned-types

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "suspicious": {
        "avoid-banned-types": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/suspicious/avoid-banned-types: <reason>