Skip to content

Commit

Permalink
Fix: no-extra-boolean-cast reports wrong negation node (fixes #11324) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and kaicataldo committed Sep 3, 2019
1 parent ba8c2aa commit 2b1a13f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-extra-boolean-cast.js
Expand Up @@ -96,7 +96,7 @@ module.exports = {
grandparent.callee.name === "Boolean")
) {
context.report({
node,
node: parent,
messageId: "unexpectedNegation",
fix: fixer => {
if (hasCommentsInside(parent)) {
Expand Down
25 changes: 17 additions & 8 deletions tests/lib/rules/no-extra-boolean-cast.js
Expand Up @@ -40,63 +40,72 @@ ruleTester.run("no-extra-boolean-cast", rule, {
output: "if (foo) {}",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 5,
endColumn: 10
}]
},
{
code: "do {} while (!!foo)",
output: "do {} while (foo)",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 14
}]
},
{
code: "while (!!foo) {}",
output: "while (foo) {}",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 8
}]
},
{
code: "!!foo ? bar : baz",
output: "foo ? bar : baz",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 1
}]
},
{
code: "for (; !!foo;) {}",
output: "for (; foo;) {}",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 8
}]
},
{
code: "!!!foo",
output: "!foo",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 2
}]
},
{
code: "Boolean(!!foo)",
output: "Boolean(foo)",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 9
}]
},
{
code: "new Boolean(!!foo)",
output: "new Boolean(foo)",
errors: [{
messageId: "unexpectedNegation",
type: "UnaryExpression"
type: "UnaryExpression",
column: 13
}]
},
{
Expand Down

0 comments on commit 2b1a13f

Please sign in to comment.