I have this regex of mine that will check the string if it contains link or url (i.e. https://eslint.org/docs/rules/no-useless-escape)
. Using this regex /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
, I've encountered and error while running my test cases in react about Unnecessary escape character: \/ no-useless-escape
. How to disable this eslint-error in order for me to proceed with my test case and use the regex.
Appreciate for any help!
A unicode escape sequence is a backslash followed by the letter 'u' followed by four hexadecimal digits (0-9a-fA-F). It matches a character in the target sequence with the value specified by the four digits. For example, ”\u0041“ matches the target sequence ”A“ when the ASCII character encoding is used.
You can also disable all ESLint rules by putting /* eslint-disable */ at the top of a file.
Operators: * , + , ? , | Anchors: ^ , $ Others: . , \ In order to use a literal ^ at the start or a literal $ at the end of a regex, the character must be escaped.
You can use ESLint and try adding either of the things:-
//eslint-disable-line
on the line to disable warnings.//eslint-disable-next-line
to line before to disable warnings.See from docs of ESLint, Disabling Rules with Inline Comments.
To disable all rules on a specific line, use a line or block comment in one of the following formats:
alert('foo'); // eslint-disable-line // eslint-disable-next-line alert('foo'); /* eslint-disable-next-line */ alert('foo'); alert('foo'); /* eslint-disable-line */
You can disable warnings in entire file by adding /* eslint-disable */
at the top of the file.
To disable rule warnings in an entire file, put a
/* eslint-disable */
block comment at the top of the file:/* eslint-disable */ alert('foo');
It's the \/
in [-A-Z0-9+&@#\/%?=~_|!:,.;]
and [-A-Z0-9+&@#\/%=~_|]
(NOT the ones in :\/\/
). Most characters do not have to be escaped within a character class (square brackets). This should be equivalent: /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/ig
See https://www.regular-expressions.info/charclass.html for more info, but the relevant part:
In most regex flavors, the only special characters or metacharacters inside a character class are the closing bracket ], the backslash , the caret ^, and the hyphen -. The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash. To search for a star or plus, use [+*]. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.
You can also use
/* eslint-disable no-useless-escape */
to disable rule for entire script file.
//eslint-disable-next-line
place this above the line of code
OR
/*eslint no-undef: 0*/
place this on the first line of the file(or first line of the script tag) this would make eslint disabled on the whole file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With