dart-code-checker / dart-code-metrics

Software analytics tool that helps developers analyse and improve software quality.
https://dcm.dev
Other
856 stars 265 forks source link

[New rule] avoid-closure-without-call #1217

Closed fzyzcjy closed 1 year ago

fzyzcjy commented 1 year ago

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_
incendial commented 1 year ago

Great suggestion, implemented

incendial commented 1 year ago

Available in Teams 1.3.0