2022-03-17 21:32:14 +08:00
|
|
|
import { outdent } from "outdent";
|
2022-07-20 23:18:24 +08:00
|
|
|
import prettier from "../../config/prettier-entry.js";
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("infers postcss parser", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({
|
2017-10-02 11:08:34 -05:00
|
|
|
status: 0,
|
|
|
|
|
});
|
2017-06-06 17:24:56 +02:00
|
|
|
});
|
|
|
|
|
|
2018-12-19 14:03:30 +00:00
|
|
|
describe("infers postcss parser with --check", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli("cli/with-parser-inference", ["--check", "*"]).test({
|
2018-12-19 14:03:30 +00:00
|
|
|
status: 0,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-02 11:08:34 -05:00
|
|
|
describe("infers postcss parser with --list-different", () => {
|
2023-04-11 08:44:23 +08:00
|
|
|
runCli("cli/with-parser-inference", ["--list-different", "*"]).test({
|
2017-10-02 11:08:34 -05:00
|
|
|
status: 0,
|
|
|
|
|
});
|
2017-06-06 17:24:56 +02:00
|
|
|
});
|
2017-11-03 18:06:25 +11:00
|
|
|
|
|
|
|
|
describe("infers parser from filename", () => {
|
2022-04-29 14:22:24 +08:00
|
|
|
test("json from .prettierrc", async () => {
|
2021-08-31 12:40:52 +08:00
|
|
|
expect(
|
2022-04-29 14:22:24 +08:00
|
|
|
await prettier.format(" { } ", { filepath: "x/y/.prettierrc" }),
|
|
|
|
|
).toBe("{}\n");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("json from .stylelintrc", async () => {
|
|
|
|
|
expect(
|
|
|
|
|
await prettier.format(" { } ", { filepath: "x/y/.stylelintrc" }),
|
|
|
|
|
).toBe("{}\n");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("yaml from .stylelintrc", async () => {
|
|
|
|
|
expect(
|
|
|
|
|
await prettier.format(" extends: '' ", {
|
|
|
|
|
filepath: "x/y/.stylelintrc",
|
|
|
|
|
}),
|
2021-10-04 07:46:38 +09:00
|
|
|
).toBe('extends: ""\n');
|
2021-08-31 12:40:52 +08:00
|
|
|
});
|
|
|
|
|
|
2022-04-29 14:22:24 +08:00
|
|
|
test("babel from Jakefile", async () => {
|
2017-11-03 18:06:25 +11:00
|
|
|
expect(
|
2022-04-29 14:22:24 +08:00
|
|
|
await prettier.format("let foo = ( x = 1 ) => x", {
|
|
|
|
|
filepath: "x/y/Jakefile",
|
|
|
|
|
}),
|
2021-10-04 07:46:38 +09:00
|
|
|
).toBe("let foo = (x = 1) => x;\n");
|
2017-11-03 18:06:25 +11:00
|
|
|
});
|
2022-02-18 08:39:12 +09:00
|
|
|
|
2022-04-29 14:22:24 +08:00
|
|
|
test("json from .swcrc", async () => {
|
2022-02-18 08:39:12 +09:00
|
|
|
expect(
|
2022-04-29 14:22:24 +08:00
|
|
|
await prettier.format(
|
2022-03-17 20:13:28 +08:00
|
|
|
/* indent */ `
|
|
|
|
|
{
|
|
|
|
|
"jsc": {
|
|
|
|
|
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
|
|
|
|
|
"keepClassNames": false
|
|
|
|
|
}}
|
|
|
|
|
`,
|
2022-02-18 08:39:12 +09:00
|
|
|
{ filepath: "/path/to/.swcrc" },
|
|
|
|
|
),
|
2022-03-17 20:13:28 +08:00
|
|
|
).toBe(
|
|
|
|
|
outdent`
|
|
|
|
|
{
|
|
|
|
|
"jsc": {
|
|
|
|
|
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
|
2024-01-17 18:02:25 +08:00
|
|
|
"keepClassNames": false
|
|
|
|
|
}
|
2022-03-17 20:13:28 +08:00
|
|
|
}
|
|
|
|
|
` + "\n",
|
|
|
|
|
);
|
2022-02-18 08:39:12 +09:00
|
|
|
});
|
2022-07-09 00:30:26 -04:00
|
|
|
|
2022-07-11 17:32:09 +08:00
|
|
|
test("json from .lintstagedrc", async () => {
|
2022-07-09 00:30:26 -04:00
|
|
|
expect(
|
2022-07-11 17:32:09 +08:00
|
|
|
await prettier.format(" { '*': 'your-cmd' } ", {
|
2022-07-09 00:30:26 -04:00
|
|
|
filepath: "/path/to/.lintstagedrc",
|
|
|
|
|
}),
|
|
|
|
|
).toBe('{ "*": "your-cmd" }\n');
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-11 17:32:09 +08:00
|
|
|
test("yaml from .lintstagedrc", async () => {
|
2022-07-09 00:30:26 -04:00
|
|
|
expect(
|
2022-07-11 17:32:09 +08:00
|
|
|
await prettier.format(
|
2022-07-09 00:30:26 -04:00
|
|
|
/* indent */ `
|
|
|
|
|
'*':
|
|
|
|
|
- your-cmd
|
|
|
|
|
`,
|
|
|
|
|
{ filepath: "/path/to/.lintstagedrc" },
|
|
|
|
|
),
|
|
|
|
|
).toBe(
|
|
|
|
|
outdent`
|
|
|
|
|
"*":
|
|
|
|
|
- your-cmd
|
|
|
|
|
` + "\n",
|
|
|
|
|
);
|
|
|
|
|
});
|
2017-11-03 18:06:25 +11:00
|
|
|
});
|