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

Warn when regular expression is used in conditional #59001

Open
6 tasks done
mjbvz opened this issue Jun 24, 2024 · 0 comments
Open
6 tasks done

Warn when regular expression is used in conditional #59001

mjbvz opened this issue Jun 24, 2024 · 0 comments
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jun 24, 2024

πŸ” Search Terms

  • conditional
  • regular expression
  • regex

βœ… Viability Checklist

⭐ Suggestion

When a regular expression literal appears in a conditional, such as:

if (/abc?/) {
    foo()
} else {
    bar()
}

It would be helpful warn that bar() is unreachable. The programmer likely meant to call /abc?/.test(...)

TypeScript could help catch this easy to make mistake

πŸ“ƒ Motivating Example

We recently were bitten by this in VS Code. It slipped through code review too

πŸ’» Use Cases

Help programmers catch an easy to make mistake

RyanCavanaugh added a commit to RyanCavanaugh/TypeScript that referenced this issue Jun 24, 2024
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Experience Enhancement Noncontroversial enhancements labels Jun 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants