Skip to content

Commit ae080df

Browse files
authored
Enable unicorn/template-indent rule (#12469)
1 parent 361dc14 commit ae080df

13 files changed

Lines changed: 122 additions & 104 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ module.exports = {
153153
"unicorn/prefer-string-starts-ends-with": "error",
154154
"unicorn/prefer-switch": "error",
155155
"unicorn/prefer-type-error": "error",
156+
"unicorn/template-indent": "error",
156157
},
157158
overrides: [
158159
{

scripts/release/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ function getBlogPostInfo(version) {
103103

104104
function getChangelogContent({ version, previousVersion, body }) {
105105
return outdent`
106-
[diff](https://github.com/prettier/prettier/compare/${previousVersion}...${version})
106+
[diff](https://github.com/prettier/prettier/compare/${previousVersion}...${version})
107107
108-
${body}
108+
${body}
109109
`;
110110
}
111111

tests/config/install-prettier.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const path = require("path");
44
const fs = require("fs");
5+
const { outdent } = require("outdent");
56
const { default: chalk } = require("../../vendors/chalk.js");
67
const { default: tempy } = require("../../vendors/tempy.js");
78
const { execaSync } = require("../../vendors/execa.js");
@@ -74,12 +75,12 @@ module.exports = (packageDir) => {
7475

7576
console.log(
7677
chalk.green(
78+
outdent`
79+
Prettier installed
80+
at ${chalk.inverse(installed)}
81+
from ${chalk.inverse(packageDir)}
82+
with ${chalk.inverse(client)}.
7783
`
78-
Prettier installed
79-
at ${chalk.inverse(installed)}
80-
from ${chalk.inverse(packageDir)}
81-
with ${chalk.inverse(client)}.
82-
`.trim()
8384
)
8485
);
8586

tests/config/utils/check-parsers.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ const checkParser = ({ dirname, files }, parsers = []) => {
163163
suggestCategories.length === 0
164164
? ""
165165
: outdent`
166-
Suggest move your tests to:
167-
${suggestCategories
168-
.map((category) => `- ${path.join(TESTS_ROOT, category)}`)
169-
.join("\n")}
166+
Suggest move your tests to:
167+
${suggestCategories
168+
.map((category) => `- ${path.join(TESTS_ROOT, category)}`)
169+
.join("\n")}
170170
171-
Or config to allow use this parser in "${__filename}".
172-
`;
171+
Or config to allow use this parser in "${__filename}".
172+
`;
173173

174174
throw new Error(
175175
`Parser "${parser}" should not used in "${dirname}".${

tests/format/js/cursor/jsfmt.spec.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
run_spec(__dirname, ["babel", "typescript", "flow"]);
22

33
const prettier = require("prettier-local");
4+
const { outdent } = require("outdent");
45

56
test("translates cursor correctly in basic case", () => {
67
expect(
@@ -32,17 +33,22 @@ test("keeps cursor inside formatted node", () => {
3233
});
3334

3435
test("doesn't insert second placeholder for nonexistent TypeAnnotation", () => {
35-
const code = `
36-
foo('bar', cb => {
37-
console.log('stuff')
38-
})`;
36+
const code =
37+
"\n" +
38+
outdent`
39+
foo('bar', cb => {
40+
console.log('stuff')
41+
})
42+
`;
3943
expect(
4044
prettier.formatWithCursor(code, { parser: "babel", cursorOffset: 24 })
4145
).toMatchObject({
42-
formatted: `foo("bar", (cb) => {
43-
console.log("stuff");
44-
});
45-
`,
46+
formatted:
47+
outdent`
48+
foo("bar", (cb) => {
49+
console.log("stuff");
50+
});
51+
` + "\n",
4652
cursorOffset: 25,
4753
});
4854
});

tests/integration/__tests__/__snapshots__/format.js.snap

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ exports[`html parser should handle CRLF correctly 1`] = `"\\"<!--\\\\r\\\\n tes
1212
exports[`markdown parser should handle CRLF correctly 1`] = `"\\"\`\`\`\\\\r\\\\n\\\\r\\\\n\\\\r\\\\n\`\`\`\\\\r\\\\n\\""`;
1313

1414
exports[`typescript parser should throw the first error when both JSX and non-JSX mode failed 1`] = `
15-
"Expression expected. (9:7)
16-
7 | );
17-
8 |
18-
> 9 | label:
19-
| ^
20-
10 | "
15+
"Expression expected. (8:7)
16+
6 | );
17+
7 |
18+
> 8 | label:
19+
| ^"
2120
`;
2221

2322
exports[`yaml parser should handle CRLF correctly 1`] = `"\\"a: 123\\\\r\\\\n\\""`;

tests/integration/__tests__/doc-trim.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const prettier = require("prettier-local");
4+
const { outdent } = require("outdent");
45
const docPrinter = prettier.doc.printer;
56
const docBuilders = prettier.doc.builders;
67

@@ -34,12 +35,14 @@ describe("trim", () => {
3435
"}",
3536
])
3637
),
37-
`function()
38-
{
39-
#if DEBUG
40-
alert(42);
41-
#endif
42-
}`,
38+
outdent`
39+
function()
40+
{
41+
#if DEBUG
42+
alert(42);
43+
#endif
44+
}
45+
`,
4346
],
4447
[
4548
"ignores trimmed characters when fitting the line",

tests/integration/__tests__/format.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const prettier = require("prettier-local");
4+
const { outdent } = require("outdent");
45
const fooPlugin = require("../plugins/defaultOptions/plugin.js");
56

67
test("yaml parser should handle CRLF correctly", () => {
@@ -14,15 +15,15 @@ test("yaml parser should handle CRLF correctly", () => {
1415
});
1516

1617
test("typescript parser should throw the first error when both JSX and non-JSX mode failed", () => {
17-
const input = `
18-
import React from "react";
18+
const input = outdent`
19+
import React from "react";
1920
20-
const App = () => (
21-
<div className="App">
22-
</div>
23-
);
21+
const App = () => (
22+
<div className="App">
23+
</div>
24+
);
2425
25-
label:
26+
label:
2627
`;
2728
expect(() =>
2829
prettier.format(input, { parser: "typescript" })

tests/integration/__tests__/ignore-in-subdirectories.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ describe("formats files when executing in a subdirectory and using stdin", () =>
7070
input: "hello_world( );",
7171
}
7272
).test({
73-
stdout: `hello_world();
74-
`,
73+
stdout: "hello_world();\n",
7574
status: 0,
7675
});
7776
});

tests/integration/__tests__/line-suffix-boundary.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/** @type {import('prettier')} */
44
const prettier = require("prettier-local");
5+
const { outdent } = require("outdent");
56

67
const { group, indent, line, lineSuffix, lineSuffixBoundary, softline } =
78
prettier.doc.builders;
@@ -24,11 +25,13 @@ describe("lineSuffixBoundary", () => {
2425
"];",
2526
]);
2627

27-
const expected = `let foo = [
28-
item1,
29-
item2, // comment
30-
item3
31-
];`;
28+
const expected = outdent`
29+
let foo = [
30+
item1,
31+
item2, // comment
32+
item3
33+
];
34+
`;
3235

3336
expect(printDoc(doc)).toBe(expected);
3437
});

0 commit comments

Comments
 (0)