Incorrect Unnecessary escape character warning
See original GitHub issueeslint 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:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, sorry about the backticks. I was confused as to how to fix. I figured it out now. Thank you.
@ljharb Ah, thank you!
So, this is working correctly. Those escapes are unnecessary by the language spec.