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

regexp/no-invalid-regexp for invalid regexes #283

Closed
RunDevelopment opened this issue Aug 9, 2021 · 2 comments · Fixed by #288
Closed

regexp/no-invalid-regexp for invalid regexes #283

RunDevelopment opened this issue Aug 9, 2021 · 2 comments · Fixed by #288
Assignees
Labels
enhancement New feature or request new rule

Comments

@RunDevelopment
Copy link
Collaborator

Motivation
While developing #282, I noticed that ESLint's no-invalid-regexp only validates expression of the form RegExp(<string literal>). It doesn't support the concatenation of string literals and all the fancy stuff #282 can do.

E.g. ESLint's no-invalid-regexp will detect RegExp("([") but it can't detect RegExp("([" + ""). We can detect this, so why not report it?

Description
Add a new rule regexp/no-invalid-regexp that behaves like ESLint no-invalid-regexp but uses PatternSource under the hood.

The best way to implement this might be to extend the defineRegexpVisitor to allow a new visitor type that doesn't require a parsed RegExpp AST.

Examples

/* ✓ GOOD */
var foo = RegExp("foo")
var foo = RegExp("([" + "])")

/* ✗ BAD */
var foo = RegExp("([")
var foo = new RegExp("([" + "\\" + "])", "i")
@RunDevelopment RunDevelopment added enhancement New feature or request new rule labels Aug 9, 2021
@RunDevelopment RunDevelopment changed the title regexpp/no-invalid-regexp for invalid regexes regexp/no-invalid-regexp for invalid regexes Aug 9, 2021
@RunDevelopment RunDevelopment self-assigned this Aug 9, 2021
@RunDevelopment
Copy link
Collaborator Author

This is blocked by #282. (obviously)

@ota-meshi
Copy link
Owner

That rule sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants