-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
feat: add option allowEscape
to no-misleading-character-class
rule
#18208
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
These two look like the same kind of possible error this rule targets - the sequence appears as a single character - so perhaps both should not be allowed? |
Maybe we could require that both characters in |
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
Perhaps we could allow only sequences that consist exclusively of ASCII characters. So |
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
I think we can require that combining mark characters in a character class are only allowed when written as escape sequences; which is to say regardless of the previous character. This would be the most immediate solution to always disallow |
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
@mdjermanovic looking for your feedback here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Great work, thanks!
Since this is a new feature, it needs another approval from a team member before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[X] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
Fixes #15080
What changes did you make? (Give an overview)
This PR adds an option to allow escape sequences in regexp character classes to the
no-misleading-character-class
rule. The new option only has effect on nodes whose source location can be statically determined with our tools. These are the same nodes that report granular errors:RegExp
constructorRegExp
constructorIs there anything you'd like reviewers to focus on?
I would like to fine tune this rule to allow only escape sequence that are not confusing, and I'm not sure I've got the right balance. For example
/[\👍]/
contains an escape sequence where the backslash just escapes the next character without changing its value. I think that those escape sequences should be still forbidden even when the new option is set. Other cases are less trivial.In the current implementation, the new option will allow any escape sequences except those where the character being escaped is prepended by one or more backslashes. If one or more of the characters in a group are escaped, the group will be allowed.
/[A\u0301]/
/[👨\u200d👩\u200d👦]/u
/[\n̅]/
\n
is a non-trivial escape sequence/[\e̅]/
\e
ise