Skip to content

Commit f8cb785

Browse files
SevenOutmanfisker
andauthored
Support stylelintrc (#10924)
* Infer JSON/YAML parser for .stylelintrc * Update test snapshots * Update src/language-yaml/embed.js Co-authored-by: fisker Cheung <[email protected]> * Add changelog for stylelintrc support * Update embed.js * style: Fix prettier linting problems Co-authored-by: fisker Cheung <[email protected]>
1 parent 261bb03 commit f8cb785

5 files changed

Lines changed: 20 additions & 3 deletions

File tree

changelog_unreleased/cli/10924.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### Infer parser for `.stylelintrc` (#10924 by @SevenOutman)
2+
3+
A `.stylelintrc` file (without extension) is handled using `json` and `yaml` parsers.

src/language-yaml/embed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
function embed(path, print, textToDoc, options) {
44
const node = path.getValue();
55

6-
// Try to format `.prettierrc` as `json` first
6+
// Try to format `.prettierrc` and `.stylelintrc` as `json` first
77
if (
88
node.type === "root" &&
99
options.filepath &&
10-
/(?:[/\\]|^)\.prettierrc$/.test(options.filepath)
10+
/(?:[/\\]|^)\.(?:prettier|stylelint)rc$/.test(options.filepath)
1111
) {
1212
return textToDoc(options.originalText, { ...options, parser: "json" });
1313
}

src/language-yaml/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const languages = [
1313
filenames: [
1414
...data.filenames.filter((filename) => filename !== "yarn.lock"),
1515
".prettierrc",
16+
".stylelintrc",
1617
],
1718
})),
1819
];

tests/integration/__tests__/__snapshots__/support-info.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ exports[`CLI --support-info (stdout) 1`] = `
740740
\\".clang-tidy\\",
741741
\\".gemrc\\",
742742
\\"glide.lock\\",
743-
\\".prettierrc\\"
743+
\\".prettierrc\\",
744+
\\".stylelintrc\\"
744745
],
745746
\\"linguistLanguageId\\": 407,
746747
\\"name\\": \\"YAML\\",

tests/integration/__tests__/with-parser-inference.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ describe("infers parser from filename", () => {
2828
).toEqual("{}\n");
2929
});
3030

31+
test("json from .stylelintrc", () => {
32+
expect(
33+
prettier.format(" { } ", { filepath: "x/y/.stylelintrc" })
34+
).toEqual("{}\n");
35+
});
36+
37+
test("yaml from .stylelintrc", () => {
38+
expect(
39+
prettier.format(" extends: '' ", { filepath: "x/y/.stylelintrc" })
40+
).toEqual('extends: ""\n');
41+
});
42+
3143
test("babel from Jakefile", () => {
3244
expect(
3345
prettier.format("let foo = ( x = 1 ) => x", { filepath: "x/y/Jakefile" })

0 commit comments

Comments
 (0)