Skip to content

avoid_unnecessary_call

v1.0.0 Warning Code Quality

This rule flags a function invoked through an explicit .call().

callback.call() and callback() do the same thing, and the shorter one is how a function is invoked everywhere else in the language. Spelling out .call makes a plain invocation look like a method on an object, so a reader stops to check whether the receiver is a callable class.

Two cases are left alone. A null-aware invocation (callback?.call()) has no shorthand — callback?() does not parse. And a class defining call as a real method is invoking that method, where .call is part of its name rather than the implicit function interface; the rule checks the receiver’s type to tell the two apart.

void submit(void Function() onDone) {
onDone.call();
}
void submit(void Function() onDone) {
onDone();
}

This rule is in the opinionated preset.

To disable this rule:

many_lints.yaml
rules:
avoid_unnecessary_call: false

To keep the rule on but skip certain paths, use per-rule exclude.