Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linter] adding unnecessary_statements to the "recommended rule set" #59732

Closed
stephane-archer opened this issue Dec 16, 2024 · 6 comments
Closed
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@stephane-archer
Copy link

void bar() {
  print('hello world');
}
void main() {
  /// a lot of code
  bar;
  /// a lot of code
}

I was debugging and could not figure out why my code wasn't working and why I wasn't breaking in bar...

Can we have a linter to detect this kind of statement: functionName;?
From my understanding, these types of statements are not doing anything.
The author probably meats functionName(); if it wasn't passed to anything.

@stephane-archer stephane-archer added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Dec 16, 2024
@bwilkerson
Copy link
Member

Does the unnecessary_statements lint do what you're looking for?

@stephane-archer
Copy link
Author

@bwilkerson yes, thank you! you might consider adding it to the "recommended rule set"

@stephane-archer stephane-archer changed the title [linter] function name statements; [linter] adding unnecessary_statements to the "recommended rule set" Dec 16, 2024
@DanTup
Copy link
Collaborator

DanTup commented Dec 20, 2024

@bwilkerson not sure if you missed the question above. Someone just asked me about the same thing - he was surprised he had no diagnostic when he had the parens missing on a function call.

Does this lint ever produce false positives, or does it only trigger when the statement geniunely does nothing? If the latter, could it be considered as a core lint - it could help new developers that aren't familiar with the difference. (I couldn't find if there's a process for suggesting new lints - are issues here the right way?).

@bwilkerson
Copy link
Member

Sorry, yes, I forgot to answer the question:

To propose a lint for inclusion in one of the existing lint sets (core, recommended, or flutter), please open an issue in the lints repository, discussing the value of the lint and, if the lint has false-positives, why you think it's worth the possible noise or how we might remove the false positives.

Does this lint ever produce false positives ...

Yes, it can have false positives, but as far as I know that will happen only when the language is used in a non-standard way. The example from the docs is a statement of the form a + b. If the type of a is a user defined type and that type overrides + in such a way that it has a side-effect, then the statement is probably necessary. I hope that most users aren't writing operators with side-effects, but we can't completely discount the possibility.

@stephane-archer
Copy link
Author

@DanTup can you link the issue here so I can follow it too?

@DanTup
Copy link
Collaborator

DanTup commented Dec 20, 2024

@bwilkerson thanks! I saw the linter repo was marked archived and thought here might tbe the right place. Although I see the lints repo has 0 issues now, and many have been moved to core, so I have filed the request there:

dart-lang/core#844

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

3 participants