feat: add option allowEscape
to no-misleading-character-class
rule
#18208
+286
−36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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