-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib,test: remove unneeded escaping of / #9485
Conversation
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.
@Trott We can write lint rule to auto fix it, right?
Commit message either has a missing backtick before |
@princejwesley This is actually enforced by ESLint's The no-useless-escape rule is intentionally not autofixable in ESLint itself, because useless escapes are often due to a programmer error where the code isn't doing what it's supposed to. Of course, Node could create a custom autofixable version of the rule if we wanted to. |
@not-an-aardvark |
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.
Fixed, thanks! |
@princejwesley I don't understand the question. |
@not-an-aardvark We can write custom rule just for regular expression character classes. |
Oh, I see. I suppose we could do that, but based on #9449 (comment) I'm not sure whether we want to do it or whether it would be worth it. |
@Trott Instead of addressing this particular case manually, we can have a rule that will fix automatically. I'll write it if its fine for you 😄 |
I do not want to discourage you from trying! I do suspect some of the resulting changes might be controversial because they reduce readability. For example, here's the current line 549 of var braceExpr = /^(?:property:?\s*)?[^\.\[]+(\[[^\]]+\])\s*?$/i; Let's break out one of the problematic character classes: [^\.\[] Removing the unnecessary escaping of the [^.\[] Removing the unnecessary escaping of the [^.[] You can make the case that the above is not all that confusing, but it gets harder to make that case when you restore the character class to its original context, and even more so when you also remove another extra unnecessary escape in the line for a var braceExpr = /^(?:property:?\s*)?[^.[]+(\[[^\]]+])\s*?$/i; The original is a confusing regular expression to try to read, and the explicit (but unnecessary) escaping makes it easier to understand. Removing the unnecessary escaping makes the line actually more difficult to understand. It's possible that this bit of code could benefit from more refactoring such that the unnecessary escapes are removed and the regular expression is easier to understand. So given all that, if you want to try to do an auto-fix and see what it looks like, that sounds good to me! Even if they don't all get landed, it may be good to fix as many as we can at one time. |
@princejwesley If you're going to add an autofixer, I would recommend using this as a starting point. (The rule has changed a bit since that PR, but I think that basically covers the modification that would need to be made to allow autofixing.) @Trott When we made the bugfix to |
@Trott we can have configurable option to ignore unnecessary escape for characters like |
@princejwesley: Sounds great! Thanks in advance! Looking forward to what you come up with! @not-an-aardvark: Thanks for the context and additional information! |
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#9485 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Landed in 7ef16ee |
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: #9485 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[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: nodejs#9485 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[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: #9485 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
lib test
Description of change
The
/
character does not need to be escaped when occurring inside acharacter class in a regular expression. Remove such instances of
escaping in the code base.
/cc @silverwind