avoid-declaring-call-method
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 may lead to unexpected results or overcomplicated code.
Additional resources:
-https://gist.github.com/ilikerobots/df1fec65cf0b91a1dfa2f94dc4e43680
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');