Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
tools: Add no useless regex char class rule#9591
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
princejwesley commented Nov 13, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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 😄 |
Trott commented Nov 14, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This can be replaced with fixer.replaceTextRange([start, start + 1], '')
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.
Done
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.
Nit: I think this is supposed to say empty.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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 <[email protected]>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 <[email protected]>
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 <[email protected]>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 <[email protected]>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 <[email protected]>
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