Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unnecessary-boolean-literal-compare] incorrec…
Browse files Browse the repository at this point in the history
…t fix when condition is reversed (#3581)
  • Loading branch information
alonstern committed Jul 31, 2021
1 parent 18e30cb commit b595575
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -186,7 +186,7 @@ export default util.createRule<Options, MessageIds>({
range:
expression.range[0] < against.range[0]
? [expression.range[1], against.range[1]]
: [against.range[1], expression.range[1]],
: [against.range[0], expression.range[0]],
};
}

Expand Down
Expand Up @@ -224,5 +224,39 @@ ruleTester.run('no-unnecessary-boolean-literal-compare', rule, {
}
`,
},
{
code: `
declare const varBoolean: boolean;
if (false !== varBoolean) {
}
`,
errors: [
{
messageId: 'negated',
},
],
output: `
declare const varBoolean: boolean;
if (varBoolean) {
}
`,
},
{
code: `
declare const varBoolean: boolean;
if (true !== varBoolean) {
}
`,
errors: [
{
messageId: 'negated',
},
],
output: `
declare const varBoolean: boolean;
if (!varBoolean) {
}
`,
},
],
});

0 comments on commit b595575

Please sign in to comment.