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
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();
}void inspect(void Function() action, int Function(int) convert, Action alias, Function unknownSignature) { action.call(); action.call(); convert.call(1); convert.call(1); alias.call(); alias.call(); unknownSignature.call(); unknownSignature.call(); (action).call();void instances(Callable callable, InheritedCallable inherited) { callable.call(); callable.call(); inherited.call();Valid
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.
{
"linter": {
"rules": {
"style": {
"avoid-unnecessary-call": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-unnecessary-call: <reason>More style rules
- avoid-unnecessary-continue
Flags an unlabeled continue at the end of a loop body or its final branch.
- avoid-unnecessary-getter
Flags a getter that only exposes a private final field.
- avoid-unnecessary-if
Flags an if branch that only returns the same expression as the following return.
- avoid-unnecessary-length-check
Empty collections already skip
for-inandforEachbodies. - avoid-unnecessary-local-variable
Reports a single-use local used only to initialize the next local.
- avoid-unnecessary-negations
Simplifies negated bool literals and equality comparisons with a logical negation on both sides.
- avoid-unnecessary-overrides-in-stateflutter
Redundant Flutter State overrides that drop inherited
@protected. - avoid-unnecessary-reassignment
Reports an eager local initializer immediately overwritten without a read.