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

proposal: no_wildcard_variable_uses #59157

Closed
5 tasks done
pq opened this issue May 26, 2023 · 3 comments · Fixed by dart-archive/linter#4396
Closed
5 tasks done

proposal: no_wildcard_variable_uses #59157

pq opened this issue May 26, 2023 · 3 comments · Fixed by dart-archive/linter#4396
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. devexp-linter Issues with the analyzer's support for the linter package linter-lint-proposal linter-new-language-feature P3 A lower priority bug or feature request

Comments

@pq
Copy link
Member

pq commented May 26, 2023

<no_wildcard_variable_uses>

Description

Do not use wildcard parameters or variables.

Details

There's a proposal to change the language so that (at least) parameters and local variables named _ (e.g., wildcards) become non-binding. When that happens, existing code that uses wildcard parameters or variables will break.

Enabling this lint now will make it less breaking to make _ non-binding in a future Dart release.

Kind

Error

Bad Examples

var _ = 1;
print(_); // LINT
void f(int __) {
  print(__); // LINT multiple underscores too
}

Good Examples

for (var _ in [1, 2, 3]) count++;
try {
  ...
} catch (_) {
  ...
}
var [a, _, b, _] = [1, 2, 3, 4];

Discussion

#51221

cc @dart-lang/language-team

Discussion checklist

  • List any existing rules this proposal modifies, complements, overlaps or conflicts with.
  • List any relevant issues (reported here, the SDK Tracker, or elsewhere).
  • If there's any prior art (e.g., in other linters), please add references here.
  • If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn't any corresponding advice, should there be?)
  • If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.
@munificent
Copy link
Member

I know I suggested this name, but now that I think about it, it would probably be better for the name to emphasize that it's using a variable whose name is a wildcard that's the issue, not declaring one. Maybe "do_not_use_wildcard"?

@pq pq changed the title proposal: no_wildcard_wildcard_variables proposal: no_wildcard_variable_uses May 26, 2023
@pq
Copy link
Member Author

pq commented May 26, 2023

Ah, right. It's a good point. I updated to no_wildcard_variable_uses (since we have more no_s than do_not_s) but do_not_use_wildcard_variables would be fine too.

Open to other ideas too!

/cc @bwilkerson

@pq
Copy link
Member Author

pq commented May 26, 2023

Given the support in #51221, I'm going to transition this to accepted and offer a simple implementation. (We don't have to land that obviously.)

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
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. devexp-linter Issues with the analyzer's support for the linter package linter-lint-proposal linter-new-language-feature P3 A lower priority bug or feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants