question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong no-useless-escape when escaping character after escaping "\"

See original GitHub issue

Tell us about your environment

Node version: v10.7.0 npm version: v6.8.0 Local ESLint version: v6.6.0 Global ESLint version: v6.6.0 (Currently used)

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

The problem exists with default settings.

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

The problem is when you try to escape a character after escaping a backslash.

const regEx =  "[\\\/]"; //match backslash or forwardslash

Command used:

eslint

What did you expect to happen? No eslint error/warning.

What actually happened? Please include the actual, raw output from ESLint. no-useless-escape error/warning.

EDIT: Changed the example. Exclamation does not need an escape. But forwardslash does.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
aladdin-addcommented, Nov 14, 2019
1reaction
mdjermanoviccommented, Nov 14, 2019

Hi @MarkusLund, thanks for the issue!

The example indeed looks like a useless escape:

"[\\\!]" === "[\\!]" // true
Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Unnecessary escape character: \/ no-useless-escape
The linter was showing an error due to '\.' inside square brackets ('[]'). Square brackets do not need an escape character ('\') to...
Read more >
no-useless-escape - ESLint - Pluggable JavaScript Linter
Rule Details​​ This rule flags escapes that can be safely removed without changing behavior.
Read more >
Python Escape Characters
An escape character is a backslash \ followed by the character you want to insert. An example of an illegal character is a...
Read more >
regexp/no-useless-escape
This rule reports unnecessary escape characters in RegExp. You may be able to find another mistake by finding unnecessary escapes.
Read more >
no-useless-escape - Rules - ESLint中文文档
Escaping non-special characters in strings, template literals, and regular expressions doesn't have any effect, as demonstrated in the following example:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found