From 0f19075f5f0bc3ecca0c583a0be699eca157ff06 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Fri, 12 Aug 2022 03:18:55 -0500 Subject: [PATCH 1/6] Add prettier-plugin-astro to list of plugins (#13269) * Add prettier-plugin-astro to list of plugins * Order the plugin correctly alphabetically * Update creator text/link * Update cspell dictionary --- cspell.json | 2 ++ docs/plugins.md | 1 + 2 files changed, 3 insertions(+) diff --git a/cspell.json b/cspell.json index 4475099a8..c35113b9e 100644 --- a/cspell.json +++ b/cspell.json @@ -14,6 +14,7 @@ "arrayify", "Artem", "Ascher", + "astro", "atrule", "atrules", "atword", @@ -369,6 +370,7 @@ "webstorm", "Weixin", "whitespaces", + "withastro", "wxss", "xdescribe", "xtest", diff --git a/docs/plugins.md b/docs/plugins.md index 59c603ab2..c77b1126c 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -58,6 +58,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI ## Community Plugins - [`prettier-plugin-apex`](https://github.com/dangmai/prettier-plugin-apex) by [**@dangmai**](https://github.com/dangmai) +- [`prettier-plugin-astro`](https://github.com/withastro/prettier-plugin-astro) by [**@withastro contributors**](https://github.com/withastro/prettier-plugin-astro/graphs/contributors) - [`prettier-plugin-elm`](https://github.com/gicentre/prettier-plugin-elm) by [**@giCentre**](https://github.com/gicentre) - [`prettier-plugin-erb`](https://github.com/adamzapasnik/prettier-plugin-erb) by [**@adamzapasnik**](https://github.com/adamzapasnik) - [`prettier-plugin-glsl`](https://github.com/NaridaL/glsl-language-toolkit/tree/main/packages/prettier-plugin-glsl) by [**@NaridaL**](https://github.com/NaridaL) From 5910eb9204497b656594ceaaeae057a318a9fede Mon Sep 17 00:00:00 2001 From: Nikolas Date: Mon, 15 Aug 2022 12:18:37 +0200 Subject: [PATCH 2/6] Add `prettier-plugin-prisma` to list of community plugins (#13272) --- docs/plugins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins.md b/docs/plugins.md index c77b1126c..0065dbce2 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -66,6 +66,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI - [`prettier-plugin-java`](https://github.com/jhipster/prettier-java) by [**@JHipster**](https://github.com/jhipster) - [`prettier-plugin-jsonata`](https://github.com/Stedi/prettier-plugin-jsonata) by [**@Stedi**](https://github.com/Stedi) - [`prettier-plugin-kotlin`](https://github.com/Angry-Potato/prettier-plugin-kotlin) by [**@Angry-Potato**](https://github.com/Angry-Potato) +- [`prettier-plugin-prisma`](https://github.com/umidbekk/prettier-plugin-prisma) by [**@umidbekk**](https://github.com/umidbekk) - [`prettier-plugin-properties`](https://github.com/eemeli/prettier-plugin-properties) by [**@eemeli**](https://github.com/eemeli) - [`prettier-plugin-sh`](https://github.com/un-ts/prettier/tree/master/packages/sh) by [**@JounQin**](https://github.com/JounQin) - [`prettier-plugin-sql`](https://github.com/un-ts/prettier/tree/master/packages/sql) by [**@JounQin**](https://github.com/JounQin) From 2d3a2748471bf03d4bf59e3dc47f689cc984fadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pereira?= <43006560+jspereiramoura@users.noreply.github.com> Date: Wed, 17 Aug 2022 11:32:29 -0300 Subject: [PATCH 3/6] fix: extra space between '#' and '{' (#13286) * fix: extra space between '#' and '{' * Update src/language-css/printer-postcss.js Co-authored-by: fisker Cheung * adding changelog * Update 13286.md Co-authored-by: fisker Cheung --- changelog_unreleased/scss/13286.md | 13 +++++++++++++ src/language-css/printer-postcss.js | 8 ++++++++ .../scss/variables/__snapshots__/jsfmt.spec.js.snap | 2 ++ tests/format/scss/variables/variables.scss | 1 + 4 files changed, 24 insertions(+) create mode 100644 changelog_unreleased/scss/13286.md diff --git a/changelog_unreleased/scss/13286.md b/changelog_unreleased/scss/13286.md new file mode 100644 index 000000000..d64d73195 --- /dev/null +++ b/changelog_unreleased/scss/13286.md @@ -0,0 +1,13 @@ +#### fix: extra space between '#' and '{' (#13286 by @jspereiramoura) + + +```scss +// Input +padding: var(--spacer#{(1) + 2}); + +// Prettier stable +padding: var(--spacer# {(1) + 2}); + +// Prettier main +padding: var(--spacer#{(1) + 2}); +``` diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 825961ff2..744646020 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -825,6 +825,14 @@ function genericPrint(path, options, print) { continue; } + if ( + iNode.value?.endsWith("#") && + iNextNode.value === "{" && + isParenGroupNode(iNextNode.group) + ) { + continue; + } + // Be default all values go through `line` parts.push(line); } diff --git a/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap b/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap index 6f19d50c0..4312c1b47 100644 --- a/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/scss/variables/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,7 @@ printWidth: 80 prop1: var(--#{$var}); prop2: var(#{$var}, --my-#{$var}, pink); prop3: calc(var(--#{$var}) * 1px); + prop4: var(--spacer#{(1) + 2}); } @supports (--#{$prop}: green) { @@ -27,6 +28,7 @@ printWidth: 80 prop1: var(--#{$var}); prop2: var(#{$var}, --my-#{$var}, pink); prop3: calc(var(--#{$var}) * 1px); + prop4: var(--spacer#{(1) + 2}); } @supports (--#{$prop}: green) { diff --git a/tests/format/scss/variables/variables.scss b/tests/format/scss/variables/variables.scss index 35e7c6e9b..577714686 100644 --- a/tests/format/scss/variables/variables.scss +++ b/tests/format/scss/variables/variables.scss @@ -4,6 +4,7 @@ prop1: var(--#{$var}); prop2: var(#{$var}, --my-#{$var}, pink); prop3: calc(var(--#{$var}) * 1px); + prop4: var(--spacer#{(1) + 2}); } @supports (--#{$prop}: green) { From f2244bdc8621c0a001e3717f595bc8fd8653cce7 Mon Sep 17 00:00:00 2001 From: Gleb Dolzhikov Date: Wed, 17 Aug 2022 18:36:25 +0300 Subject: [PATCH 4/6] Fix parens in inferred function return types with `extends` (#13289) Co-authored-by: Gleb Dolzhikov <9276677@gmail.com> --- changelog_unreleased/typescript/13289.md | 13 +++++++++++++ src/language-js/needs-parens.js | 10 ++++++++++ .../__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ .../typescript/conditional-types/issue-13275.ts | 1 + 4 files changed, 38 insertions(+) create mode 100644 changelog_unreleased/typescript/13289.md create mode 100644 tests/format/typescript/conditional-types/issue-13275.ts diff --git a/changelog_unreleased/typescript/13289.md b/changelog_unreleased/typescript/13289.md new file mode 100644 index 000000000..7a4183c19 --- /dev/null +++ b/changelog_unreleased/typescript/13289.md @@ -0,0 +1,13 @@ +#### Fix parens in inferred function return types with `extends` (#13289 by @GlebDolzhikov) + + +```ts +// Input +type Foo = T extends (...a: any[]) => (infer R extends string) ? R : never; + +// Prettier stable +type Foo = T extends (...a: any[]) => infer R extends string ? R : never; + +// Prettier main +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; +``` diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 0695e9731..1a71011ec 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -412,6 +412,16 @@ function needsParens(path, options) { // fallthrough case "TSFunctionType": case "TSConstructorType": + if (name === "extendsType" && parent.type === "TSConditionalType") { + const returnTypeAnnotation = (node.returnType || node.typeAnnotation) + .typeAnnotation; + if ( + returnTypeAnnotation.type === "TSInferType" && + returnTypeAnnotation.typeParameter.constraint + ) { + return true; + } + } if (name === "checkType" && parent.type === "TSConditionalType") { return true; } diff --git a/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap index d109f4511..7231c3da4 100644 --- a/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/conditional-types/__snapshots__/jsfmt.spec.js.snap @@ -278,6 +278,20 @@ type Unpacked = T extends (infer U)[] ================================================================================ `; +exports[`issue-13275.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; + +=====================================output===================================== +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; + +================================================================================ +`; + exports[`nested-in-condition.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/conditional-types/issue-13275.ts b/tests/format/typescript/conditional-types/issue-13275.ts new file mode 100644 index 000000000..de1ccb285 --- /dev/null +++ b/tests/format/typescript/conditional-types/issue-13275.ts @@ -0,0 +1 @@ +type Foo = T extends ((...a: any[]) => infer R extends string) ? R : never; From a2a3849c430b31871db5e89ff1542b4d14f80f68 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 21 Aug 2022 09:48:37 +0200 Subject: [PATCH 5/6] Added `prettier-plugin-nginx` to Community Plugins list (#13320) Added [`prettier-plugin-nginx`](https://github.com/joedeandev/prettier-plugin-nginx) to Community Plugins list. --- cspell.json | 1 + docs/plugins.md | 1 + 2 files changed, 2 insertions(+) diff --git a/cspell.json b/cspell.json index c35113b9e..ed51d0e90 100644 --- a/cspell.json +++ b/cspell.json @@ -224,6 +224,7 @@ "neoclide", "neoformat", "neovim", + "nginx", "nnoremap", "nocheck", "nonenumerable", diff --git a/docs/plugins.md b/docs/plugins.md index 0065dbce2..d599cf544 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -66,6 +66,7 @@ To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI - [`prettier-plugin-java`](https://github.com/jhipster/prettier-java) by [**@JHipster**](https://github.com/jhipster) - [`prettier-plugin-jsonata`](https://github.com/Stedi/prettier-plugin-jsonata) by [**@Stedi**](https://github.com/Stedi) - [`prettier-plugin-kotlin`](https://github.com/Angry-Potato/prettier-plugin-kotlin) by [**@Angry-Potato**](https://github.com/Angry-Potato) +- [`prettier-plugin-nginx`](https://github.com/joedeandev/prettier-plugin-nginx) by [**@joedeandev**](https://github.com/joedeandev) - [`prettier-plugin-prisma`](https://github.com/umidbekk/prettier-plugin-prisma) by [**@umidbekk**](https://github.com/umidbekk) - [`prettier-plugin-properties`](https://github.com/eemeli/prettier-plugin-properties) by [**@eemeli**](https://github.com/eemeli) - [`prettier-plugin-sh`](https://github.com/un-ts/prettier/tree/master/packages/sh) by [**@JounQin**](https://github.com/JounQin) From 5a627651ff648edd38bd0b5e667210a8a1f4e4a1 Mon Sep 17 00:00:00 2001 From: Gleb Dolzhikov Date: Tue, 23 Aug 2022 15:56:52 +0300 Subject: [PATCH 6/6] fix: line breaks in multiline strings, issue 13157 (#13274) Co-authored-by: Georgii Dolzhykov Co-authored-by: Gleb Dolzhikov Co-authored-by: fisker Cheung --- changelog_unreleased/javascript/13274.md | 34 ++++++++++ src/language-js/print/flow.js | 3 +- src/language-js/print/literal.js | 5 +- .../literal/__snapshots__/jsfmt.spec.js.snap | 27 ++++++++ tests/format/flow/literal/jsfmt.spec.js | 1 + tests/format/flow/literal/multiline.js | 6 ++ .../strings/__snapshots__/jsfmt.spec.js.snap | 65 +++++++++++++++++++ tests/format/js/strings/multiline-literal.js | 9 +++ .../literal/__snapshots__/jsfmt.spec.js.snap | 25 +++++++ tests/format/typescript/literal/jsfmt.spec.js | 1 + tests/format/typescript/literal/multiline.ts | 6 ++ 11 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 changelog_unreleased/javascript/13274.md create mode 100644 tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/flow/literal/jsfmt.spec.js create mode 100644 tests/format/flow/literal/multiline.js create mode 100644 tests/format/js/strings/multiline-literal.js create mode 100644 tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/typescript/literal/jsfmt.spec.js create mode 100644 tests/format/typescript/literal/multiline.ts diff --git a/changelog_unreleased/javascript/13274.md b/changelog_unreleased/javascript/13274.md new file mode 100644 index 000000000..26466f984 --- /dev/null +++ b/changelog_unreleased/javascript/13274.md @@ -0,0 +1,34 @@ +#### Fix inconsistent formatting for multiline strings (#13274 by @GlebDolzhikov) + + +```jsx +// Input +const loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' + +// Prettier stable +const loremIpsumFooBazBar1 = "Multiline string\ + Multiline string\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; + +// Prettier main +const loremIpsumFooBazBar1 = + "Multiline string\ + Multiline string\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\ + Multiline string\ + Multiline string"; +``` diff --git a/src/language-js/print/flow.js b/src/language-js/print/flow.js index 47ffce034..22bf76583 100644 --- a/src/language-js/print/flow.js +++ b/src/language-js/print/flow.js @@ -16,6 +16,7 @@ const { shouldPrintComma, } = require("../utils/index.js"); const { locStart, locEnd } = require("../loc.js"); +const { replaceTextEndOfLine } = require("../../document/doc-utils.js"); const { printClass } = require("./class.js"); const { printOpaqueType, @@ -278,7 +279,7 @@ function printFlow(path, options, print) { case "QualifiedTypeIdentifier": return [print("qualification"), ".", print("id")]; case "StringLiteralTypeAnnotation": - return printString(rawText(node), options); + return replaceTextEndOfLine(printString(rawText(node), options)); case "NumberLiteralTypeAnnotation": assert.strictEqual(typeof node.value, "number"); // fall through diff --git a/src/language-js/print/literal.js b/src/language-js/print/literal.js index a61a65eb3..a614bd5f4 100644 --- a/src/language-js/print/literal.js +++ b/src/language-js/print/literal.js @@ -1,5 +1,6 @@ "use strict"; const { printString, printNumber } = require("../../common/util.js"); +const { replaceTextEndOfLine } = require("../../document/doc-utils.js"); function printLiteral(path, options /*, print*/) { const node = path.getNode(); @@ -13,7 +14,7 @@ function printLiteral(path, options /*, print*/) { case "NumericLiteral": // Babel 6 Literal split return printNumber(node.extra.raw); case "StringLiteral": // Babel 6 Literal split - return printString(node.extra.raw, options); + return replaceTextEndOfLine(printString(node.extra.raw, options)); case "NullLiteral": // Babel 6 Literal split return "null"; case "BooleanLiteral": // Babel 6 Literal split @@ -40,7 +41,7 @@ function printLiteral(path, options /*, print*/) { } if (typeof value === "string") { - return printString(node.raw, options); + return replaceTextEndOfLine(printString(node.raw, options)); } return String(value); diff --git a/tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap b/tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..bafcf8a56 --- /dev/null +++ b/tests/format/flow/literal/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`multiline.js format 1`] = ` +====================================options===================================== +parsers: ["flow", "babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +type loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +type loremIpsumFooBazBar1 = + "Multiline string\\ + Multiline string"; + +type loremIpsumFooBazBar2 = + "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; diff --git a/tests/format/flow/literal/jsfmt.spec.js b/tests/format/flow/literal/jsfmt.spec.js new file mode 100644 index 000000000..fbfa6501a --- /dev/null +++ b/tests/format/flow/literal/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow", "babel"]); diff --git a/tests/format/flow/literal/multiline.js b/tests/format/flow/literal/multiline.js new file mode 100644 index 000000000..22648828e --- /dev/null +++ b/tests/format/flow/literal/multiline.js @@ -0,0 +1,6 @@ +type loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' diff --git a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap index dc97633de..9dead4456 100644 --- a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,70 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`multiline-literal.js - {"trailingComma":"all"} format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow"] +printWidth: 80 +trailingComma: "all" + | printWidth +=====================================input====================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string\\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = + "Multiline string\\ + Multiline string\\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; + +exports[`multiline-literal.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string\\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = + "Multiline string\\ + Multiline string\\ +"; + +const loremIpsumFooBazBar2 = + "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; + exports[`non-octal-eight-and-nine.js [acorn] format 1`] = ` "Invalid escape sequence (3:3) 1 | // https://github.com/babel/babel/pull/11852 diff --git a/tests/format/js/strings/multiline-literal.js b/tests/format/js/strings/multiline-literal.js new file mode 100644 index 000000000..fcecf64f3 --- /dev/null +++ b/tests/format/js/strings/multiline-literal.js @@ -0,0 +1,9 @@ +// https://github.com/prettier/prettier/pull/13274 + +const loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string\ +' + +const loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string' diff --git a/tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..cb42c67fc --- /dev/null +++ b/tests/format/typescript/literal/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`multiline.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type loremIpsumFooBazBar1 = 'Multiline string\\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\\ + Multiline string\\ + Multiline string' + +=====================================output===================================== +type loremIpsumFooBazBar1 = "Multiline string\\ + Multiline string"; + +type loremIpsumFooBazBar2 = "Multiline string\\ + Multiline string\\ + Multiline string"; + +================================================================================ +`; diff --git a/tests/format/typescript/literal/jsfmt.spec.js b/tests/format/typescript/literal/jsfmt.spec.js new file mode 100644 index 000000000..2ea3bb6eb --- /dev/null +++ b/tests/format/typescript/literal/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/format/typescript/literal/multiline.ts b/tests/format/typescript/literal/multiline.ts new file mode 100644 index 000000000..22648828e --- /dev/null +++ b/tests/format/typescript/literal/multiline.ts @@ -0,0 +1,6 @@ +type loremIpsumFooBazBar1 = 'Multiline string\ + Multiline string' + +type loremIpsumFooBazBar2 = 'Multiline string\ + Multiline string\ + Multiline string'