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.

Incorrect Unnecessary escape character warning

See original GitHub issue

eslint version 3.16.1 node version 6.6.0 npm version 3.10.8

For my slugify function below, I’m getting 3 unnecessary escape character warnings on /- when those parts are definitely needed.

function slugify(text) {
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
}

01:32:54 web.1 | 25:19 warning Unnecessary escape character: - no-useless-escape 01:32:54 web.1 | 26:15 warning Unnecessary escape character: - no-useless-escape 01:32:54 web.1 | 26:17 warning Unnecessary escape character: - no-useless-escape

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
krisfieldscommented, May 16, 2017

Ok, sorry about the backticks. I was confused as to how to fix. I figured it out now. Thank you.

1reaction
mysticateacommented, May 14, 2017

@ljharb Ah, thank you!

So, this is working correctly. Those escapes are unnecessary by the language spec.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Unnecessary escape character: \/ no-useless-escape
I had a similar warning in react. Unnecessary escape character: \# no-useless-escape. Simply just remove whatever is mentioned in the ...
Read more >
no-useless-escape - ESLint - Pluggable JavaScript Linter
This rule flags escapes that can be safely removed without changing behavior. Examples of incorrect code for this rule: /*eslint no-useless-escape: "error"*/ " ......
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 >
Unnecessary escape character? · Issue #704 - GitHub
One good argument for why ESLint should not warn about \] is that regex's "Unicode mode" (which @mathiasbynens recently described as "strict ...
Read more >
Improve Readability with ES6 Template Strings
Yay, no more backslash \ to escape characters in strings! A better way is to use template strings with backticks ( ` )....
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