Skip to content
Permalink
Browse files

Fix: no-extra-boolean-cast reports wrong negation node (fixes #11324) (

  • Loading branch information
mdjermanovic authored and kaicataldo committed Sep 3, 2019
1 parent ba8c2aa commit 2b1a13fa0de8360586857f3ced8da514c971297d
Showing with 18 additions and 9 deletions.
  1. +1 −1 lib/rules/no-extra-boolean-cast.js
  2. +17 −8 tests/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)) {
@@ -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
}]
},
{

0 comments on commit 2b1a13f

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