avoid_unnecessary_call
v1.0.0 Warning Code Quality
This rule flags a function invoked through an explicit .call().
Why use this rule
Section titled “Why use this rule”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();}Turning this rule off
Section titled “Turning this rule off”This rule is in the opinionated preset.
To disable this rule:
rules: avoid_unnecessary_call: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_accessing_other_classes_private_members— Make the underscore mean what everyone reads it as.avoid_commented_out_code— Detect and flag commented-out code.avoid_complex_conditions— Keep boolean conditions within an operand budget.avoid_deep_nesting— Keep control flow within a nesting budget.