avoid-declaring-call-method
added in: 1.3.0
warning
Warns when a class has a call
method.
Dart has a concept of callable classes, meaning that you can invoke a class instance (if a class has a call
method) like if you'd invoke a regular function / method.
While this feature might be convenient for some use-cases, this behavior is implicit and might lead to unexpected results or overcomplicated code.
Additional resources:
Example
❌ Bad:
class WannabeFunction {
String call(String a, String b, String c) => '$a $b $c!'; // LINT
}
var wf = WannabeFunction();
var out = wf('Hi', 'there,', 'gang');
✅ Good:
class WannabeFunction {
String calculate(String a, String b, String c) => '$a $b $c!';
}
var wf = WannabeFunction();
var out = wf.calculate('Hi', 'there,', 'gang');