Permalink
Browse files

Update: Make no-cond-assign work for ternaries (fixes #10091) (#10109)

  • Loading branch information...
goodoldneon authored and platinumazure committed Mar 22, 2018
1 parent f1f1bdf commit ea6fb17aee8af295bc46a467cf22c3e72dbd68c3
Showing with 6 additions and 3 deletions.
  1. +2 −1 lib/rules/no-cond-assign.js
  2. +4 −2 tests/lib/rules/no-cond-assign.js
@@ -139,7 +139,8 @@ module.exports = {
DoWhileStatement: testForAssign,
ForStatement: testForAssign,
IfStatement: testForAssign,
WhileStatement: testForAssign
WhileStatement: testForAssign,
ConditionalExpression: testForAssign
};
}
@@ -40,7 +40,8 @@ ruleTester.run("no-cond-assign", rule, {
{ code: "if ((node => node = parentNode)(someNode)) { }", options: ["always"], parserOptions: { ecmaVersion: 6 } },
{ code: "if (function(node) { return node = parentNode; }) { }", options: ["except-parens"] },
{ code: "if (function(node) { return node = parentNode; }) { }", options: ["always"] },
{ code: "x = 0;", options: ["always"] }
{ code: "x = 0;", options: ["always"] },
"var x; var b = (x === 0) ? 1 : 0;"
],
invalid: [
{ code: "var x; if (x = 0) { var b = 1; }", errors: [{ messageId: "missing", type: "IfStatement", line: 1, column: 12 }] },
@@ -59,6 +60,7 @@ ruleTester.run("no-cond-assign", rule, {
{ code: "if ((x = 0)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "an 'if' statement" }, type: "IfStatement" }] },
{ code: "while ((x = 0)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'while' statement" }, type: "WhileStatement" }] },
{ code: "do { } while ((x = x + 1));", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'do...while' statement" }, type: "DoWhileStatement" }] },
{ code: "for(; (x = y); ) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'for' statement" }, type: "ForStatement" }] }
{ code: "for(; (x = y); ) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'for' statement" }, type: "ForStatement" }] },
{ code: "var x; var b = (x = 0) ? 1 : 0;", errors: [{ messageId: "missing", type: "ConditionalExpression" }] }
]
});

0 comments on commit ea6fb17

Please sign in to comment.