Skip to content

Warn when regular expression is used in conditionalΒ #59001

Open

Description

πŸ” 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions