]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/keyword-spacing.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / lib / rules / keyword-spacing.js
index 64ee5a434742edd0837d4e8619785776b9b7ca31..35c8a06e43e6590667a29b0d9f6d0ee5fbade5da 100644 (file)
@@ -11,7 +11,8 @@
 
 const parser = require("../../fixtures/fixture-parser"),
     rule = require("../../../lib/rules/keyword-spacing"),
-    { RuleTester } = require("../../../lib/rule-tester");
+    { RuleTester } = require("../../../lib/rule-tester"),
+    fixtureParser = require("../../fixtures/fixture-parser");
 
 //------------------------------------------------------------------------------
 // Helpers
@@ -259,6 +260,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         { code: "async function wrap() { a =await a }", parserOptions: { ecmaVersion: 8 } },
         { code: "async function wrap() { a = await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } },
+        { code: "async function wrap() { a+await a }", parserOptions: { ecmaVersion: 8 } },
+        { code: "async function wrap() { a + await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } },
+        { code: "async function wrap() { a<await a }", parserOptions: { ecmaVersion: 8 } },
+        { code: "async function wrap() { a < await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } },
+        { code: "async function wrap() { a>await a }", parserOptions: { ecmaVersion: 8 } },
+        { code: "async function wrap() { a > await a }", options: [NEITHER], parserOptions: { ecmaVersion: 8 } },
 
         // not conflict with `space-unary-ops`
         { code: "async function wrap() { !await'a' }", parserOptions: { ecmaVersion: 8 } },
@@ -366,6 +373,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         { code: "a =class {}", parserOptions: { ecmaVersion: 6 } },
         { code: "a = class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "a+class {}", parserOptions: { ecmaVersion: 6 } },
+        { code: "a + class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "a<class {}", parserOptions: { ecmaVersion: 6 } },
+        { code: "a < class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "a>class {}", parserOptions: { ecmaVersion: 6 } },
+        { code: "a > class{}", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
 
         // not conflict with `space-unary-ops`
         { code: "!class {}", parserOptions: { ecmaVersion: 6 } },
@@ -379,6 +392,10 @@ ruleTester.run("keyword-spacing", rule, {
         { code: "<Foo onClick={class {}} />", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },
         { code: "<Foo onClick={ class{}} />", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },
 
+        // private names
+        { code: "class C {\n#x;\nfoo() {\nfor (this.#x of bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class C {\n#x;\nfoo() {\nfor (this.#x in bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },
+
         //----------------------------------------------------------------------
         // const
         //----------------------------------------------------------------------
@@ -497,6 +514,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         "a =delete foo.a",
         { code: "a = delete foo.a", options: [NEITHER] },
+        "a+delete foo.a",
+        { code: "a + delete foo.a", options: [NEITHER] },
+        "a<delete foo.a",
+        { code: "a < delete foo.a", options: [NEITHER] },
+        "a>delete foo.a",
+        { code: "a > delete foo.a", options: [NEITHER] },
 
         // not conflict with `space-unary-ops`
         "!delete(foo.a)",
@@ -694,6 +717,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         "a =function() {}",
         { code: "a = function() {}", options: [NEITHER] },
+        "a+function() {}",
+        { code: "a + function() {}", options: [NEITHER] },
+        "a<function() {}",
+        { code: "a < function() {}", options: [NEITHER] },
+        "a>function() {}",
+        { code: "a > function() {}", options: [NEITHER] },
 
         // not conflict with `space-unary-ops`
         "!function() {}",
@@ -721,11 +750,17 @@ ruleTester.run("keyword-spacing", rule, {
         { code: "class A { a() {} get [b]() {} }", options: [override("get", BOTH)], parserOptions: { ecmaVersion: 6 } },
         { code: "({ get[b]() {} })", options: [override("get", NEITHER)], parserOptions: { ecmaVersion: 6 } },
         { code: "class A { a() {}get[b]() {} }", options: [override("get", NEITHER)], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A { a; get #b() {} }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a;get#b() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
 
         // not conflict with `comma-spacing`
         { code: "({ a,get [b]() {} })", parserOptions: { ecmaVersion: 6 } },
         { code: "({ a, get[b]() {} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
 
+        // not conflict with `semi-spacing`
+        { code: "class A { ;get #b() {} }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { ; get#b() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
+
         //----------------------------------------------------------------------
         // if
         //----------------------------------------------------------------------
@@ -850,6 +885,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         "a =new foo()",
         { code: "a = new foo()", options: [NEITHER] },
+        "a+new foo()",
+        { code: "a + new foo()", options: [NEITHER] },
+        "a<new foo()",
+        { code: "a < new foo()", options: [NEITHER] },
+        "a>new foo()",
+        { code: "a > new foo()", options: [NEITHER] },
 
         // not conflict with `space-unary-ops`
         "!new(foo)()",
@@ -878,7 +919,16 @@ ruleTester.run("keyword-spacing", rule, {
         //----------------------------------------------------------------------
 
         "function foo() { {} return +a }",
+        {
+            code: "function foo() { return <p/>; }",
+            parserOptions: { ecmaFeatures: { jsx: true } }
+        },
         { code: "function foo() { {}return+a }", options: [NEITHER] },
+        {
+            code: "function foo() { return<p/>; }",
+            options: [{ after: false }],
+            parserOptions: { ecmaFeatures: { jsx: true } }
+        },
         { code: "function foo() { {} return +a }", options: [override("return", BOTH)] },
         { code: "function foo() { {}return+a }", options: [override("return", NEITHER)] },
         "function foo() {\nreturn\n}",
@@ -905,11 +955,17 @@ ruleTester.run("keyword-spacing", rule, {
         { code: "class A { a() {} set [b](value) {} }", options: [override("set", BOTH)], parserOptions: { ecmaVersion: 6 } },
         { code: "({ set[b](value) {} })", options: [override("set", NEITHER)], parserOptions: { ecmaVersion: 6 } },
         { code: "class A { a() {}set[b](value) {} }", options: [override("set", NEITHER)], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A { a; set #b(value) {} }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a;set#b(value) {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
 
         // not conflict with `comma-spacing`
         { code: "({ a,set [b](value) {} })", parserOptions: { ecmaVersion: 6 } },
         { code: "({ a, set[b](value) {} })", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
 
+        // not conflict with `semi-spacing`
+        { code: "class A { ;set #b(value) {} }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { ; set#b(value) {} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
+
         //----------------------------------------------------------------------
         // static
         //----------------------------------------------------------------------
@@ -918,6 +974,15 @@ ruleTester.run("keyword-spacing", rule, {
         { code: "class A { a() {}static[b]() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
         { code: "class A { a() {} static [b]() {} }", options: [override("static", BOTH)], parserOptions: { ecmaVersion: 6 } },
         { code: "class A { a() {}static[b]() {} }", options: [override("static", NEITHER)], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A { a; static [b]; }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a;static[b]; }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a; static #b; }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a;static#b; }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a() {} static {} }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a() {}static{} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a() {} static {} }", options: [override("static", BOTH)], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a() {}static{} }", options: [override("static", NEITHER)], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { a() {}\nstatic\n{} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
 
         // not conflict with `generator-star-spacing`
         { code: "class A { static* [a]() {} }", parserOptions: { ecmaVersion: 6 } },
@@ -926,6 +991,10 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `semi-spacing`
         { code: "class A { ;static a() {} }", parserOptions: { ecmaVersion: 6 } },
         { code: "class A { ; static a() {} }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A { ;static a; }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { ; static a ; }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { ;static {} }", parserOptions: { ecmaVersion: 2022 } },
+        { code: "class A { ; static{} }", options: [NEITHER], parserOptions: { ecmaVersion: 2022 } },
 
         //----------------------------------------------------------------------
         // super
@@ -975,6 +1044,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         { code: "class A extends B { constructor() { b =super() } }", parserOptions: { ecmaVersion: 6 } },
         { code: "class A extends B { constructor() { b = super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A extends B { constructor() { b+super() } }", parserOptions: { ecmaVersion: 6 } },
+        { code: "class A extends B { constructor() { b + super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A extends B { constructor() { b<super() } }", parserOptions: { ecmaVersion: 6 } },
+        { code: "class A extends B { constructor() { b < super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
+        { code: "class A extends B { constructor() { b>super() } }", parserOptions: { ecmaVersion: 6 } },
+        { code: "class A extends B { constructor() { b > super() } }", options: [NEITHER], parserOptions: { ecmaVersion: 6 } },
 
         // not conflict with `space-unary-ops`
         { code: "class A extends B { constructor() { !super() } }", parserOptions: { ecmaVersion: 6 } },
@@ -1014,6 +1089,16 @@ ruleTester.run("keyword-spacing", rule, {
         { code: "{} this[a]", options: [override("this", BOTH)] },
         { code: "{}this[a]", options: [override("this", NEITHER)] },
 
+        {
+            code: "<Thing> this.blah",
+            parser: fixtureParser("keyword-spacing", "prefix-cast-operator-space")
+        },
+        {
+            code: "<Thing>this.blah",
+            options: [override("this", { before: false })],
+            parser: fixtureParser("keyword-spacing", "prefix-cast-operator-no-space")
+        },
+
         // not conflict with `array-bracket-spacing`
         "[this]",
         { code: "[ this ]", options: [NEITHER] },
@@ -1051,6 +1136,18 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         "a =this",
         { code: "a = this", options: [NEITHER] },
+        "a+this",
+        { code: "a + this", options: [NEITHER] },
+        "a<this",
+        { code: "a < this", options: [NEITHER] },
+        "a>this",
+        { code: "a > this", options: [NEITHER] },
+        "this+a",
+        { code: "this + a", options: [NEITHER] },
+        "this<a",
+        { code: "this < a", options: [NEITHER] },
+        "this>a",
+        { code: "this > a", options: [NEITHER] },
 
         // not conflict with `space-unary-ops`
         "!this",
@@ -1146,6 +1243,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         "a =typeof foo",
         { code: "a = typeof foo", options: [NEITHER] },
+        "a+typeof foo",
+        { code: "a + typeof foo", options: [NEITHER] },
+        "a<typeof foo",
+        { code: "a < typeof foo", options: [NEITHER] },
+        "a>typeof foo",
+        { code: "a > typeof foo", options: [NEITHER] },
 
         // not conflict with `space-unary-ops`
         "!typeof+foo",
@@ -1223,6 +1326,12 @@ ruleTester.run("keyword-spacing", rule, {
         // not conflict with `space-infix-ops`
         "a =void foo",
         { code: "a = void foo", options: [NEITHER] },
+        "a+void foo",
+        { code: "a + void foo", options: [NEITHER] },
+        "a<void foo",
+        { code: "a < void foo", options: [NEITHER] },
+        "a>void foo",
+        { code: "a > void foo", options: [NEITHER] },
 
         // not conflict with `space-unary-ops`
         "!void+foo",
@@ -2453,6 +2562,19 @@ ruleTester.run("keyword-spacing", rule, {
             parserOptions: { ecmaVersion: 6 },
             errors: unexpectedBeforeAndAfter("get")
         },
+        {
+            code: "class A { a;get#b() {} }",
+            output: "class A { a;get #b() {} }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedAfter("get")
+        },
+        {
+            code: "class A { a; get #b() {} }",
+            output: "class A { a; get#b() {} }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedAfter("get")
+        },
 
         //----------------------------------------------------------------------
         // if
@@ -2750,12 +2872,25 @@ ruleTester.run("keyword-spacing", rule, {
             output: "function foo() { {} return +a }",
             errors: expectedBeforeAndAfter("return")
         },
+        {
+            code: "function foo() { return<p/>; }",
+            output: "function foo() { return <p/>; }",
+            parserOptions: { ecmaFeatures: { jsx: true } },
+            errors: expectedAfter("return")
+        },
         {
             code: "function foo() { {} return +a }",
             output: "function foo() { {}return+a }",
             options: [NEITHER],
             errors: unexpectedBeforeAndAfter("return")
         },
+        {
+            code: "function foo() { return <p/>; }",
+            output: "function foo() { return<p/>; }",
+            options: [{ after: false }],
+            parserOptions: { ecmaFeatures: { jsx: true } },
+            errors: unexpectedAfter("return")
+        },
         {
             code: "function foo() { {}return+a }",
             output: "function foo() { {} return +a }",
@@ -2833,6 +2968,19 @@ ruleTester.run("keyword-spacing", rule, {
             parserOptions: { ecmaVersion: 6 },
             errors: unexpectedBeforeAndAfter("set")
         },
+        {
+            code: "class A { a;set#b(x) {} }",
+            output: "class A { a;set #b(x) {} }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedAfter("set")
+        },
+        {
+            code: "class A { a; set #b(x) {} }",
+            output: "class A { a; set#b(x) {} }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedAfter("set")
+        },
 
         //----------------------------------------------------------------------
         // static
@@ -2878,6 +3026,85 @@ ruleTester.run("keyword-spacing", rule, {
             parserOptions: { ecmaVersion: 6 },
             errors: unexpectedBeforeAndAfter("static")
         },
+        {
+            code: "class A { a;static[b]; }",
+            output: "class A { a;static [b]; }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedAfter("static")
+        },
+        {
+            code: "class A { a; static [b]; }",
+            output: "class A { a; static[b]; }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedAfter("static")
+        },
+        {
+            code: "class A { a;static#b; }",
+            output: "class A { a;static #b; }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedAfter("static")
+        },
+        {
+            code: "class A { a; static #b; }",
+            output: "class A { a; static#b; }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedAfter("static")
+        },
+        {
+            code: "class A { a() {}static{} }",
+            output: "class A { a() {} static {} }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedBeforeAndAfter("static")
+        },
+        {
+            code: "class A { a() {}static{} }",
+            output: "class A { a() {} static {} }",
+            options: [override("static", BOTH)],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedBeforeAndAfter("static")
+        },
+        {
+            code: "class A {  a() {}static {} }",
+            output: "class A {  a() {} static {} }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedBefore("static")
+        },
+        {
+            code: "class A {  a() {} static{} }",
+            output: "class A {  a() {} static {} }",
+            parserOptions: { ecmaVersion: 2022 },
+            errors: expectedAfter("static")
+        },
+        {
+            code: "class A { a() {} static {} }",
+            output: "class A { a() {}static{} }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedBeforeAndAfter("static")
+        },
+        {
+            code: "class A { a() {} static {} }",
+            output: "class A { a() {}static{} }",
+            options: [override("static", NEITHER)],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedBeforeAndAfter("static")
+        },
+        {
+            code: "class A { a() {} static{} }",
+            output: "class A { a() {}static{} }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedBefore("static")
+        },
+        {
+            code: "class A { a() {}static {} }",
+            output: "class A { a() {}static{} }",
+            options: [NEITHER],
+            parserOptions: { ecmaVersion: 2022 },
+            errors: unexpectedAfter("static")
+        },
 
         //----------------------------------------------------------------------
         // super
@@ -2966,6 +3193,19 @@ ruleTester.run("keyword-spacing", rule, {
             options: [override("this", NEITHER)],
             errors: unexpectedBefore("this")
         },
+        {
+            code: "<Thing> this.blah",
+            output: "<Thing>this.blah",
+            options: [override("this", { before: false })],
+            parser: fixtureParser("keyword-spacing", "prefix-cast-operator-space"),
+            errors: unexpectedBefore("this")
+        },
+        {
+            code: "<Thing>this.blah",
+            output: "<Thing> this.blah",
+            parser: fixtureParser("keyword-spacing", "prefix-cast-operator-no-space"),
+            errors: expectedBefore("this")
+        },
 
         //----------------------------------------------------------------------
         // throw