From 2b1a13fa0de8360586857f3ced8da514c971297d Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Tue, 3 Sep 2019 04:38:06 +0200 Subject: [PATCH] Fix: no-extra-boolean-cast reports wrong negation node (fixes #11324) (#12197) --- lib/rules/no-extra-boolean-cast.js | 2 +- tests/lib/rules/no-extra-boolean-cast.js | 25 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/rules/no-extra-boolean-cast.js b/lib/rules/no-extra-boolean-cast.js index 9bbd5546edd..e818cd448c4 100644 --- a/lib/rules/no-extra-boolean-cast.js +++ b/lib/rules/no-extra-boolean-cast.js @@ -96,7 +96,7 @@ module.exports = { grandparent.callee.name === "Boolean") ) { context.report({ - node, + node: parent, messageId: "unexpectedNegation", fix: fixer => { if (hasCommentsInside(parent)) { diff --git a/tests/lib/rules/no-extra-boolean-cast.js b/tests/lib/rules/no-extra-boolean-cast.js index 1de914ca585..a530f81f603 100644 --- a/tests/lib/rules/no-extra-boolean-cast.js +++ b/tests/lib/rules/no-extra-boolean-cast.js @@ -40,7 +40,9 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "if (foo) {}", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 5, + endColumn: 10 }] }, { @@ -48,7 +50,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "do {} while (foo)", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 14 }] }, { @@ -56,7 +59,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "while (foo) {}", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 8 }] }, { @@ -64,7 +68,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "foo ? bar : baz", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 1 }] }, { @@ -72,7 +77,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "for (; foo;) {}", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 8 }] }, { @@ -80,7 +86,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "!foo", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 2 }] }, { @@ -88,7 +95,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "Boolean(foo)", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 9 }] }, { @@ -96,7 +104,8 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: "new Boolean(foo)", errors: [{ messageId: "unexpectedNegation", - type: "UnaryExpression" + type: "UnaryExpression", + column: 13 }] }, {