avoid-unnecessary-call

Group
Style
Path
lint/style/avoid-unnecessary-call
Default
Off, opt in
Origin
Falcon
Rule
156 of 512

Prefer direct invocation of functions and resolved callable instances.

Null-aware calls remain necessary for nullable receivers. Dynamic, unresolved, static and extension-only call members are deliberately not diagnosed.

Invalid

example.dartdart
typedef Action = void Function();
void inspect(void Function() action, int Function(int) convert, Action alias, Function unknownSignature) {
  action.call();
  convert.call(1);
  alias.call();
  unknownSignature.call();
  (action).call();
}

class Callable {
  void call() {}
}
class InheritedCallable extends Callable {}
void instances(Callable callable, InheritedCallable inherited) {
  callable.call();
  inherited.call();
}
Invoke this function directly instead of using `.call()`.
2void inspect(void Function() action, int Function(int) convert, Action alias, Function unknownSignature) {
3 action.call();
Invoke this function directly instead of using `.call()`.
3 action.call();
4 convert.call(1);
Invoke this function directly instead of using `.call()`.
4 convert.call(1);
5 alias.call();
Invoke this function directly instead of using `.call()`.
5 alias.call();
6 unknownSignature.call();
Invoke this function directly instead of using `.call()`.
6 unknownSignature.call();
7 (action).call();
Invoke this function directly instead of using `.call()`.
14void instances(Callable callable, InheritedCallable inherited) {
15 callable.call();
Invoke this function directly instead of using `.call()`.
15 callable.call();
16 inherited.call();

Valid

example.dartdart
class Callable {
  void call() {}
}
void inspect(void Function()? nullable, void Function() action, Callable custom, dynamic unresolved) {
  nullable?.call();
  action();
  unresolved.call();
  final tearOff = action.call;
  action..call();
}

class StaticCallable {
  static void call() {}
}
class Plain {}
extension CallableExtension on Plain {
  void call() {}
}
void exclusions(Plain plain, Callable? nullableCallable) {
  StaticCallable.call();
  plain.call();
  nullableCallable?.call();
}

Configure avoid-unnecessary-call

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "avoid-unnecessary-call": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/style/avoid-unnecessary-call: <reason>