Skip to content

Commit

Permalink
Revert "Revert features for minor (#11016)"
Browse files Browse the repository at this point in the history
This reverts commit 09d65c3.
  • Loading branch information
fisker authored and sosukesuzuki committed Aug 31, 2021
1 parent 6dd2788 commit c0f42dd
Show file tree
Hide file tree
Showing 5 changed files with 20 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.
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 c0f42dd

Please sign in to comment.