mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
160 lines
2.6 KiB
JavaScript
160 lines
2.6 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/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']; } }",
|
|
languageOptions: { ecmaVersion: 2022 },
|
|
},
|
|
{
|
|
code: "class C { #field; foo() { this['#field'] === this.#field; } }",
|
|
languageOptions: { ecmaVersion: 2022 },
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
code: "if (x === x) { }",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "if (x !== x) { }",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "if (x > x) { }",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "if ('x' > 'x') { }",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "do {} while (x === x)",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x === x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x !== x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x == x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x != x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x > x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x < x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x >= x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "x <= x",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "foo.bar().baz.qux >= foo.bar ().baz .qux",
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "class C { #field; foo() { this.#field === this.#field; } }",
|
|
languageOptions: { ecmaVersion: 2022 },
|
|
errors: [
|
|
{
|
|
messageId: "comparingToSelf",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|