Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSONC filenames list #15947

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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