diff --git a/changelog_unreleased/cli/12320.md b/changelog_unreleased/cli/12320.md new file mode 100644 index 000000000..3ba65e968 --- /dev/null +++ b/changelog_unreleased/cli/12320.md @@ -0,0 +1,3 @@ +#### Infer parser for `.swcrc` (#12320 by @sosukesuzuki) + +A [`.swcrc`](https://swc.rs/docs/configuration/swcrc) is handled using `json` parser. diff --git a/cspell.json b/cspell.json index dc0c23ca4..f5714c9a7 100644 --- a/cspell.json +++ b/cspell.json @@ -310,6 +310,7 @@ "suchipi", "supertypes", "Supprimer", + "swcrc", "templating", "tempy", "testname", diff --git a/src/language-js/index.js b/src/language-js/index.js index 407b49a6f..d19c29033 100644 --- a/src/language-js/index.js +++ b/src/language-js/index.js @@ -102,7 +102,7 @@ const languages = [ since: "1.5.0", parsers: ["json"], vscodeLanguageIds: ["jsonc"], - filenames: [...data.filenames, ".eslintrc"], + filenames: [...data.filenames, ".eslintrc", ".swcrc"], }) ), createLanguage(require("linguist-languages/data/JSON5.json"), () => ({ diff --git a/tests/integration/__tests__/__snapshots__/support-info.js.snap b/tests/integration/__tests__/__snapshots__/support-info.js.snap index b2b59cf5e..abf30a7b9 100644 --- a/tests/integration/__tests__/__snapshots__/support-info.js.snap +++ b/tests/integration/__tests__/__snapshots__/support-info.js.snap @@ -512,7 +512,8 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"language-configuration.json\\", \\"tsconfig.json\\", \\"tslint.json\\", - \\".eslintrc\\" + \\".eslintrc\\", + \\".swcrc\\" ], \\"group\\": \\"JSON\\", \\"linguistLanguageId\\": 423, diff --git a/tests/integration/__tests__/with-parser-inference.js b/tests/integration/__tests__/with-parser-inference.js index 3dd4fc913..3e7bb779c 100644 --- a/tests/integration/__tests__/with-parser-inference.js +++ b/tests/integration/__tests__/with-parser-inference.js @@ -45,4 +45,26 @@ describe("infers parser from filename", () => { prettier.format("let foo = ( x = 1 ) => x", { filepath: "x/y/Jakefile" }) ).toBe("let foo = (x = 1) => x;\n"); }); + + test("json from .swcrc", () => { + expect( + prettier.format( + ` + { + "jsc": { + // Requires v1.2.50 or upper and requires target to be es2016 or upper. + "keepClassNames": false + } + } + `, + { filepath: "/path/to/.swcrc" } + ) + ).toBe(`{ + "jsc": { + // Requires v1.2.50 or upper and requires target to be es2016 or upper. + "keepClassNames": false + } +} +`); + }); });