dart-code-checker/dart-code-metrics

[New rule] avoid-closure-without-call

fzyzcjy opened this issue · 2 comments

Rule details

It is a common typo to forget to call a function, but instead just leave the closure there, especially when doing refactoring etc. Thus, this rule will avoid this.

What type of rule is this?

Warns about a potential problem

Example code

Example 1:


InkWell(
  onTap: () => _handle, // BAD
  onTap: () => _handle(), // GOOD
  onTap: _handle, // GOOD
)

void _handle() { ... }

Example 2:

extension Ext on List {
  void myFunction(int a) { ... }
}

Something(
  someCallback: (a) => myList.myFunction, // BAD
  someCallback: (a) => myList.myFunction(a), // GOOD
  someCallback: myList.myFunction, // GOOD
)


### Participation

- [X] I am willing to submit a pull request to implement this rule.

### Additional comments

_No response_

Great suggestion, implemented

Available in Teams 1.3.0