Support .lintstagedrc (#13081)

* Test `.lintstagedrc` JSON and YML formatting (TDD)

* Support `.lintstagedrc` formatting

* Update spell checking for `.lintstagedrc`

* Update changelog

* Update changelog
This commit is contained in:
Or Rosenblatt authored and GitHub committed 2022-07-09 13:30:26 +09:00
1 parent a043ac0d73
commit a00d31e1a4
6 files changed
+35 -3

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
#### Infer parser for `.lintstagedrc` (#13081 by @OrRosenblatt)
A `.lintstagedrc` file (without extension) is handled using `json` and `yaml` parsers.
+2
View File
@@ -184,6 +184,8 @@
"linearize",
"linebreak",
"linebreaks",
"lintstaged",
"lintstagedrc",
"literalline",
"loglevel",
"lowercased",
+2 -2
View File
@@ -3,11 +3,11 @@
function embed(path, print, textToDoc, options) {
const node = path.getValue();
// Try to format `.prettierrc` and `.stylelintrc` as `json` first
// Try to format `.prettierrc`, `.stylelintrc`, and `.lintstagedrc` as `json` first
if (
node.type === "root" &&
options.filepath &&
/(?:[/\\]|^)\.(?:prettier|stylelint)rc$/.test(options.filepath)
/(?:[/\\]|^)\.(?:prettier|stylelint|lintstaged)rc$/.test(options.filepath)
) {
return textToDoc(options.originalText, { ...options, parser: "json" });
}
+1
View File
@@ -15,6 +15,7 @@ const languages = [
...data.filenames.filter((filename) => filename !== "yarn.lock"),
".prettierrc",
".stylelintrc",
".lintstagedrc",
],
})),
];
@@ -774,7 +774,8 @@ exports[`CLI --support-info (stdout) 1`] = `
"CITATION.cff",
"glide.lock",
".prettierrc",
".stylelintrc"
".stylelintrc",
".lintstagedrc"
],
"linguistLanguageId": 407,
"name": "YAML",
@@ -70,4 +70,29 @@ describe("infers parser from filename", () => {
` + "\n"
);
});
test("json from .lintstagedrc", () => {
expect(
prettier.format(" { '*': 'your-cmd' } ", {
filepath: "/path/to/.lintstagedrc",
})
).toBe('{ "*": "your-cmd" }\n');
});
test("yaml from .lintstagedrc", () => {
expect(
prettier.format(
/* indent */ `
'*':
- your-cmd
`,
{ filepath: "/path/to/.lintstagedrc" }
)
).toBe(
outdent`
"*":
- your-cmd
` + "\n"
);
});
});