Skip to content

Commit

Permalink
Fix JSONC filenames list (#15947)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Jan 17, 2024
1 parent 6c6a332 commit 1cd4d9c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
14 changes: 14 additions & 0 deletions changelog_unreleased/json/15947.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#### Fix incorrect parser inference (#15947 by @fisker)

Files like `.eslintrc.json` were incorrectly formatted as JSONC files.

<!-- prettier-ignore -->
```jsx
// Input
prettier --file-info .eslintrc.json
{ "ignored": false, "inferredParser": "jsonc" }

// Prettier main
prettier --file-info .eslintrc.json
{ "ignored": false, "inferredParser": "json" }
```
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"jscodeshift",
"jsesc",
"jsfmt",
"jslintrc",
"jsonata",
"judgements",
"kalmanb",
Expand Down
16 changes: 16 additions & 0 deletions src/language-json/languages.evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ const languages = [
parsers: ["json"],
vscodeLanguageIds: ["json"],
extensions: data.extensions.filter((extension) => extension !== ".jsonl"),
filenames: [
...data.filenames,
".babelrc",
".jscsrc",
".jshintrc",
".jslintrc",
".swcrc",
],
})),
createLanguage(linguistLanguages["JSON with Comments"], () => ({
parsers: ["jsonc"],
vscodeLanguageIds: ["jsonc"],
// Too many filenames from `linguist-languages` are not a valid JSONC files.
// https://github.com/prettier/prettier/issues/15945#issuecomment-1895371835
filenames: [
"devcontainer.json",
"jsconfig.json",
"language-configuration.json",
"tsconfig.json",
],
})),
createLanguage(linguistLanguages.JSON5, () => ({
parsers: ["json5"],
Expand Down
18 changes: 7 additions & 11 deletions tests/integration/__tests__/__snapshots__/support-info.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,12 @@ exports[`CLI --support-info (stdout) 1`] = `
"Pipfile.lock",
"composer.lock",
"flake.lock",
"mcmod.info"
"mcmod.info",
".babelrc",
".jscsrc",
".jshintrc",
".jslintrc",
".swcrc"
],
"linguistLanguageId": 174,
"name": "JSON",
Expand Down Expand Up @@ -522,19 +527,10 @@ exports[`CLI --support-info (stdout) 1`] = `
".sublime_session"
],
"filenames": [
".babelrc",
".devcontainer.json",
".eslintrc.json",
".jscsrc",
".jshintrc",
".jslintrc",
".swcrc",
"api-extractor.json",
"devcontainer.json",
"jsconfig.json",
"language-configuration.json",
"tsconfig.json",
"tslint.json"
"tsconfig.json"
],
"group": "JSON",
"linguistLanguageId": 423,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/__tests__/with-parser-inference.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ describe("infers parser from filename", () => {
{
"jsc": {
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false,
},
"keepClassNames": false
}
}
` + "\n",
);
Expand Down

0 comments on commit 1cd4d9c

Please sign in to comment.