Uh oh!
There was an error while loading. Please reload this page.
tools: Add no useless regex char class rule - #9591
Conversation
Trott
commented
Nov 14, 2016
Nice! Any plans to submit the |
Trott
commented
Nov 14, 2016
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. |
princejwesley
commented
Nov 14, 2016
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#9591The `/` 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
1fd4f71Compareprincejwesley
commented
Nov 14, 2016
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.
Trott
commented
Nov 16, 2016
I had imagined going this route:
Then, at some point, we do one of the following. Either:
...or...
|
Trott
commented
Nov 24, 2016
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>MylesBorins
commented
Dec 20, 2016
@Trott would you be willing to manually backport? |
Trott
commented
Dec 20, 2016
@thealphanerd Did you mean to @-mention @princejwesley instead? |
MylesBorins
commented
Dec 21, 2016
@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