const rule = require("../../../lib/rules/key-spacing"),
{ RuleTester } = require("../../../lib/rule-tester");
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
const ruleTester = new RuleTester();
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 };",
{ 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" }
+ ]
+ }
+ ]
});