Skip to content

Commit

Permalink
Revert "Revert features for minor" (#11044)
Browse files Browse the repository at this point in the history
* Revert "Revert features for minor (#11016)"

This reverts commit 09d65c3.

* Update cspell.json

Co-authored-by: sosukesuzuki <aosukeke@gmail.com>
  • Loading branch information
fisker and sosukesuzuki committed Aug 31, 2021
1 parent 4992d97 commit 07786bd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions 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.
1 change: 1 addition & 0 deletions cspell.json
Expand Up @@ -308,6 +308,7 @@
"stylefmt",
"styleguides",
"stylelint",
"stylelintrc",
"Stylesheet",
"subvalue",
"suchipi",
Expand Down
4 changes: 2 additions & 2 deletions src/language-yaml/embed.js
Expand Up @@ -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" });
}
Expand Down
1 change: 1 addition & 0 deletions src/language-yaml/index.js
Expand Up @@ -14,6 +14,7 @@ const languages = [
filenames: [
...data.filenames.filter((filename) => filename !== "yarn.lock"),
".prettierrc",
".stylelintrc",
],
})),
];
Expand Down
Expand Up @@ -743,7 +743,8 @@ exports[`CLI --support-info (stdout) 1`] = `
\\".clang-tidy\\",
\\".gemrc\\",
\\"glide.lock\\",
\\".prettierrc\\"
\\".prettierrc\\",
\\".stylelintrc\\"
],
\\"linguistLanguageId\\": 407,
\\"name\\": \\"YAML\\",
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/__tests__/with-parser-inference.js
Expand Up @@ -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" })
Expand Down

0 comments on commit 07786bd

Please sign in to comment.