Skip to content

Commit

Permalink
Chore: fixed false negative and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed Mar 23, 2020
1 parent 9953a04 commit 03cdf0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rules/yoda.js
Expand Up @@ -235,7 +235,7 @@ module.exports = {
function isBetweenTest() {
let leftLiteral, rightLiteral;

if (node.operator === "&&") {
if (node.operator === "&&" && same(left.right, right.left)) {
leftLiteral = getNormalizedLiteral(left.left);
rightLiteral = getNormalizedLiteral(right.right);

Expand All @@ -247,7 +247,7 @@ module.exports = {
return true;
}

if (leftLiteral.value <= rightLiteral.value && same(left.right, right.left)) {
if (leftLiteral.value <= rightLiteral.value) {
return true;
}
}
Expand All @@ -261,7 +261,7 @@ module.exports = {
function isOutsideTest() {
let leftLiteral, rightLiteral;

if (node.operator === "||") {
if (node.operator === "||" && same(left.left, right.right)) {
leftLiteral = getNormalizedLiteral(left.right);
rightLiteral = getNormalizedLiteral(right.left);

Expand All @@ -273,7 +273,7 @@ module.exports = {
return true;
}

if ((leftLiteral.value <= rightLiteral.value) && same(left.left, right.right)) {
if ((leftLiteral.value <= rightLiteral.value)) {
return true;
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/yoda.js
Expand Up @@ -1094,6 +1094,18 @@ ruleTester.run("yoda", rule, {
type: "BinaryExpression"
}
]
},
{
code: "if (0 < a && b < max) {}",
output: "if (a > 0 && b < max) {}",
options: ["never", { exceptRange: true }],
errors: [
{
messageId: "expected",
data: { expectedSide: "right", operator: "<" },
type: "BinaryExpression"
}
]
}

]
Expand Down

0 comments on commit 03cdf0d

Please sign in to comment.