From 01b597dfa8f7c904154accc130e9ef2cc4d9a2b4 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 11 Jun 2021 11:05:28 +0800 Subject: [PATCH 1/2] Revert "Revert features for minor (#11016)" This reverts commit 09d65c35af4810e975c34d85377793eec260059f. --- changelog_unreleased/cli/10924.md | 3 +++ src/language-yaml/embed.js | 4 ++-- src/language-yaml/index.js | 1 + .../__tests__/__snapshots__/support-info.js.snap | 3 ++- tests/integration/__tests__/with-parser-inference.js | 12 ++++++++++++ 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelog_unreleased/cli/10924.md diff --git a/changelog_unreleased/cli/10924.md b/changelog_unreleased/cli/10924.md new file mode 100644 index 000000000000..22486a31d107 --- /dev/null +++ b/changelog_unreleased/cli/10924.md @@ -0,0 +1,3 @@ +#### Infer parser for `.stylelintrc` (#10924 by @SevenOutman) + +A `.stylelintrc` file (without extension) is handled using `json` and `yaml` parsers. diff --git a/src/language-yaml/embed.js b/src/language-yaml/embed.js index cf246b8e02d8..cc3e0722c67d 100644 --- a/src/language-yaml/embed.js +++ b/src/language-yaml/embed.js @@ -3,11 +3,11 @@ function embed(path, print, textToDoc, options) { const node = path.getValue(); - // Try to format `.prettierrc` as `json` first + // Try to format `.prettierrc` and `.stylelintrc` as `json` first if ( node.type === "root" && options.filepath && - /(?:[/\\]|^)\.prettierrc$/.test(options.filepath) + /(?:[/\\]|^)\.(?:prettier|stylelint)rc$/.test(options.filepath) ) { return textToDoc(options.originalText, { ...options, parser: "json" }); } diff --git a/src/language-yaml/index.js b/src/language-yaml/index.js index f406e04e57a3..600ed41939eb 100644 --- a/src/language-yaml/index.js +++ b/src/language-yaml/index.js @@ -14,6 +14,7 @@ const languages = [ filenames: [ ...data.filenames.filter((filename) => filename !== "yarn.lock"), ".prettierrc", + ".stylelintrc", ], })), ]; diff --git a/tests/integration/__tests__/__snapshots__/support-info.js.snap b/tests/integration/__tests__/__snapshots__/support-info.js.snap index 08a061feef0f..6296347e54af 100644 --- a/tests/integration/__tests__/__snapshots__/support-info.js.snap +++ b/tests/integration/__tests__/__snapshots__/support-info.js.snap @@ -743,7 +743,8 @@ exports[`CLI --support-info (stdout) 1`] = ` \\".clang-tidy\\", \\".gemrc\\", \\"glide.lock\\", - \\".prettierrc\\" + \\".prettierrc\\", + \\".stylelintrc\\" ], \\"linguistLanguageId\\": 407, \\"name\\": \\"YAML\\", diff --git a/tests/integration/__tests__/with-parser-inference.js b/tests/integration/__tests__/with-parser-inference.js index 4e0c0cb3f732..ad200e6a883f 100644 --- a/tests/integration/__tests__/with-parser-inference.js +++ b/tests/integration/__tests__/with-parser-inference.js @@ -28,6 +28,18 @@ describe("infers parser from filename", () => { ).toEqual("{}\n"); }); + test("json from .stylelintrc", () => { + expect( + prettier.format(" { } ", { filepath: "x/y/.stylelintrc" }) + ).toEqual("{}\n"); + }); + + test("yaml from .stylelintrc", () => { + expect( + prettier.format(" extends: '' ", { filepath: "x/y/.stylelintrc" }) + ).toEqual('extends: ""\n'); + }); + test("babel from Jakefile", () => { expect( prettier.format("let foo = ( x = 1 ) => x", { filepath: "x/y/Jakefile" }) From ebb039cbebe3c41bd883c7ac8fca7a2ff2a00057 Mon Sep 17 00:00:00 2001 From: sosukesuzuki Date: Tue, 31 Aug 2021 10:51:00 +0900 Subject: [PATCH 2/2] Update cspell.json --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 2d617833f2e7..29f9fe29fff8 100644 --- a/cspell.json +++ b/cspell.json @@ -308,6 +308,7 @@ "stylefmt", "styleguides", "stylelint", + "stylelintrc", "Stylesheet", "subvalue", "suchipi",