banned-usage

Path
lint/suspicious/banned-usage
Default
Off, opt in
Origin
Falcon
Rule
192 of 512

Ban resolved API references, not identifiers that merely share their spelling. Match top-level declaration names or DeclaringType.member; prefixes are ignored. Calls, tear-offs, property reads/writes, constructors and cascades are included. Unnamed constructors consistently use Class.new, including aliases and prefixes. Dynamic and unresolved targets are skipped.

Invalid

example.dartdart
import 'support.dart';
import 'support.dart' as p;

void legacy() {}
void example(Client client) {
  legacy();
  var callback = legacy;
  client.old();
  var method = client.old;
  client..old();
}

void constructorsAndStatics() {
  Client();
  new Client();
  const Client();
  p.Client();
  var factory = Client.new;
  Alias.named();
  new Alias.named();
  print(Client.flag);
  print(p.Client.flag);
  print(Choice.legacy);
}

extension on String {
  void shout() => legacy();
}
class Base {
  void legacy() {}
}
class Sub extends Base {
  void run() => legacy();
}
void shorthand() {
  Choice choice = .legacy;
  Client named = .named();
  Client unnamed = .new();
}

class ChildClient extends Client {
  ChildClient() : super.named();
}
class ClientFactory {
  factory ClientFactory() = ClientFactory.named;
  ClientFactory.named();
}
Use the supported alternative.
5void example(Client client) {
6 legacy();
Use the supported alternative.
6 legacy();
7 var callback = legacy;
Use the supported alternative.
7 var callback = legacy;
8 client.old();
Use the supported alternative.
8 client.old();
9 var method = client.old;
Use the supported alternative.
9 var method = client.old;
10 client..old();
Use the supported alternative.
13void constructorsAndStatics() {
14 Client();
Use the supported alternative.
14 Client();
15 new Client();
Use the supported alternative.
15 new Client();
16 const Client();
Use the supported alternative.
16 const Client();
17 p.Client();
Use the supported alternative.
17 p.Client();
18 var factory = Client.new;
Use the supported alternative.
18 var factory = Client.new;
19 Alias.named();
Use the supported alternative.
19 Alias.named();
20 new Alias.named();
Use the supported alternative.
20 new Alias.named();
21 print(Client.flag);
Use the supported alternative.
21 print(Client.flag);
22 print(p.Client.flag);
Use the supported alternative.
22 print(p.Client.flag);
23 print(Choice.legacy);
Use the supported alternative.
26extension on String {
27 void shout() => legacy();
Use the supported alternative.
32class Sub extends Base {
33 void run() => legacy();
Use the supported alternative.
35void shorthand() {
36 Choice choice = .legacy;
Use the supported alternative.
36 Choice choice = .legacy;
37 Client named = .named();
Use the supported alternative.
37 Client named = .named();
38 Client unnamed = .new();
Use the supported alternative.
41class ChildClient extends Client {
42 ChildClient() : super.named();
Use the supported alternative.
44class ClientFactory {
45 factory ClientFactory() = ClientFactory.named;

Valid

example.dartdart
void legacy() {}
class Other {
  void old() {}
}
void example(Other client) {
  void legacy() {}
  legacy();
  client.old();
}
void dynamicReceiver(dynamic client) {
  client.old();
}

class StaticOwner {
  static void legacy() {}
  void run() => legacy();
}
extension ExtensionOwner on int {
  void legacy() {}
  void run() => legacy();
}
enum OtherChoice {
  legacy;
  void run() => print(legacy);
}
class T {}
void generic<T>() => print(T);

extension on String {
  void legacy() {}
  void run() => legacy();
}
class GenericClient<T> {
  const GenericClient.allowed();
}
void genericConstructors() {
  GenericClient<int>.allowed();
  var constructor = GenericClient<int>.allowed;
}

class InheritedBase {
  void old() {}
}
class InheritedChild extends InheritedBase {
  void run() => old();
}
enum ModernChoice { current }
class ModernClient {
  ModernClient.named();
}
void shorthand() {
  ModernChoice choice = .current;
  ModernClient client = .named();
}
extension on int {
  int get legacy => this;
  int read() => legacy;
}

class ModernBase {
  ModernBase.named();
}
class ModernChild extends ModernBase {
  ModernChild() : super.named();
  ModernChild.redirect() : this();
}
class ModernFactory {
  factory ModernFactory() = ModernFactory.named;
  ModernFactory.named();
}

Configure banned-usage

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

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

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

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