A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/eslint/eslint/commit/92bf49a4b39dde728fbc6d348e62c7009e21cf7d below:

improve the key width calculation in `key-spacing` rule (#16154) ยท eslint/eslint@92bf49a ยท GitHub

File tree Expand file treeCollapse file tree 3 files changed

+180

-4

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+180

-4

lines changed Original file line number Diff line number Diff line change

@@ -9,6 +9,9 @@

9 9

//------------------------------------------------------------------------------

10 10 11 11

const astUtils = require("./utils/ast-utils");

12 +

const GraphemeSplitter = require("grapheme-splitter");

13 + 14 +

const splitter = new GraphemeSplitter();

12 15 13 16

//------------------------------------------------------------------------------

14 17

// Helpers

@@ -508,7 +511,7 @@ module.exports = {

508 511

const startToken = sourceCode.getFirstToken(property);

509 512

const endToken = getLastTokenBeforeColon(property.key);

510 513 511 -

return endToken.range[1] - startToken.range[0];

514 +

return splitter.countGraphemes(sourceCode.getText().slice(startToken.range[0], endToken.range[1]));

512 515

}

513 516 514 517

/**

Original file line number Diff line number Diff line change

@@ -73,6 +73,7 @@

73 73

"functional-red-black-tree": "^1.0.1",

74 74

"glob-parent": "^6.0.1",

75 75

"globals": "^13.15.0",

76 +

"grapheme-splitter": "^1.0.4",

76 77

"ignore": "^5.2.0",

77 78

"import-fresh": "^3.0.0",

78 79

"imurmurhash": "^0.1.4",

Original file line number Diff line number Diff line change

@@ -896,8 +896,82 @@ ruleTester.run("key-spacing", rule, {

896 896

on: "value"

897 897

}

898 898

}]

899 -

}

900 -

],

899 +

},

900 + 901 +

// https://github.com/eslint/eslint/issues/15914

902 +

{

903 +

code: `

904 +

var foo = {

905 +

"a": "bar",

906 +

"๐Œ˜": "baz"

907 +

};

908 +

`,

909 +

options: [{

910 +

align: {

911 +

on: "value"

912 +

}

913 +

}]

914 +

},

915 +

{

916 +

code: `

917 +

var foo = {

918 +

"a": "bar",

919 +

"ร": "baz",

920 +

"oอ‚": "qux",

921 +

"mฬ…": "xyz",

922 +

"ล™": "abc"

923 + 924 +

};

925 +

`,

926 +

options: [{

927 +

align: {

928 +

on: "value"

929 +

}

930 +

}]

931 +

},

932 +

{

933 +

code: `

934 +

var foo = {

935 +

"๐ŸŒท": "bar", // 2 code points

936 +

"๐ŸŽ": "baz", // 2 code points

937 +

"๐Ÿ‡ฎ๐Ÿ‡ณ": "qux", // 4 code points

938 +

"๐Ÿณ๏ธโ€๐ŸŒˆ": "xyz", // 6 code points

939 +

};

940 +

`,

941 +

options: [{

942 +

align: {

943 +

on: "value"

944 +

}

945 +

}]

946 +

},

947 +

{

948 +

code: `

949 +

const foo = {

950 +

"a": "bar",

951 +

[๐Œ˜]: "baz"

952 +

};

953 +

`,

954 +

options: [{

955 +

align: {

956 +

on: "value"

957 +

}

958 +

}],

959 +

parserOptions: { ecmaVersion: 6 }

960 +

},

961 +

{

962 +

code: `

963 +

const foo = {

964 +

"abc": "bar",

965 +

[ ๐Œ˜ ]: "baz"

966 +

};

967 +

`,

968 +

options: [{

969 +

align: {

970 +

on: "value"

971 +

}

972 +

}],

973 +

parserOptions: { ecmaVersion: 6 }

974 +

}],

901 975

invalid: [{

902 976

code: "var a ={'key' : value };",

903 977

output: "var a ={'key':value };",

@@ -2203,5 +2277,103 @@ ruleTester.run("key-spacing", rule, {

2203 2277

{ messageId: "missingValue", data: { computed: "", key: "bar" }, line: 3, column: 12, type: "Literal" },

2204 2278

{ messageId: "missingValue", data: { computed: "", key: "baz" }, line: 3, column: 20, type: "Literal" }

2205 2279

]

2206 -

}]

2280 +

},

2281 +

{

2282 +

code: `

2283 +

const foo = {

2284 +

"a": "bar",

2285 +

[ ๐Œ˜ ]: "baz"

2286 +

};

2287 +

`,

2288 +

output: `

2289 +

const foo = {

2290 +

"a": "bar",

2291 +

[ ๐Œ˜ ]: "baz"

2292 +

};

2293 +

`,

2294 +

options: [{

2295 +

align: {

2296 +

on: "value"

2297 +

}

2298 +

}],

2299 +

parserOptions: { ecmaVersion: 6 },

2300 +

errors: [

2301 +

{ messageId: "missingValue", data: { computed: "", key: "a" }, line: 3, column: 22, type: "Literal" }

2302 +

]

2303 +

},

2304 +

{

2305 +

code: `

2306 +

const foo = {

2307 +

"a": "bar",

2308 +

[ ๐Œ˜ ]: "baz"

2309 +

};

2310 +

`,

2311 +

output: `

2312 +

const foo = {

2313 +

"a" : "bar",

2314 +

[ ๐Œ˜ ]: "baz"

2315 +

};

2316 +

`,

2317 +

options: [{

2318 +

align: {

2319 +

on: "colon"

2320 +

}

2321 +

}],

2322 +

parserOptions: { ecmaVersion: 6 },

2323 +

errors: [

2324 +

{ messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 17, type: "Literal" }

2325 +

]

2326 +

},

2327 +

{

2328 +

code: `

2329 +

const foo = {

2330 +

"a": "bar",

2331 +

"๐Œ˜": "baz"

2332 +

};

2333 +

`,

2334 +

output: `

2335 +

const foo = {

2336 +

"a": "bar",

2337 +

"๐Œ˜": "baz"

2338 +

};

2339 +

`,

2340 +

options: [{

2341 +

align: {

2342 +

on: "value"

2343 +

}

2344 +

}],

2345 +

parserOptions: { ecmaVersion: 6 },

2346 +

errors: [

2347 +

{ messageId: "extraValue", data: { computed: "", key: "a" }, line: 3, column: 20, type: "Literal" }

2348 +

]

2349 +

},

2350 +

{

2351 +

code: `

2352 +

var foo = {

2353 +

"๐ŸŒท": "bar", // 2 code points

2354 +

"๐ŸŽ": "baz", // 2 code points

2355 +

"๐Ÿ‡ฎ๐Ÿ‡ณ": "qux", // 4 code points

2356 +

"๐Ÿณ๏ธโ€๐ŸŒˆ": "xyz", // 6 code points

2357 +

};

2358 +

`,

2359 +

output: `

2360 +

var foo = {

2361 +

"๐ŸŒท": "bar", // 2 code points

2362 +

"๐ŸŽ": "baz", // 2 code points

2363 +

"๐Ÿ‡ฎ๐Ÿ‡ณ": "qux", // 4 code points

2364 +

"๐Ÿณ๏ธโ€๐ŸŒˆ": "xyz", // 6 code points

2365 +

};

2366 +

`,

2367 +

options: [{

2368 +

align: {

2369 +

on: "value"

2370 +

}

2371 +

}],

2372 +

errors: [

2373 +

{ messageId: "extraValue", data: { computed: "", key: "๐ŸŒท" }, line: 3, column: 21, type: "Literal" },

2374 +

{ messageId: "extraValue", data: { computed: "", key: "๐ŸŽ" }, line: 4, column: 21, type: "Literal" },

2375 +

{ messageId: "extraValue", data: { computed: "", key: "๐Ÿ‡ฎ๐Ÿ‡ณ" }, line: 5, column: 23, type: "Literal" }

2376 +

]

2377 +

}

2378 +

]

2207 2379

});

You canโ€™t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4