mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-08-18 05:36:38 +00:00
58 lines
2.7 KiB
JavaScript
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" }]
|
|
}
|
|
]
|
|
});
|