All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rules.jshint.E014.html Maven / Gradle / Ivy

Go to download

Consume reports generated by jshint for code quality. Also consume reports for code duplication (either simian or cpd). Consumes the unit/integration tests reports (generated by Jasmin) coverage report (lcov generated by Istanbul). The information generated by reports are added in Sonar

There is a newer version: 2.1.0
Show newest version

    

History

This warning was introduced in the original version of JSLint and existed in the same form in JSHint until version 1.0.0 when it was removed. ESLint has always issued the same warning.

When do I get this error?

The "A regular expression literal can be confused with '/='" error is thrown when JSLint, JSHint (prior to version 1.0.0) or ESLint encounters a regular expression literal that begins with the = character. In the following example we attempt to assign a regular expression literal to match the string "=1" to the variable x:

x
 
1
var regex = /=1/;
2
JSLint found 1 errorVersion 2015-09-23
Line 0:Expected '/\=' and instead saw '/='.

Why do I get this error?

This error is raised to highlight a potentially confusing piece of code. Your code will run fine if you do not fix this error, but it may be confusing to others, especially at first glance to someone quickly searching through your script.

The / character is ambiguous in JavaScript. It can either signify the start or end of a regular expression literal, as it does in the example above, or it can be interpreted as the division operator. Like most of the arithmetic operators, the division operator can be combined with the assignment operator to produce a shorthand:

3
 
1
var x = 10;
2
x /= 5; // Shorthand division-assignment operator
3
JSLint found no errorsVersion 2015-09-23

This ambiguity is not a problem because the parser should always be able to differentiate between the two uses. However, you can see why the regular expression example at the top of this page could cause initial confusion.

To solve this issue, you can simply escape the = character in the regular expression. This will behave in exactly the same way but since the = character is no longer the first, the error is not raised:

2
 
1
var regex = /\=1/;
2
JSLint found no errorsVersion 2015-09-23

Alternatively, you can use the RegExp constructor, which removes the need for the ambiguous delimiting / characters:

2
 
1
var regex = new RegExp("=1");
2
JSLint found no errorsVersion 2015-09-23

In ESLint the rule that generates this warning is named no-div-regex. You can disable it by setting it to 0, or enable it by setting it to 1.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy