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: unnecessary_pattern lint #59616

Open
HosseinYousefi opened this issue Nov 26, 2024 · 1 comment
Open

Proposal: unnecessary_pattern lint #59616

HosseinYousefi opened this issue Nov 26, 2024 · 1 comment
Labels
analyzer-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. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@HosseinYousefi
Copy link
Member

Consider this:

final foo = int.parse('1') == 1 ? '1' : null;
if (foo case final bar) {
  print(bar);
}

What we wanted to do is to check for foo's nullity, but actually we forgot to type ?. foo case final bar is unnecessary as it basically matches everything, it'd be good if we have a lint to warn us here.

@dart-github-bot
Copy link
Collaborator

Summary: Proposed lint unnecessary_pattern detects unnecessary case statements in pattern matching when the pattern matches all possible values, indicating a likely coding error. This helps catch unintended matches.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. 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 Nov 26, 2024
@keertip keertip added the analyzer-linter Issues with the analyzer's support for the linter package label Nov 26, 2024
@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Nov 26, 2024
@keertip keertip added the P3 A lower priority bug or feature request label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-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. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants