pve-eslint/eslint/tests/lib/rules/no-self-compare.js
Thomas Lamprecht 609c276fc2 import 8.3.0 source
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-12-01 13:39:06 +01:00

58 lines
2.7 KiB
JavaScript

/**
* @fileoverview Tests for no-self-compare rule.
* @author Ilya Volodin
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-self-compare"),
{ RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("no-self-compare", rule, {
valid: [
"if (x === y) { }",
"if (1 === 2) { }",
"y=x*x",
"foo.bar.baz === foo.bar.qux",
{
code: "class C { #field; foo() { this.#field === this['#field']; } }",
parserOptions: { ecmaVersion: 2022 }
},
{
code: "class C { #field; foo() { this['#field'] === this.#field; } }",
parserOptions: { ecmaVersion: 2022 }
}
],
invalid: [
{ code: "if (x === x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "if (x !== x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "if (x > x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "if ('x' > 'x') { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "do {} while (x === x)", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x === x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x !== x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x == x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x != x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x > x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x < x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x >= x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "x <= x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{ code: "foo.bar().baz.qux >= foo.bar ().baz .qux", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
{
code: "class C { #field; foo() { this.#field === this.#field; } }",
parserOptions: { ecmaVersion: 2022 },
errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }]
}
]
});