Skip to content

Commit 1cd4d9c

Browse files
authored
Fix JSONC filenames list (#15947)
1 parent 6c6a332 commit 1cd4d9c

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

changelog_unreleased/json/15947.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#### Fix incorrect parser inference (#15947 by @fisker)
2+
3+
Files like `.eslintrc.json` were incorrectly formatted as JSONC files.
4+
5+
<!-- prettier-ignore -->
6+
```jsx
7+
// Input
8+
prettier --file-info .eslintrc.json
9+
{ "ignored": false, "inferredParser": "jsonc" }
10+
11+
// Prettier main
12+
prettier --file-info .eslintrc.json
13+
{ "ignored": false, "inferredParser": "json" }
14+
```

cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"jscodeshift",
157157
"jsesc",
158158
"jsfmt",
159+
"jslintrc",
159160
"jsonata",
160161
"judgements",
161162
"kalmanb",

src/language-json/languages.evaluate.js

+16
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,26 @@ const languages = [
1414
parsers: ["json"],
1515
vscodeLanguageIds: ["json"],
1616
extensions: data.extensions.filter((extension) => extension !== ".jsonl"),
17+
filenames: [
18+
...data.filenames,
19+
".babelrc",
20+
".jscsrc",
21+
".jshintrc",
22+
".jslintrc",
23+
".swcrc",
24+
],
1725
})),
1826
createLanguage(linguistLanguages["JSON with Comments"], () => ({
1927
parsers: ["jsonc"],
2028
vscodeLanguageIds: ["jsonc"],
29+
// Too many filenames from `linguist-languages` are not a valid JSONC files.
30+
// https://github.com/prettier/prettier/issues/15945#issuecomment-1895371835
31+
filenames: [
32+
"devcontainer.json",
33+
"jsconfig.json",
34+
"language-configuration.json",
35+
"tsconfig.json",
36+
],
2137
})),
2238
createLanguage(linguistLanguages.JSON5, () => ({
2339
parsers: ["json5"],

tests/integration/__tests__/__snapshots__/support-info.js.snap

+7-11
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,12 @@ exports[`CLI --support-info (stdout) 1`] = `
488488
"Pipfile.lock",
489489
"composer.lock",
490490
"flake.lock",
491-
"mcmod.info"
491+
"mcmod.info",
492+
".babelrc",
493+
".jscsrc",
494+
".jshintrc",
495+
".jslintrc",
496+
".swcrc"
492497
],
493498
"linguistLanguageId": 174,
494499
"name": "JSON",
@@ -522,19 +527,10 @@ exports[`CLI --support-info (stdout) 1`] = `
522527
".sublime_session"
523528
],
524529
"filenames": [
525-
".babelrc",
526-
".devcontainer.json",
527-
".eslintrc.json",
528-
".jscsrc",
529-
".jshintrc",
530-
".jslintrc",
531-
".swcrc",
532-
"api-extractor.json",
533530
"devcontainer.json",
534531
"jsconfig.json",
535532
"language-configuration.json",
536-
"tsconfig.json",
537-
"tslint.json"
533+
"tsconfig.json"
538534
],
539535
"group": "JSON",
540536
"linguistLanguageId": 423,

tests/integration/__tests__/with-parser-inference.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ describe("infers parser from filename", () => {
6666
{
6767
"jsc": {
6868
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
69-
"keepClassNames": false,
70-
},
69+
"keepClassNames": false
70+
}
7171
}
7272
` + "\n",
7373
);

0 commit comments

Comments
 (0)