Skip to content

"Convert 'forEach' to a 'for' loop" should consider prefer_final_in_for_each #56876

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

Closed
FMorschel opened this issue Oct 9, 2024 · 2 comments
Closed
Labels
legacy-area-analyzer Use area-devexp instead. type-enhancement A request for a change that isn't a bug

Comments

@FMorschel
Copy link
Contributor

The fix Convert 'forEach' to a 'for' loop (lint avoid_function_literals_in_foreach_calls) should consider prefer_final_in_for_each.

Today:

var list = [];
list.forEach((v) => print(v));    //   <- assist available

Becomes:

var list = [];
for (var v in list) {        // <- lint `prefer_final_in_for_each` on `v`
  print(v);
}

I volunteer to fix this.

@dart-github-bot
Copy link
Collaborator

Summary: The "Convert 'forEach' to a 'for' loop" quick fix should consider the prefer_final_in_for_each lint when converting a forEach loop to a for loop. Currently, the fix creates a var variable in the for loop, which triggers the lint.

@dart-github-bot dart-github-bot added legacy-area-analyzer Use area-devexp instead. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Oct 9, 2024
@FMorschel
Copy link
Contributor Author

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants