tools: Add no useless regex char class rule#9591
tools: Add no useless regex char class rule#9591princejwesley wants to merge 2 commits intonodejs:masterfrom
Conversation
|
Nice! Any plans to submit the |
|
Looking at the 10 things that this flags, I'd be OK with all of them getting fixed. :-D Would love to see the option upstreamed to ESLint itself so as to make this rule unnecessary, but for now, this seems like a good approach to me. Would be interested in @not-an-aardvark's opinion. |
|
CI: https://ci.nodejs.org/job/node-test-pull-request/4837/ @Trott I am interested in @not-an-aardvark's opinion 😄 |
|
I suspect you know this, but just to be safe: When landing this, the commit that fixes the useless escapes should land before the commit the enables the linting rule. This way, there's no chance of someone doing a |
not-an-aardvark
left a comment
There was a problem hiding this comment.
LGTM with a few nits.
However, I noticed that this doesn't check string literals. Assuming we're planning to turn off no-useless-escape in favor of this rule, we will no longer be enforcing against useless escapes in string literals (e.g. 'foo \ bar').
There was a problem hiding this comment.
Nit: This can be replaced with fixer.replaceTextRange([start, start + 1], '')
There was a problem hiding this comment.
Nit: I think this is supposed to say empty.
There was a problem hiding this comment.
I noticed that this function is very different from the corresponding one in no-useless-escape. This isn't necessarily a problem, but is there a reason to change it?
There was a problem hiding this comment.
it covers only RegExp character class.
(Possible) Useless Escape > (Possible) Useless RegExp Escape > Useless RegExp Character Class Escape (optional override)
Eslint Rule:
Disallow useless escape in regex character class
with optional override characters option and auto
fixable with eslint --fix option.
Usage:
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]
PR-URL: nodejs#9591
The `/` character does not need to be escaped when occurring inside a character class in a regular expression. Remove such instances of escaping in the code base. PR-URL: nodejs#9591
dba2a78 to
1fd4f71
Compare
not-an-aardvark
left a comment
There was a problem hiding this comment.
The implementation LGTM. I am still a bit worried about what I mentioned here, though; if we disable the regular no-useless-escape rule, we won't be checking for useless escapes in strings.
I had imagined going this route:
Then, at some point, we do one of the following. Either:
...or...
|
The `/` character does not need to be escaped when occurring inside a character class in a regular expression. Remove such instances of escaping in the code base. PR-URL: nodejs#9591 Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Eslint Rule:
Disallow useless escape in regex character class
with optional override characters option and auto
fixable with eslint --fix option.
Usage:
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]
PR-URL: nodejs#9591
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
The `/` character does not need to be escaped when occurring inside a character class in a regular expression. Remove such instances of escaping in the code base. PR-URL: #9591 Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Eslint Rule:
Disallow useless escape in regex character class
with optional override characters option and auto
fixable with eslint --fix option.
Usage:
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]
PR-URL: #9591
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
|
@Trott would you be willing to manually backport? |
|
@thealphanerd Did you mean to @-mention @princejwesley instead? |
|
@princejwesley would you be willing to backport? |
Eslint Rule:
Disallow useless escape in regex character class
with optional override characters option and auto
fixable with eslint --fix option.
Usage:
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]
PR-URL: #9591
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Eslint Rule:
Disallow useless escape in regex character class
with optional override characters option and auto
fixable with eslint --fix option.
Usage:
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]
PR-URL: nodejs/node#9591
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Checklist
make -j8 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
tools
Description of change
Eslint Rule:
Disallow useless escape in regex character class
with optional override characters option and auto
fixable with eslint
--fixoption.Usage:
no-useless-regex-char-class-escape: [2, { override: ['[', ']'] }]Note : ~~~lint errors(10) due to this rule is not addressed. Reason is, override list is not finalised.~~~
CC: @Trott