Enable unicorn/template-indent rule (#12469)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-03-17 20:13:28 +08:00
1 parent 361dc14f06
commit ae080df3e7
11 files changed
+61 -43

No files matched your search

+1
View File
@@ -153,6 +153,7 @@ module.exports = {
"unicorn/prefer-string-starts-ends-with": "error",
"unicorn/prefer-switch": "error",
"unicorn/prefer-type-error": "error",
"unicorn/template-indent": "error",
},
overrides: [
{
+3 -2
View File
@@ -2,6 +2,7 @@
const path = require("path");
const fs = require("fs");
const { outdent } = require("outdent");
const { default: chalk } = require("../../vendors/chalk.js");
const { default: tempy } = require("../../vendors/tempy.js");
const { execaSync } = require("../../vendors/execa.js");
@@ -74,12 +75,12 @@ module.exports = (packageDir) => {
console.log(
chalk.green(
`
outdent`
Prettier installed
at ${chalk.inverse(installed)}
from ${chalk.inverse(packageDir)}
with ${chalk.inverse(client)}.
`.trim()
`
)
);
+10 -4
View File
@@ -1,6 +1,7 @@
run_spec(__dirname, ["babel", "typescript", "flow"]);
const prettier = require("prettier-local");
const { outdent } = require("outdent");
test("translates cursor correctly in basic case", () => {
expect(
@@ -32,17 +33,22 @@ test("keeps cursor inside formatted node", () => {
});
test("doesn't insert second placeholder for nonexistent TypeAnnotation", () => {
const code = `
const code =
"\n" +
outdent`
foo('bar', cb => {
console.log('stuff')
})`;
})
`;
expect(
prettier.formatWithCursor(code, { parser: "babel", cursorOffset: 24 })
).toMatchObject({
formatted: `foo("bar", (cb) => {
formatted:
outdent`
foo("bar", (cb) => {
console.log("stuff");
});
`,
` + "\n",
cursorOffset: 25,
});
});
@@ -12,12 +12,11 @@ exports[`html parser should handle CRLF correctly 1`] = `"\\"<!--\\\\r\\\\n tes
exports[`markdown parser should handle CRLF correctly 1`] = `"\\"\`\`\`\\\\r\\\\n\\\\r\\\\n\\\\r\\\\n\`\`\`\\\\r\\\\n\\""`;
exports[`typescript parser should throw the first error when both JSX and non-JSX mode failed 1`] = `
"Expression expected. (9:7)
7 | );
8 |
> 9 | label:
| ^
10 | "
"Expression expected. (8:7)
6 | );
7 |
> 8 | label:
| ^"
`;
exports[`yaml parser should handle CRLF correctly 1`] = `"\\"a: 123\\\\r\\\\n\\""`;
+5 -2
View File
@@ -1,6 +1,7 @@
"use strict";
const prettier = require("prettier-local");
const { outdent } = require("outdent");
const docPrinter = prettier.doc.printer;
const docBuilders = prettier.doc.builders;
@@ -34,12 +35,14 @@ describe("trim", () => {
"}",
])
),
`function()
outdent`
function()
{
#if DEBUG
alert(42);
#endif
}`,
}
`,
],
[
"ignores trimmed characters when fitting the line",
+2 -1
View File
@@ -1,6 +1,7 @@
"use strict";
const prettier = require("prettier-local");
const { outdent } = require("outdent");
const fooPlugin = require("../plugins/defaultOptions/plugin.js");
test("yaml parser should handle CRLF correctly", () => {
@@ -14,7 +15,7 @@ test("yaml parser should handle CRLF correctly", () => {
});
test("typescript parser should throw the first error when both JSX and non-JSX mode failed", () => {
const input = `
const input = outdent`
import React from "react";
const App = () => (
@@ -70,8 +70,7 @@ describe("formats files when executing in a subdirectory and using stdin", () =>
input: "hello_world( );",
}
).test({
stdout: `hello_world();
`,
stdout: "hello_world();\n",
status: 0,
});
});
@@ -2,6 +2,7 @@
/** @type {import('prettier')} */
const prettier = require("prettier-local");
const { outdent } = require("outdent");
const { group, indent, line, lineSuffix, lineSuffixBoundary, softline } =
prettier.doc.builders;
@@ -24,11 +25,13 @@ describe("lineSuffixBoundary", () => {
"];",
]);
const expected = `let foo = [
const expected = outdent`
let foo = [
item1,
item2, // comment
item3
];`;
];
`;
expect(printDoc(doc)).toBe(expected);
});
+2 -1
View File
@@ -1,11 +1,12 @@
"use strict";
const { outdent } = require("outdent");
const loadToml = require("../../../src/utils/load-toml.js");
describe("TOML", () => {
const exampleFilePath = "example.toml";
const exampleToml = `
const exampleToml = outdent`
# This is a TOML document.
title = "TOML Example"
[owner]
+13 -12
View File
@@ -1,6 +1,7 @@
"use strict";
const { isCI } = require("ci-info");
const { outdent } = require("outdent");
const runPrettier = require("../run-prettier.js");
describe("format correctly if stdin content compatible with stdin-filepath", () => {
@@ -38,11 +39,11 @@ describe("apply editorconfig for stdin-filepath with nonexistent file", () => {
"cli",
["--stdin-filepath", "config/editorconfig/nonexistent.js"],
{
input: `
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`.trim(), // js
`, // js
}
).test({
status: 0,
@@ -54,11 +55,11 @@ describe("apply editorconfig for stdin-filepath with nonexistent directory", ()
"cli",
["--stdin-filepath", "config/editorconfig/nonexistent/one/two/three.js"],
{
input: `
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`.trim(), // js
`, // js
}
).test({
status: 0,
@@ -70,11 +71,11 @@ describe("apply editorconfig for stdin-filepath with a deep path", () => {
"cli",
["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"],
{
input: `
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`.trim(), // js
`, // js
}
).test({
status: 0,
@@ -83,11 +84,11 @@ function f() {
if (isCI) {
describe("apply editorconfig for stdin-filepath in root", () => {
const code = `
const code = outdent`
function f() {
console.log("should be indented with a tab");
}
`.trim();
`;
runPrettier("cli", ["--stdin-filepath", "/foo.js"], {
input: code, // js
}).test({
@@ -104,11 +105,11 @@ describe("apply editorconfig for stdin-filepath with a deep path", () => {
"cli",
["--stdin-filepath", "config/editorconfig/" + "a/".repeat(30) + "three.js"],
{
input: `
input: outdent`
function f() {
console.log("should be indented with a tab");
}
`.trim(), // js
`, // js
}
).test({
status: 0,
@@ -123,11 +124,11 @@ describe("don’t apply editorconfig outside project for stdin-filepath with non
"config/editorconfig/repo-root/nonexistent/one/two/three.js",
],
{
input: `
input: outdent`
function f() {
console.log("should be indented with 2 spaces");
}
`.trim(), // js
`, // js
}
).test({
status: 0,
@@ -1,6 +1,7 @@
"use strict";
const prettier = require("prettier-local");
const { outdent } = require("outdent");
const runPrettier = require("../run-prettier.js");
describe("infers postcss parser", () => {
@@ -49,22 +50,24 @@ describe("infers parser from filename", () => {
test("json from .swcrc", () => {
expect(
prettier.format(
`
/* indent */ `
{
"jsc": {
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
}}
`,
{ filepath: "/path/to/.swcrc" }
)
).toBe(
outdent`
{
"jsc": {
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
}
}
`,
{ filepath: "/path/to/.swcrc" }
)
).toBe(`{
"jsc": {
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
}
}
`);
` + "\n"
);
});
});