Consider adding unnecessary_statements to the recommended set #844
Open
Description
I was asked today by a new Dart developer why his code didn't produce any diagnostics when he'd missed the ()
from the end of a method call:
state.foo;
This isn't the first time this has come up to me, and it's also been asked for in the SDK. It seems like a useful lint and it seems like the false positives are real edge cases (like side effects in operators) so I wonder if it would be useful to recommend?
Some issues requesting this (or issues that it may have been avoided if it was used):
- [linter] adding unnecessary_statements to the "recommended rule set" sdk#59732
- proposal: alert me when I forget method's brackets sdk#58725
- Prevent equality checks as statements sdk#59028
- Would like a lint to handle unused tearoffs (or similar) sdk#57760
- [Suggestion]: Flag statements of the form: x == y; as "statement yields unused boolean" sdk#58484
- Unused boolean statements sdk#57319
- Warning if a function call is missing parenthesis sdk#58281
- Hint about statements with no effect sdk#18849
- Analyzer should lint if a statement consists of only an
==
expression sdk#30793
Additionally, it is enabled in the Flutter repository:
Possible false positives I can find are all related to operators with side effects (which I think is probably acceptable - I don't think this is common, except perhaps while print-debugging!):