Skip to content
Permalink
Browse files

Fix: check token before using in no-cond-assign (fixes #11611) (#11619)

  • Loading branch information...
g-plane authored and not-an-aardvark committed Apr 30, 2019
1 parent 7f290a9 commit b6d41cbe28a8b28b1c1d9aa36cb4c349c73f6f1d
Showing with 3 additions and 2 deletions.
  1. +1 −1 lib/rules/no-cond-assign.js
  2. +2 −1 tests/lib/rules/no-cond-assign.js
@@ -86,7 +86,7 @@ module.exports = {
nextToken = sourceCode.getTokenAfter(node, 1);

return astUtils.isParenthesised(sourceCode, node) &&
astUtils.isOpeningParenToken(previousToken) && previousToken.range[1] <= node.range[0] &&
previousToken && astUtils.isOpeningParenToken(previousToken) && previousToken.range[1] <= node.range[0] &&
astUtils.isClosingParenToken(nextToken) && nextToken.range[0] >= node.range[1];
}

@@ -61,6 +61,7 @@ ruleTester.run("no-cond-assign", rule, {
{ 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: "var x; var b = (x = 0) ? 1 : 0;", errors: [{ messageId: "missing", type: "ConditionalExpression" }] }
{ code: "var x; var b = (x = 0) ? 1 : 0;", errors: [{ messageId: "missing", type: "ConditionalExpression" }] },
{ code: "(((3496.29)).bkufyydt = 2e308) ? foo : bar;", errors: [{ messageId: "missing", type: "ConditionalExpression" }] }
]
});

0 comments on commit b6d41cb

Please sign in to comment.
You can’t perform that action at this time.