Lint Rules

noConditionalAssignment (since v11.0.0)

Disallow assignment operators in conditional expressions.

Examples

Invalid

var x;
if (x = 0) {
    var b = 1;
}
nursery/noConditionalAssignment.js:2:5 lint/nursery/noConditionalAssignment  FIXABLE  ━━━━━━━━━━━━━━

   Expected a conditional expression and instead saw an assignment.
  
    1 │ var x;
  > 2 │ if (x = 0) {
       ^^^^^
    3 │     var b = 1;
    4 │ }
  
   Suggested fix: Did you mean '==='?
  
    2 │ if·(x·===·0)·{
         ++     
function setHeight(someNode) {
    "use strict";
    do {
        someNode.height = "100px";
    } while (someNode = someNode.parentNode);
}
nursery/noConditionalAssignment.js:5:14 lint/nursery/noConditionalAssignment  FIXABLE  ━━━━━━━━━━━━━

   Expected a conditional expression and instead saw an assignment.
  
    3 │     do {
    4 │         someNode.height = "100px";
  > 5 │     } while (someNode = someNode.parentNode);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    6 │ }
    7 │ 
  
   Suggested fix: Did you mean '==='?
  
    5 │ ····}·while·(someNode·===·someNode.parentNode);
                         ++                      

Valid

var x;
if (x === 0) {
    var b = 1;
}
function setHeight(someNode) {
    "use strict";
    do {
        someNode.height = "100px";
    } while ((someNode = someNode.parentNode) !== null);
}