Skip to content

Commit

Permalink
Fix JSONC filenames list (prettier#15947)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and medikoo committed Feb 18, 2024
1 parent 20a2cc2 commit 2eb5ac0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ exports[`CLI --support-info (stdout) 1`] = `
".all-contributorsrc", ".arcconfig", ".auto-changelog", ".c8rc",
".htmlhintrc", ".imgbotconfig", ".nycrc", ".tern-config",
".tern-project", ".watchmanconfig", "Pipfile.lock", "composer.lock",
"flake.lock", "mcmod.info"
"flake.lock", "mcmod.info", ".babelrc", ".jscsrc", ".jshintrc",
".jslintrc", ".swcrc"
],
"linguistLanguageId": 174,
"name": "JSON",
Expand All @@ -436,10 +437,8 @@ exports[`CLI --support-info (stdout) 1`] = `
".sublime-workspace", ".sublime_metrics", ".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 2eb5ac0

Please sign in to comment.