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

rules.jshint.W093.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

    

When do I get this error?

The "Did you mean to return a conditional instead of an assignment?" error, and the alternative "Return statement should not contain assignment", is thrown when JSHint or ESLint encounters a return statement containing an assignment expression. In the following example we attempt to assign the result of an operation to result and also return the result of that assignment:

x
 
1
var result;
2
function multiply(a, b) {
3
    "use strict";
4
    return result = a * b;
5
}
6
JSHint found 1 errorVersion 2.9.0
Line 4:Did you mean to return a conditional instead of an assignment?

Since May 2013 JSLint has used the more generic "Unexpected assignment expression" warning in the same situation.

Why do I get this error?

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

The above example works because the assignment expression, result = a * b, returns the resultant value of result. Since in a return statement the expression is evaluated and its result is returned from the function we end up with the value we expect. You can resolve this error by splitting the logic out into two distinct steps which makes the code much more readable:

7
 
1
var result;
2
function multiply(a, b) {
3
    "use strict";
4
    result = a * b;
5
    return result;
6
}
7
JSHint found no errorsVersion 2.9.0

If you didn't mean to return the result of an assignment and are receiving this error then the chances are you actually wanted to return a boolean value. This is why JSHint asks if you meant to return a conditional. If that's the case, make sure the expression is conditional by using === instead of =:

6
 
1
var result;
2
function multiply(a, b) {
3
    "use strict";
4
    return result === a * b;
5
}
6
JSHint found no errorsVersion 2.9.0

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W093. This means you can tell JSHint to not issue this warning with the /*jshint -W093 */ directive.

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy