Skip to main content

avoid-declaring-call-method

added in: 1.3.0
🛠
Pro+

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 in some cases, this behavior is implicit and may lead to unexpected results or overcomplicated code.

Example

❌ Bad:

class WannabeFunction {
// LINT: Avoid declaring a 'call' method. Try renaming it to a regular method instead.
String call(String a, String b, String c) => '$a $b $c!';
}

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');

Additional Resources