]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/lib/rules/key-spacing.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / rules / key-spacing.js
index 849ce61994976e90b8e0574f43f3ee892637b7bc..dd0fcbc4dcf68c43e40d654409873860ba82ed3a 100644 (file)
 const rule = require("../../../lib/rules/key-spacing"),
     { RuleTester } = require("../../../lib/rule-tester");
 
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
 const ruleTester = new RuleTester();
 
 ruleTester.run("key-spacing", rule, {
@@ -892,8 +896,82 @@ ruleTester.run("key-spacing", rule, {
                 on: "value"
             }
         }]
-    }
-    ],
+    },
+
+    // https://github.com/eslint/eslint/issues/15914
+    {
+        code: `
+            var foo = {
+                "a": "bar",
+                "𐌘": "baz"
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }]
+    },
+    {
+        code: `
+            var foo = {
+                "a": "bar",
+                "Á": "baz",
+                "o͂": "qux",
+                "mĖ…": "xyz",
+                "ř": "abc"
+
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }]
+    },
+    {
+        code: `
+            var foo = {
+                "🌷": "bar", // 2 code points
+                "🎁": "baz", // 2 code points
+                "ðŸ‡ŪðŸ‡ģ": "qux", // 4 code points
+                "ðŸģïļâ€ðŸŒˆ": "xyz", // 6 code points
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }]
+    },
+    {
+        code: `
+            const foo = {
+                "a": "bar",
+                [𐌘]: "baz"
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }],
+        parserOptions: { ecmaVersion: 6 }
+    },
+    {
+        code: `
+            const foo = {
+                "abc": "bar",
+                [ ðŒ˜ ]: "baz"
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }],
+        parserOptions: { ecmaVersion: 6 }
+    }],
     invalid: [{
         code: "var a ={'key' : value };",
         output: "var a ={'key':value };",
@@ -2199,5 +2277,103 @@ ruleTester.run("key-spacing", rule, {
             { messageId: "missingValue", data: { computed: "", key: "bar" }, line: 3, column: 12, type: "Literal" },
             { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 3, column: 20, type: "Literal" }
         ]
-    }]
+    },
+    {
+        code: `
+            const foo = {
+                "a": "bar",
+                [ ðŒ˜ ]: "baz"
+            };
+        `,
+        output: `
+            const foo = {
+                "a":   "bar",
+                [ ðŒ˜ ]: "baz"
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }],
+        parserOptions: { ecmaVersion: 6 },
+        errors: [
+            { messageId: "missingValue", data: { computed: "", key: "a" }, line: 3, column: 22, type: "Literal" }
+        ]
+    },
+    {
+        code: `
+            const foo = {
+                "a": "bar",
+                [ ðŒ˜ ]: "baz"
+            };
+        `,
+        output: `
+            const foo = {
+                "a"  : "bar",
+                [ ðŒ˜ ]: "baz"
+            };
+        `,
+        options: [{
+            align: {
+                on: "colon"
+            }
+        }],
+        parserOptions: { ecmaVersion: 6 },
+        errors: [
+            { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 17, type: "Literal" }
+        ]
+    },
+    {
+        code: `
+            const foo = {
+                "a":  "bar",
+                "𐌘": "baz"
+            };
+        `,
+        output: `
+            const foo = {
+                "a": "bar",
+                "𐌘": "baz"
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }],
+        parserOptions: { ecmaVersion: 6 },
+        errors: [
+            { messageId: "extraValue", data: { computed: "", key: "a" }, line: 3, column: 20, type: "Literal" }
+        ]
+    },
+    {
+        code: `
+            var foo = {
+                "🌷":     "bar", // 2 code points
+                "🎁":     "baz", // 2 code points
+                "ðŸ‡ŪðŸ‡ģ":   "qux", // 4 code points
+                "ðŸģïļâ€ðŸŒˆ": "xyz", // 6 code points
+            };
+        `,
+        output: `
+            var foo = {
+                "🌷": "bar", // 2 code points
+                "🎁": "baz", // 2 code points
+                "ðŸ‡ŪðŸ‡ģ": "qux", // 4 code points
+                "ðŸģïļâ€ðŸŒˆ": "xyz", // 6 code points
+            };
+        `,
+        options: [{
+            align: {
+                on: "value"
+            }
+        }],
+        errors: [
+            { messageId: "extraValue", data: { computed: "", key: "🌷" }, line: 3, column: 21, type: "Literal" },
+            { messageId: "extraValue", data: { computed: "", key: "🎁" }, line: 4, column: 21, type: "Literal" },
+            { messageId: "extraValue", data: { computed: "", key: "ðŸ‡ŪðŸ‡ģ" }, line: 5, column: 23, type: "Literal" }
+        ]
+    }
+    ]
 });