From ae080df3e7c38e22ddb47699f71bd2bbca3d822e Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Mar 2022 20:13:28 +0800 Subject: [PATCH] Enable `unicorn/template-indent` rule (#12469) --- .eslintrc.js | 1 + scripts/release/utils.js | 4 +- tests/config/install-prettier.js | 11 ++-- tests/config/utils/check-parsers.js | 12 ++-- tests/format/js/cursor/jsfmt.spec.js | 22 ++++--- .../__tests__/__snapshots__/format.js.snap | 11 ++-- tests/integration/__tests__/doc-trim.js | 15 +++-- tests/integration/__tests__/format.js | 15 ++--- .../__tests__/ignore-in-subdirectories.js | 3 +- .../__tests__/line-suffix-boundary.js | 13 ++-- tests/integration/__tests__/load-toml.js | 25 ++++---- tests/integration/__tests__/stdin-filepath.js | 61 ++++++++++--------- .../__tests__/with-parser-inference.js | 33 +++++----- 13 files changed, 122 insertions(+), 104 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 45ea57473..3cd5adc21 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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: [ { diff --git a/scripts/release/utils.js b/scripts/release/utils.js index 27910ab3a..3a47125db 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -103,9 +103,9 @@ function getBlogPostInfo(version) { function getChangelogContent({ version, previousVersion, body }) { return outdent` - [diff](https://github.com/prettier/prettier/compare/${previousVersion}...${version}) + [diff](https://github.com/prettier/prettier/compare/${previousVersion}...${version}) - ${body} + ${body} `; } diff --git a/tests/config/install-prettier.js b/tests/config/install-prettier.js index 2f62f50c9..eb6dbd45b 100644 --- a/tests/config/install-prettier.js +++ b/tests/config/install-prettier.js @@ -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)}. ` -Prettier installed - at ${chalk.inverse(installed)} - from ${chalk.inverse(packageDir)} - with ${chalk.inverse(client)}. - `.trim() ) ); diff --git a/tests/config/utils/check-parsers.js b/tests/config/utils/check-parsers.js index 8234ebe10..a0d88f02a 100644 --- a/tests/config/utils/check-parsers.js +++ b/tests/config/utils/check-parsers.js @@ -163,13 +163,13 @@ const checkParser = ({ dirname, files }, parsers = []) => { suggestCategories.length === 0 ? "" : outdent` - Suggest move your tests to: - ${suggestCategories - .map((category) => `- ${path.join(TESTS_ROOT, category)}`) - .join("\n")} + Suggest move your tests to: + ${suggestCategories + .map((category) => `- ${path.join(TESTS_ROOT, category)}`) + .join("\n")} - Or config to allow use this parser in "${__filename}". - `; + Or config to allow use this parser in "${__filename}". + `; throw new Error( `Parser "${parser}" should not used in "${dirname}".${ diff --git a/tests/format/js/cursor/jsfmt.spec.js b/tests/format/js/cursor/jsfmt.spec.js index 841828427..499d7e225 100644 --- a/tests/format/js/cursor/jsfmt.spec.js +++ b/tests/format/js/cursor/jsfmt.spec.js @@ -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 = ` -foo('bar', cb => { - console.log('stuff') -})`; + const code = + "\n" + + outdent` + foo('bar', cb => { + console.log('stuff') + }) + `; expect( prettier.formatWithCursor(code, { parser: "babel", cursorOffset: 24 }) ).toMatchObject({ - formatted: `foo("bar", (cb) => { - console.log("stuff"); -}); -`, + formatted: + outdent` + foo("bar", (cb) => { + console.log("stuff"); + }); + ` + "\n", cursorOffset: 25, }); }); diff --git a/tests/integration/__tests__/__snapshots__/format.js.snap b/tests/integration/__tests__/__snapshots__/format.js.snap index b4365a670..40cafac78 100644 --- a/tests/integration/__tests__/__snapshots__/format.js.snap +++ b/tests/integration/__tests__/__snapshots__/format.js.snap @@ -12,12 +12,11 @@ exports[`html parser should handle CRLF correctly 1`] = `"\\"