Skip to content

Commit

Permalink
Fix : Don't try too hard to find fault in no-implicit-coercion (refs
Browse files Browse the repository at this point in the history
  • Loading branch information
BYK committed Aug 26, 2015
1 parent 4458a56 commit 287f41c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
7 changes: 1 addition & 6 deletions lib/rules/no-implicit-coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ function isBinaryNegatingOfIndexOf(node) {
function isMultiplyByOne(node) {
return node.operator === "*" && (
node.left.type === "Literal" && node.left.value === 1 ||
node.right.type === "Literal" && node.right.value === 1 ||
node.parent.type === "BinaryExpression" && isMultiplyByOne(node.parent)
node.right.type === "Literal" && node.right.value === 1
);
}

Expand Down Expand Up @@ -100,10 +99,6 @@ function getNonNumericOperand(node) {
if (left.type !== "BinaryExpression" && !isNumeric(left)) {
return left;
}

if (node.parent.type === "BinaryExpression") {
return getNonNumericOperand(node.parent);
}
}

/**
Expand Down
17 changes: 7 additions & 10 deletions tests/lib/rules/no-implicit-coercion.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ ruleTester.run("no-implicit-coercion", rule, {
{code: "1234 * parseInt(foo) * 1 * Number(bar)"},
{code: "1234 * parseFloat(foo) * 1 * parseInt(bar)"},
{code: "1234 * parseFloat(foo) * 1 * Number(bar)"},
{code: "1234*foo*1"},
{code: "1234*1*foo"},
{code: "1234*bar*1*foo"},
{code: "1234*1*foo*bar"},
{code: "1234*1*foo*Number(bar)"},
{code: "1234*1*Number(foo)*bar"},
{code: "1234*1*parseInt(foo)*bar"},
{code: "0 + foo"},
{code: "~foo.bar()"},

Expand All @@ -72,16 +79,6 @@ ruleTester.run("no-implicit-coercion", rule, {
{code: "+foo.bar", errors: [{message: "use `Number(foo.bar)` instead.", type: "UnaryExpression"}]},
{code: "1*foo", errors: [{message: "use `Number(foo)` instead.", type: "BinaryExpression"}]},
{code: "foo*1", errors: [{message: "use `Number(foo)` instead.", type: "BinaryExpression"}]},
{code: "1234*foo*1", errors: [{message: "use `Number(foo)` instead.", type: "BinaryExpression"}]},
{code: "1234*1*foo", errors: [{message: "use `Number(foo)` instead.", type: "BinaryExpression"}]},
{code: "1234*bar*1*foo", errors: [
{message: "use `Number(bar)` instead.", type: "BinaryExpression"},
{message: "use `Number(foo)` instead.", type: "BinaryExpression"}
]},
{code: "1234*1*foo*bar", errors: [{message: "use `Number(foo)` instead.", type: "BinaryExpression"}]},
{code: "1234*1*foo*Number(bar)", errors: [{message: "use `Number(foo)` instead.", type: "BinaryExpression"}]},
{code: "1234*1*Number(foo)*bar", errors: [{message: "use `Number(bar)` instead.", type: "BinaryExpression"}]},
{code: "1234*1*parseInt(foo)*bar", errors: [{message: "use `Number(bar)` instead.", type: "BinaryExpression"}]},
{code: "1*foo.bar", errors: [{message: "use `Number(foo.bar)` instead.", type: "BinaryExpression"}]},
{code: "\"\"+foo", errors: [{message: "use `String(foo)` instead.", type: "BinaryExpression"}]},
{code: "foo+\"\"", errors: [{message: "use `String(foo)` instead.", type: "BinaryExpression"}]},
Expand Down

0 comments on commit 287f41c

Please sign in to comment.