Skip to content

Commit

Permalink
Update: Report assignment expression location in no-cond-assign
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Nov 4, 2019
1 parent 990065e commit c7edce4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/rules/no-cond-assign.js
Expand Up @@ -117,7 +117,7 @@ module.exports = {

context.report({
node,
loc: node.test.loc.start,
loc: node.test.loc,
messageId: "missing"
});
}
Expand All @@ -134,6 +134,7 @@ module.exports = {
if (ancestor) {
context.report({
node: ancestor,
loc: node.loc,
messageId: "unexpected",
data: {
type: NODE_DESCRIPTIONS[ancestor.type] || ancestor.type
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/no-cond-assign.js
Expand Up @@ -47,12 +47,12 @@ ruleTester.run("no-cond-assign", rule, {
{ code: "switch (foo) { case baz + (a = b): bar(); }", options: ["always"] }
],
invalid: [
{ code: "var x; if (x = 0) { var b = 1; }", errors: [{ messageId: "missing", type: "IfStatement", line: 1, column: 12 }] },
{ code: "var x; if (x = 0) { var b = 1; }", errors: [{ messageId: "missing", type: "IfStatement", line: 1, column: 12, endLine: 1, endColumn: 17 }] },
{ code: "var x; while (x = 0) { var b = 1; }", errors: [{ messageId: "missing", type: "WhileStatement" }] },
{ code: "var x = 0, y; do { y = x; } while (x = x + 1);", errors: [{ messageId: "missing", type: "DoWhileStatement" }] },
{ code: "var x; for(; x+=1 ;){};", errors: [{ messageId: "missing", type: "ForStatement" }] },
{ code: "var x; if ((x) = (0));", errors: [{ messageId: "missing", type: "IfStatement" }] },
{ code: "if (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "an 'if' statement" }, type: "IfStatement" }] },
{ code: "if (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "an 'if' statement" }, type: "IfStatement", column: 18, endColumn: 39 }] },
{ code: "while (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'while' statement" }, type: "WhileStatement" }] },
{ code: "do { } while (someNode || (someNode = parentNode));", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'do...while' statement" }, type: "DoWhileStatement" }] },
{ code: "for (; (typeof l === 'undefined' ? (l = 0) : l); i++) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'for' statement" }, type: "ForStatement" }] },
Expand Down

0 comments on commit c7edce4

Please sign in to comment.