no-cond-assign
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-cond-assign": "error",
},
},
];// Unintentional assignment
let x;
if (x = 0) {
const b = 1;
}
// Practical example that is similar to an error
const setHeight = function (someNode) {
do {
someNode.height = "100px";
} while (someNode = someNode.parentNode);
}// Unintentional assignment
let x;
if (x = 0) {
const b = 1;
}
// Practical example that is similar to an error
const setHeight = function (someNode) {
do {
someNode.height = "100px";
} while (someNode = someNode.parentNode);
}
// Practical example that wraps the assignment in parentheses
const set_height = function (someNode) {
do {
someNode.height = "100px";
} while ((someNode = someNode.parentNode));
}
// Practical example that wraps the assignment and tests for 'null'
const heightSetter = function (someNode) {
do {
someNode.height = "100px";
} while ((someNode = someNode.parentNode) !== null);
}// Assignment replaced by comparison
let x;
if (x === 0) {
const b = 1;
}
// Practical example that wraps the assignment in parentheses
const setHeight = function (someNode) {
do {
someNode.height = "100px";
} while ((someNode = someNode.parentNode));
}
// Practical example that wraps the assignment and tests for 'null'
const set_height = function (someNode) {
do {
someNode.height = "100px";
} while ((someNode = someNode.parentNode) !== null);
}// Assignment replaced by comparison
let x;
if (x === 0) {
const b = 1;
}Examples from the ESLint documentation.
no-cond-assign
eslint
export default [
{
rules: {
"no-cond-assign": "error",
},
},
];no-cond-assign
eslint plugin · correctness
{
"rules": {
"no-cond-assign": "error"
}
}suspicious/noAssignInExpressions
suspicious · since 1.0.0
{
"linter": {
"rules": {
"suspicious": {
"noAssignInExpressions": "error"
}
}
}
}Disallow reassigning exceptions in catch clauses
Disallow assignments to native objects or read-only global variables
Disallow identifiers from shadowing restricted names
Require calls to isNaN() when checking for NaN
Disallow control characters in regular expressions