From c9b79ddb01522878a023d259a79e0530f23136e7 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 2 Nov 2019 23:30:18 +0100 Subject: [PATCH 01/13] Blog post, changelog and docs for 1.19 --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- changelog_unreleased/TEMPLATE.md | 39 + changelog_unreleased/angular/.gitkeep | 0 changelog_unreleased/api/.gitkeep | 0 changelog_unreleased/cli/.gitkeep | 0 changelog_unreleased/css/.gitkeep | 0 changelog_unreleased/flow/.gitkeep | 0 changelog_unreleased/graphql/.gitkeep | 0 changelog_unreleased/handlebars/.gitkeep | 0 changelog_unreleased/html/.gitkeep | 0 changelog_unreleased/javascript/.gitkeep | 0 changelog_unreleased/json/.gitkeep | 0 changelog_unreleased/less/.gitkeep | 0 changelog_unreleased/lwc/.gitkeep | 0 changelog_unreleased/markdown/.gitkeep | 0 changelog_unreleased/mdx/.gitkeep | 0 changelog_unreleased/scss/.gitkeep | 0 changelog_unreleased/typescript/.gitkeep | 0 changelog_unreleased/vue/.gitkeep | 0 changelog_unreleased/yaml/.gitkeep | 0 package.json | 2 +- scripts/release/steps/update-changelog.js | 2 +- .../blog/2019-11-03-1.19.0.md | 1383 ++++++++--------- website/versioned_docs/version-stable/api.md | 2 + website/versioned_docs/version-stable/cli.md | 4 +- .../integrating-with-linters.md | 2 +- .../versioned_docs/version-stable/options.md | 15 + .../versioned_docs/version-stable/plugins.md | 3 +- .../versioned_docs/version-stable/webstorm.md | 2 +- 29 files changed, 749 insertions(+), 707 deletions(-) create mode 100644 changelog_unreleased/TEMPLATE.md create mode 100644 changelog_unreleased/angular/.gitkeep create mode 100644 changelog_unreleased/api/.gitkeep create mode 100644 changelog_unreleased/cli/.gitkeep create mode 100644 changelog_unreleased/css/.gitkeep create mode 100644 changelog_unreleased/flow/.gitkeep create mode 100644 changelog_unreleased/graphql/.gitkeep create mode 100644 changelog_unreleased/handlebars/.gitkeep create mode 100644 changelog_unreleased/html/.gitkeep create mode 100644 changelog_unreleased/javascript/.gitkeep create mode 100644 changelog_unreleased/json/.gitkeep create mode 100644 changelog_unreleased/less/.gitkeep create mode 100644 changelog_unreleased/lwc/.gitkeep create mode 100644 changelog_unreleased/markdown/.gitkeep create mode 100644 changelog_unreleased/mdx/.gitkeep create mode 100644 changelog_unreleased/scss/.gitkeep create mode 100644 changelog_unreleased/typescript/.gitkeep create mode 100644 changelog_unreleased/vue/.gitkeep create mode 100644 changelog_unreleased/yaml/.gitkeep rename CHANGELOG.unreleased.md => website/blog/2019-11-03-1.19.0.md (70%) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index aee7178f6a5a..6ef9e89f75e3 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -5,7 +5,7 @@ - [ ] I’ve added tests to confirm my change works. - [ ] (If changing the API or CLI) I’ve documented the changes I’ve made (in the `docs/` directory) -- [ ] (If the change is user-facing) I’ve added my changes to the `CHANGELOG.unreleased.md` file following the template. +- [ ] (If the change is user-facing) I’ve added my changes to `changelog_unreleased/*/pr-XXXX.md` file following `changelog_unreleased/TEMPLATE.md`. - [ ] I’ve read the [contributing guidelines](https://github.com/prettier/prettier/blob/master/CONTRIBUTING.md). **✨[Try the playground for this PR](https://prettier.io/playground-redirect)✨** diff --git a/changelog_unreleased/TEMPLATE.md b/changelog_unreleased/TEMPLATE.md new file mode 100644 index 000000000000..c5886b13a4d8 --- /dev/null +++ b/changelog_unreleased/TEMPLATE.md @@ -0,0 +1,39 @@ + + +#### Title ([#XXXX](https://github.com/prettier/prettier/pull/XXXX) by [@user](https://github.com/user)) + +Optional description if it makes sense. + + +```jsx +// Input +(foo ?? baz) || baz; + +// Prettier stable +foo ?? baz || baz; + +// Prettier master +(foo ?? baz) || baz; +``` diff --git a/changelog_unreleased/angular/.gitkeep b/changelog_unreleased/angular/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/api/.gitkeep b/changelog_unreleased/api/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/cli/.gitkeep b/changelog_unreleased/cli/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/css/.gitkeep b/changelog_unreleased/css/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/flow/.gitkeep b/changelog_unreleased/flow/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/graphql/.gitkeep b/changelog_unreleased/graphql/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/handlebars/.gitkeep b/changelog_unreleased/handlebars/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/html/.gitkeep b/changelog_unreleased/html/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/javascript/.gitkeep b/changelog_unreleased/javascript/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/json/.gitkeep b/changelog_unreleased/json/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/less/.gitkeep b/changelog_unreleased/less/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/lwc/.gitkeep b/changelog_unreleased/lwc/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/markdown/.gitkeep b/changelog_unreleased/markdown/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/mdx/.gitkeep b/changelog_unreleased/mdx/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/scss/.gitkeep b/changelog_unreleased/scss/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/typescript/.gitkeep b/changelog_unreleased/typescript/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/vue/.gitkeep b/changelog_unreleased/vue/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/changelog_unreleased/yaml/.gitkeep b/changelog_unreleased/yaml/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/package.json b/package.json index 0fe307bd627f..ebcb8c1813c4 100644 --- a/package.json +++ b/package.json @@ -130,6 +130,6 @@ "build": "node --max-old-space-size=3072 ./scripts/build/build.js", "build-docs": "node ./scripts/build-docs.js", "check-deps": "node ./scripts/check-deps.js", - "spellcheck": "npx -p cspell@4.0.31 cspell {bin,scripts,src}/**/*.js {docs,website/blog}/**/*.md CHANGELOG.unreleased.md" + "spellcheck": "npx -p cspell@4.0.31 cspell {bin,scripts,src}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md" } } diff --git a/scripts/release/steps/update-changelog.js b/scripts/release/steps/update-changelog.js index 4ad5ee3dfd32..d45d5b1b1c34 100644 --- a/scripts/release/steps/update-changelog.js +++ b/scripts/release/steps/update-changelog.js @@ -57,7 +57,7 @@ module.exports = async function({ version, previousVersion }) { dedent(chalk` {yellow.bold A manual step is necessary.} - You can copy the entries from {bold CHANGELOG.unreleased.md} to {bold CHANGELOG.md} + You can copy the entries from {bold changelog_unreleased/*/pr-*.md} to {bold CHANGELOG.md} and update it accordingly. You don't need to commit the file, the script will take care of that. diff --git a/CHANGELOG.unreleased.md b/website/blog/2019-11-03-1.19.0.md similarity index 70% rename from CHANGELOG.unreleased.md rename to website/blog/2019-11-03-1.19.0.md index 30a4121fbf09..0543d427bb87 100644 --- a/CHANGELOG.unreleased.md +++ b/website/blog/2019-11-03-1.19.0.md @@ -1,50 +1,24 @@ - -#### Category: Title ([#PR] by [@user]) +## Highlights -Description +### Vue -``` -// Input -Code Sample - -// Output (Prettier stable) -Code Sample - -// Output (Prettier master) -Code Sample -``` - -Details: - - Description: optional if the `Title` is enough to explain everything. - -Examples: +#### Add `--vue-indent-script-and-style` ([#6157] by [@kamilic]) -#### TypeScript: Correctly handle `//` in TSX ([#5728] by [@JamesHenry]) +The new [`--vue-indent-script-and-style`](https://prettier.io/docs/en/options.html#vue-files-script-and-style-tags-indentation) option controls whether or not to indent the code inside ` - - - - - - - -``` - -#### TypeScript: Correctly format long one-line mapped types in one pass ([#6420] by [@sosukesuzuki]) - -Previously, when Prettier formatted long one-line mapped types, it would break the line but didn’t add a semicolon until you ran Prettier again, which means Prettier’s idempotence rule was broken. Now, Prettier adds the semicolon in the first run. - - -```ts -// Input -type FooBar = { [P in keyof T]: T[P] extends Something ? Something : T[P] } - -// Prettier (stable) -type FooBar = { - [P in keyof T]: T[P] extends Something ? Something : T[P] -}; - -// Prettier (master) -type FooBar = { - [P in keyof T]: T[P] extends Something ? Something : T[P]; -}; -``` - -#### JavaScript: Fix formatting of object destructuring with parameter decorators ([#6411] by [@sosukesuzuki]) - -Previously, Prettier formatted decorators for destructured parameters in a weird way. Now, parameter decorators are placed just above the parameter they belong to. +#### Fix formatting of object destructuring with parameter decorators ([#6411] by [@sosukesuzuki]) ```js @@ -811,7 +699,7 @@ class Class { ) {} } -// Prettier (stable) +// Prettier 1.18 class Class { method(@decorator { @@ -819,7 +707,7 @@ class Class { }) {} } -// Prettier (master) +// Prettier 1.19 class Class { method( @decorator @@ -828,7 +716,7 @@ class Class { } ``` -#### JavaScript: Handle empty object patterns with type annotations in function parameters ([#6438] by [@bakkot]) +#### Handle empty object patterns with type annotations in function parameters ([#6438] by [@bakkot]) ```js @@ -836,18 +724,18 @@ class Class { const f = ({}: MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongType) => {}; function g({}: Foo) {} -// Output (Prettier stable) +// Prettier 1.18 const f = ({ , }: MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongType) => {}; function g({ }: Foo) {} -// Output (Prettier master) +// Prettier 1.19 const f = ({}: MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongType) => {}; function g({}: Foo) {} ``` -#### JavaScript: Put a closing parenthesis onto a new line after binary expressions within function calls ([#6441] by [@sosukesuzuki]) +#### Put a closing parenthesis onto a new line after binary expressions within function calls ([#6441] by [@sosukesuzuki]) ```js @@ -860,14 +748,14 @@ function g({}: Foo) {} eeeeeeeeeeeeeeeeeeeeeeeee )(); -// Prettier (stable) +// Prettier 1.18 (aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc && ddddddddddddddddddddddddd && eeeeeeeeeeeeeeeeeeeeeeeee)(); -// Prettier (master) +// Prettier 1.19 ( aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb && @@ -877,25 +765,25 @@ function g({}: Foo) {} )(); ``` -#### JavaScript: Fix formatting of long named exports ([#6446] by [@sosukesuzuki]) +#### Fix formatting of long named exports ([#6446] by [@sosukesuzuki]) -Now, Prettier formats them the same way it formats named imports. +Now, Prettier formats named exports the same way as named imports. ```js // Input export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo"; -// Prettier (stable) +// Prettier 1.18 export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo"; -// Prettier (master) +// Prettier 1.19 export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo"; ``` -#### JavaScript: Fix bad formatting for multi-line optional chaining with comment ([#6506] by [@sosukesuzuki]) +#### Fix bad formatting for multi-line optional chaining with comment ([#6506] by [@sosukesuzuki]) ```js @@ -906,14 +794,14 @@ return a // Comment ?.d() -// Prettier (stable) +// Prettier 1.18 return a .b() .c() ?.// Comment d(); -// Prettier (master) +// Prettier 1.19 return ( a .b() @@ -923,7 +811,7 @@ return ( ); ``` -#### JavaScript: Fix inconsistent indentation in switch statement ([#6514] by [@sosukesuzuki]) +#### Fix inconsistent indentation in switch statement ([#6514] by [@sosukesuzuki]) ```js @@ -934,7 +822,7 @@ switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVar switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) { } -// Prettier (stable) +// Prettier 1.18 switch ( $veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName @@ -946,7 +834,7 @@ switch ( ) { } -// Prettier (master) +// Prettier 1.19 switch ( $veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName @@ -960,62 +848,7 @@ switch ( } ``` -#### TypeScript: Keep type parameters inline for type annotations in variable declarations ([#6467] by [@sosukesuzuki]) - - -```ts -// Input -const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); - -// Prettier (stable) -const fooooooooooooooo: SomeThing< - boolean -> = looooooooooooooooooooooooooooooongNameFunc(); - -// Prettier (master) -const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); -``` - -#### Handlebars: Fix `--single-quote` option on HTML attributes ([#6377] by [@dcyriller]) - -Previously, the flag was not applied on HTML attributes. - - -```hbs - -
- - -
- - -
-``` - -#### TypeScript: Sometimes double parentheses around types were removed incorrectly ([#6604] by [@sosukesuzuki]) - - -```ts -// Input -type A = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6; -type B = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6; -type C = ((number | string))["toString"]; -type D = ((keyof T1))["foo"]; - -// Prettier (stable) -type A = 0 extends 1 extends 2 ? 3 : 4 ? 5 : 6; -type B = 0 extends 1 ? 2 : 3 extends 4 ? 5 : 6; -type C = number | string["toString"]; -type D = keyof T1["foo"]; - -// Prettier (master) -type A = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; -type B = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; -type C = (number | string)["toString"]; -type D = (keyof T1)["foo"]; -``` - -#### JavaScript: Support formatting code with V8 intrinsics ([#6496] by [@rreverser]) +#### Support formatting code with V8 intrinsics ([#6496] by [@rreverser]) ```js @@ -1026,33 +859,19 @@ function doSmth() { foo ) } -// Prettier (stable) +// Prettier 1.18 SyntaxError: Unexpected token (2:13) 1 | function doSmth() { > 2 | %DebugPrint | ^ -// Prettier (master) +// Prettier 1.19 function doSmth() { %DebugPrint(foo); } ``` -#### TypeScript: Sometimes removing parentheses around JSX made the code unparseable ([#6640] by [@sosukesuzuki]) - - -```tsx -// Input -().toString(); - -// Prettier (stable) -.toString(): - -// Prettier (master) -().toString(); -``` - -#### JavaScript: Object destructuring in method parameters always broke into multiple lines ([#6646] by [@ericsakmar]) +#### Object destructuring in method parameters always broke into multiple lines ([#6646] by [@ericsakmar]) ```js @@ -1072,7 +891,7 @@ class A { } } -// Prettier (stable) +// Prettier 1.18 const obj = { func( id, @@ -1103,7 +922,7 @@ class A { } } -// Prettier (master) +// Prettier 1.19 const obj = { func(id, { blog: { title } }) { return id + title; @@ -1120,21 +939,96 @@ class A { } ``` -#### Angular: Put a closing parenthesis onto a new line after ternaries passed to pipes ([#5682] by [@selvazhagan]) +### HTML + +#### Don't wrap `template` elements on lines shorter than `printWidth` ([#6284] by [@sosukesuzuki]) + +Previously, even if the line length was shorter than `printWidth`, Prettier would break the line with a `template` element. + + +```html + + + + + + + + +``` + +#### Script tags are now treated as blocks for the purposes of formatting ([#6423] by [@thorn0]) + +Previously, in the [whitespace-sensitive mode](https://prettier.io/docs/en/options.html#html-whitespace-sensitivity), they were formatted as if they were inline. + + +```html + + + + + + + + + +``` + +#### Add support for `!` and other entities ([#6785] by [@lydell] and [@ikatyang]) + +Previously, Prettier only supported the most common HTML entities, such as ` ` and `"`. Now, Prettier supports every HTML entity in the HTML spec, such as `!` and `⋔`. + + +```html + +

Hi!

+ + + + +

Hi!

+``` + +### Angular + +#### Put a closing parenthesis onto a new line after ternaries passed to pipes ([#5682] by [@selvazhagan]) ```html {{ (isCustomDiscount ? 'DISCOUNTS__DISCOUNT_TRAINING_HEADER__CUSTOM_DISCOUNT' : 'DISCOUNTS__DISCOUNT_TRAINING_HEADER__DISCOUNT') | translate }} - + {{ (isCustomDiscount ? "DISCOUNTS__DISCOUNT_TRAINING_HEADER__CUSTOM_DISCOUNT" : "DISCOUNTS__DISCOUNT_TRAINING_HEADER__DISCOUNT") | translate }} - + {{ (isCustomDiscount ? "DISCOUNTS__DISCOUNT_TRAINING_HEADER__CUSTOM_DISCOUNT" @@ -1143,7 +1037,38 @@ class A { }} ``` -#### Handlebars: Fix handling of whitespace and line breaks ([#6354] by [@chadian]) +#### Add formatting for `i18n` attributes ([#6695] by [@voithos]) + +Prettier will auto-wrap the contents of `i18n` attributes once they exceed the line length. + + +```html + +

+ Hello! +

+ + +

+ Hello! +

+ + +

+ Hello! +

+``` + +### Handlebars + +#### Fix handling of whitespace and line breaks ([#6354] by [@chadian]) This fixes a variety of whitespace and line break use cases within Handlebars and Glimmer templates. @@ -1159,7 +1084,7 @@ Some sentence with {{dynamic}} expressions. sometimes{{nogaps}}areimportant {{name}} is your name - + {{name}} Some sentence with @@ -1175,7 +1100,7 @@ areimportant {{name}} is your name - + {{name}} Some sentence with {{dynamic}} expressions. @@ -1187,174 +1112,233 @@ sometimes{{nogaps}}areimportant {{name}} is your name ``` -#### Angular: Add formatting for `i18n` attributes ([#6695] by [@voithos]) +#### Avoid adding unwanted line breaks between text and mustaches ([#6186] by [@gavinjoyce]) -Prettier will auto-wrap the contents of `i18n` attributes once they exceed the line length. +Previously, Prettier added line breaks between text and mustaches which resulted in unwanted whitespace in rendered output. -```html +```hbs -

- Hello! -

+

Your username is @{{name}}

+

Hi {{firstName}} {{lastName}}

- -

- Hello! -

+ +

+ Your username is @ + {{name}} +

+

+ Hi + {{firstName}} + {{lastName}} +

- -

- Hello! -

+ +

+ Your username is @{{name}} +

+

+ Hi {{firstName}} {{lastName}} +

``` -#### JavaScript: Break arrays of arrays/objects if each element has more than one element/property ([#6694] by [@sosukesuzuki]) +#### Improve comment formatting ([#6206] by [@gavinjoyce]) -```js -// Input -test.each([ - { a: "1", b: 1 }, - { a: "2", b: 2 }, - { a: "3", b: 3 } -])("test", ({ a, b }) => { - expect(Number(a)).toBe(b); -}); -[[0, 1, 2], [0, 1, 2]]; -new Map([ - [A, B], - [C, D], - [E, F], - [G, H], - [I, J], - [K, L], - [M, N] -]); +```hbs + +
+ {{! Foo }} + {{#if @foo}} + Foo + {{/if}} -// Output (Prettier stable) -test.each([{ a: "1", b: 1 }, { a: "2", b: 2 }, { a: "3", b: 3 }])( - "test", - ({ a, b }) => { - expect(Number(a)).toBe(b); - } -); -[[0, 1, 2], [0, 1, 2]] -new Map([[A, B], [C, D], [E, F], [G, H], [I, J], [K, L], [M, N]]); + {{! Bar }} + {{#if @bar}} + Bar + {{/if}} +
-// Output (Prettier master) -test.each([ - { a: "1", b: 1 }, - { a: "2", b: 2 }, - { a: "3", b: 3 } -])("test", ({ a, b }) => { - expect(Number(a)).toBe(b); -}); -[ - [0, 1, 2], - [0, 1, 2] -]; -new Map([ - [A, B], - [C, D], - [E, F], - [G, H], - [I, J], - [K, L], - [M, N] -]); + +
+ {{! Foo }} + {{#if @foo}} + Foo + {{/if}}{{! Bar }}{{#if @bar}} + Bar + {{/if}} +
+ + +
+ {{! Foo }} + {{#if @foo}} + Foo + {{/if}} + {{! Bar }} + {{#if @bar}} + Bar + {{/if}} +
``` -#### TypeScript: Keep semi for a class property before index signature when no-semi is enabled ([#6728] by [@sosukesuzuki]) +#### Preserve HTML entities ([#6234] by [@gavinjoyce]) -Attempting to format Prettier’s output again used to result in a syntax error. + +```hbs + +

+ Some escaped characters: < > & +

+ + +

+ Some escaped characters: < > & +

+ + +

+ Some escaped characters: < > & +

+``` + +#### Fix `--single-quote` option on HTML attributes ([#6377] by [@dcyriller]) + +Previously, the flag was not applied on HTML attributes. + + +```hbs + +
+ + +
+ + +
+``` + +### MDX + +#### Text following JSX was trimmed incorrectly ([#6340] by [@JounQin]) -```ts -// Input -export class User { - id: number = 2; - [key: string]: any -} +```md + + + test test + 123 -// Output (Prettier stable) -export class User { - id: number = 2 - [key: string]: any -} + + + test test +123 -// Output (Prettier master) -export class User { - id: number = 2; - [key: string]: any -} + + + test test + 123 ``` -#### Flow: Parentheses around arrow functions' return types that have `FunctionTypeAnnotation` nested in `ObjectTypeAnnotation` ([#6717] by [@sosukesuzuki]) +#### Adjacent JSX elements should be allowed ([#6332] by [@JounQin]) + + +```jsx +// Input + + test test +123 + +// Prettier 1.18 +SyntaxError: Unexpected token (3:9) + 1 | + 2 | test test +> 3 | 123 + | ^ + +// Prettier 1.19 + + test test +123 -This is a workaround for a [bug](https://github.com/facebook/flow/pull/8163) in the Flow parser. Without the parentheses, the parser throws an error. -```js // Input -const example1 = (): { p: (string => string) } => (0: any); + + test test + + + test test +123 -// Output (Prettier stable) -const example1 = (): { p: string => string } => (0: any); +// Prettier 1.18 +SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...? (4:1) + 2 | test test + 3 | +> 4 | + | ^ + 5 | test test + 6 | 123 -// Output (Prettier master) -const example1 = (): ({ p: string => string }) => (0: any); +// Prettier 1.19 + + test test + + + test test +123 ``` -#### CLI: Handle errors when reading stdin ([#6708] by [@andersk] and [@lydell]) +### API + +#### Add `resolveConfig` option to `getFileInfo()` ([#6666] by [@kaicataldo]) + +Add a `resolveConfig: boolean` option to `prettier.getFileInfo()` that, when set to `true`, will resolve the configuration for the given file path. This allows consumers to take any overridden parsers into account. + +### CLI + +#### Handle errors when reading stdin ([#6708] by [@andersk] and [@lydell]) If you had an error in your `.prettierrc` Prettier used to crash when formatting stdin. Such errors are now handled properly. ``` -# Prettier stable +# Prettier 1.18 $ prettier --parser babel < test.js (node:21531) UnhandledPromiseRejectionWarning: Error: Invalid printWidth value. Expected an integer, but received "nope". - at _loop (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:7887:63) - at Normalizer._applyNormalization (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:8000:13) - at applyNormalization (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:7817:49) - at Normalizer.normalize (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:7823:9) - at normalizeOptions$1 (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:8760:31) - at Object.normalizeApiOptions (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:8918:10) - at getOptionsForFile (/home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:44160:69) - at /home/lydell/forks/prettier/node_modules/prettier/bin-prettier.js:44214:22 + at _loop (/home/you/project/node_modules/prettier/bin-prettier.js:7887:63) + at Normalizer._applyNormalization (/home/you/project/node_modules/prettier/bin-prettier.js:8000:13) + at applyNormalization (/home/you/project/node_modules/prettier/bin-prettier.js:7817:49) + at Normalizer.normalize (/home/you/project/node_modules/prettier/bin-prettier.js:7823:9) + at normalizeOptions$1 (/home/you/project/node_modules/prettier/bin-prettier.js:8760:31) + at Object.normalizeApiOptions (/home/you/project/node_modules/prettier/bin-prettier.js:8918:10) + at getOptionsForFile (/home/you/project/node_modules/prettier/bin-prettier.js:44160:69) + at /home/you/project/node_modules/prettier/bin-prettier.js:44214:22 at process._tickCallback (internal/process/next_tick.js:68:7) (node:21531) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:21531) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. -# Prettier master +# Prettier 1.19 $ prettier --parser babel < test.js [error] Invalid printWidth value. Expected an integer, but received "nope". ``` -#### CLI: Gracefully handle nonexistent paths passed to --stdin-filepath ([#6687] by [@voithos]) +#### CLI: Gracefully handle nonexistent paths passed to `--stdin-filepath` ([#6687] by [@voithos] and [@lydell]) -Previously, if you passed a nonexistent subdirectory to --stdin-filepath, Prettier would throw an error. Now, Prettier gracefully handles this. +Previously, if you passed a nonexistent subdirectory to `--stdin-filepath`, Prettier would throw an error. Now, Prettier gracefully handles this. ``` -# Prettier stable +# Prettier 1.18 $ prettier --stdin-filepath does/not/exist.js < test.js -[error] Invalid configuration file: ENOENT: no such file or directory, scandir '/home/lydell/forks/prettier/does/not' +[error] Invalid configuration file: ENOENT: no such file or directory, scandir '/home/you/project/does/not' -# Prettier master +# Prettier 1.19 $ prettier --stdin-filepath does/not/exist.js < test.js test; ``` [#5682]: https://github.com/prettier/prettier/pull/5682 -[#6657]: https://github.com/prettier/prettier/pull/6657 [#5910]: https://github.com/prettier/prettier/pull/5910 [#6033]: https://github.com/prettier/prettier/pull/6033 +[#6157]: https://github.com/prettier/prettier/pull/6157 [#6186]: https://github.com/prettier/prettier/pull/6186 [#6206]: https://github.com/prettier/prettier/pull/6206 [#6209]: https://github.com/prettier/prettier/pull/6209 @@ -1363,7 +1347,6 @@ test; [#6236]: https://github.com/prettier/prettier/pull/6236 [#6270]: https://github.com/prettier/prettier/pull/6270 [#6284]: https://github.com/prettier/prettier/pull/6284 -[#6785]: https://github.com/prettier/prettier/pull/6785 [#6289]: https://github.com/prettier/prettier/pull/6289 [#6301]: https://github.com/prettier/prettier/pull/6301 [#6307]: https://github.com/prettier/prettier/pull/6307 @@ -1390,31 +1373,35 @@ test; [#6605]: https://github.com/prettier/prettier/pull/6605 [#6640]: https://github.com/prettier/prettier/pull/6640 [#6646]: https://github.com/prettier/prettier/pull/6646 +[#6657]: https://github.com/prettier/prettier/pull/6657 [#6666]: https://github.com/prettier/prettier/pull/6666 [#6673]: https://github.com/prettier/prettier/pull/6673 -[#6695]: https://github.com/prettier/prettier/pull/6695 +[#6687]: https://github.com/prettier/prettier/pull/6687 [#6694]: https://github.com/prettier/prettier/pull/6694 +[#6695]: https://github.com/prettier/prettier/pull/6695 +[#6708]: https://github.com/prettier/prettier/pull/6708 [#6717]: https://github.com/prettier/prettier/pull/6717 [#6728]: https://github.com/prettier/prettier/pull/6728 -[#6708]: https://github.com/prettier/prettier/pull/6708 -[#6687]: https://github.com/prettier/prettier/pull/6687 +[#6785]: https://github.com/prettier/prettier/pull/6785 +[@andersk]: https://github.com/andersk +[@bakkot]: https://gibhub.com/bakkot [@brainkim]: https://github.com/brainkim +[@chadian]: https://github.com/chadian +[@cryrivers]: https://github.com/Cryrivers +[@dcyriller]: https://github.com/dcyriller [@duailibe]: https://github.com/duailibe -[@gavinjoyce]: https://github.com/gavinjoyce -[@sosukesuzuki]: https://github.com/sosukesuzuki +[@ericsakmar]: https://github.com/ericsakmar [@g-harel]: https://github.com/g-harel +[@gavinjoyce]: https://github.com/gavinjoyce +[@ikatyang]: https://github.com/ikatyang/ [@jounqin]: https://github.com/JounQin -[@bakkot]: https://gibhub.com/bakkot -[@thorn0]: https://github.com/thorn0 -[@dcyriller]: https://github.com/dcyriller +[@kaicataldo]: https://github.com/kaicataldo +[@kamilic]: https://github.com/kamilic +[@lydell]: https://github.com/lydell [@rreverser]: https://github.com/RReverser -[@ericsakmar]: https://github.com/ericsakmar +[@selvazhagan]: https://github.com/selvazhagan +[@sosukesuzuki]: https://github.com/sosukesuzuki [@squidfunk]: https://github.com/squidfunk +[@thorn0]: https://github.com/thorn0 [@vjeux]: https://github.com/vjeux -[@selvazhagan]: https://github.com/selvazhagan -[@chadian]: https://github.com/chadian -[@kaicataldo]: https://github.com/kaicataldo -[@cryrivers]: https://github.com/Cryrivers [@voithos]: https://github.com/voithos -[@andersk]: https://github.com/andersk -[@lydell]: https://github.com/lydell diff --git a/website/versioned_docs/version-stable/api.md b/website/versioned_docs/version-stable/api.md index cb814f647d8d..53276a878203 100644 --- a/website/versioned_docs/version-stable/api.md +++ b/website/versioned_docs/version-stable/api.md @@ -101,6 +101,8 @@ Setting `options.ignorePath` (`string`) and `options.withNodeModules` (`boolean` Providing [plugin](plugins.md) paths in `options.plugins` (`string[]`) helps extract `inferredParser` for files that are not supported by Prettier core. +When setting `options.resolveConfig` (`boolean`, default `false`), Prettier will resolve the configuration for the given `filePath`. This is useful, for example, when the `inferredParser` might be overridden for a subset of files. + Use `prettier.getFileInfo.sync(filePath [, options])` if you'd like to use sync version. ## `prettier.getSupportInfo([version])` diff --git a/website/versioned_docs/version-stable/cli.md b/website/versioned_docs/version-stable/cli.md index 9b483dd37235..dc0136310f13 100644 --- a/website/versioned_docs/version-stable/cli.md +++ b/website/versioned_docs/version-stable/cli.md @@ -18,7 +18,7 @@ In practice, this may look something like: prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**/*.js" ``` -Don't forget the quotes around the globs! The quotes make sure that Prettier expands the globs rather than your shell, for cross-platform usage. The [glob syntax from the `fast-glob` module](https://github.com/mrmlnc/fast-glob/blob/master/README.md#pattern-syntax) is used. +Don't forget the quotes around the globs! The quotes make sure that Prettier expands the globs rather than your shell, for cross-platform usage. The [glob syntax from the glob module](https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer) is used. Prettier CLI will ignore files located in `node_modules` directory. To opt-out from this behavior use `--with-node-modules` flag. @@ -149,8 +149,6 @@ Prettier CLI will ignore files located in `node_modules` directory. To opt-out f This rewrites all processed files in place. This is comparable to the `eslint --fix` workflow. -To avoid re-checking unchanged files, use the `--only-changed` flag. - ## `--loglevel` Change the level of logging for the CLI. Valid options are: diff --git a/website/versioned_docs/version-stable/integrating-with-linters.md b/website/versioned_docs/version-stable/integrating-with-linters.md index a6b762f5bf57..e310e0e1bbc9 100644 --- a/website/versioned_docs/version-stable/integrating-with-linters.md +++ b/website/versioned_docs/version-stable/integrating-with-linters.md @@ -125,7 +125,7 @@ Then in `tslint.json`: ### Disable formatting rules -[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your [`devDependencies`], then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. +[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your `devDependencies`, then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. ```bash yarn add --dev stylelint-config-prettier diff --git a/website/versioned_docs/version-stable/options.md b/website/versioned_docs/version-stable/options.md index 170a96fcf96c..b88cd4aeaaae 100644 --- a/website/versioned_docs/version-stable/options.md +++ b/website/versioned_docs/version-stable/options.md @@ -308,6 +308,21 @@ Valid options: | ------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------- | | `"css"` | --html-whitespace-sensitivity | htmlWhitespaceSensitivity: "" | +## Vue files script and style tags indentation + +_First available in v1.19.0_ + +Whether or not to indent the code inside ` + + + + + + + + + + + + + + +``` + ### Angular #### Put a closing parenthesis onto a new line after ternaries passed to pipes ([#5682] by [@selvazhagan]) @@ -1211,13 +1278,33 @@ Previously, the flag was not applied on HTML attributes.
- +
- +
``` +#### Break long interpolations ([#6249] by [@jjaffeux]) + + +```hbs + +{{my-component foo="bar" bar="baz" action=(action "almostTheMaximumLengthxxxx") +}} + + +{{my-component foo="bar" bar="baz" action=(action "almostTheMaximumLengthxxxx") +}} + + +{{my-component + foo="bar" + bar="baz" + action=(action "almostTheMaximumLengthxxxx") +}} +``` + ### MDX #### Text following JSX was trimmed incorrectly ([#6340] by [@JounQin]) @@ -1321,7 +1408,7 @@ $ prettier --parser babel < test.js [error] Invalid printWidth value. Expected an integer, but received "nope". ``` -#### CLI: Gracefully handle nonexistent paths passed to `--stdin-filepath` ([#6687] by [@voithos] and [@lydell]) +#### Gracefully handle nonexistent paths passed to `--stdin-filepath` ([#6687] by [@voithos] and [@lydell]) Previously, if you passed a nonexistent subdirectory to `--stdin-filepath`, Prettier would throw an error. Now, Prettier gracefully handles this. @@ -1335,6 +1422,16 @@ $ prettier --stdin-filepath does/not/exist.js < test.js test; ``` +#### Config should not be evaluated for ignored files ([#6233] by [@jamesreggio]) + +Prior to this change, the CLI would resolve the config for a file before checking it against the ignored list. If the config was invalid, the CLI would report a failure. + +This change relocates the config-resolution phase until after the file is confirmed to not be ignored. + +### Other + +Thanks to [@fisker] for updating lots of Prettier’s dependencies! + [#5682]: https://github.com/prettier/prettier/pull/5682 [#5910]: https://github.com/prettier/prettier/pull/5910 [#6033]: https://github.com/prettier/prettier/pull/6033 @@ -1343,11 +1440,14 @@ test; [#6206]: https://github.com/prettier/prettier/pull/6206 [#6209]: https://github.com/prettier/prettier/pull/6209 [#6217]: https://github.com/prettier/prettier/pull/6217 +[#6233]: https://github.com/prettier/prettier/pull/6233 [#6234]: https://github.com/prettier/prettier/pull/6234 [#6236]: https://github.com/prettier/prettier/pull/6236 +[#6249]: https://github.com/prettier/prettier/pull/6249 [#6270]: https://github.com/prettier/prettier/pull/6270 [#6284]: https://github.com/prettier/prettier/pull/6284 [#6289]: https://github.com/prettier/prettier/pull/6289 +[#6293]: https://github.com/prettier/prettier/pull/6293 [#6301]: https://github.com/prettier/prettier/pull/6301 [#6307]: https://github.com/prettier/prettier/pull/6307 [#6332]: https://github.com/prettier/prettier/pull/6332 @@ -1366,6 +1466,7 @@ test; [#6441]: https://github.com/prettier/prettier/pull/6441 [#6446]: https://github.com/prettier/prettier/pull/6446 [#6467]: https://github.com/prettier/prettier/pull/6467 +[#6471]: https://github.com/prettier/prettier/pull/6471 [#6496]: https://github.com/prettier/prettier/pull/6496 [#6506]: https://github.com/prettier/prettier/pull/6506 [#6514]: https://github.com/prettier/prettier/pull/6514 @@ -1384,6 +1485,7 @@ test; [#6728]: https://github.com/prettier/prettier/pull/6728 [#6785]: https://github.com/prettier/prettier/pull/6785 [@andersk]: https://github.com/andersk +[@ascorbic]: https://github.com/ascorbic [@bakkot]: https://gibhub.com/bakkot [@brainkim]: https://github.com/brainkim [@chadian]: https://github.com/chadian @@ -1391,13 +1493,16 @@ test; [@dcyriller]: https://github.com/dcyriller [@duailibe]: https://github.com/duailibe [@ericsakmar]: https://github.com/ericsakmar +[@fisker]: https://github.com/fisker [@g-harel]: https://github.com/g-harel [@gavinjoyce]: https://github.com/gavinjoyce [@ikatyang]: https://github.com/ikatyang/ +[@jjaffeux]: https://github.com/jjaffeux [@jounqin]: https://github.com/JounQin [@kaicataldo]: https://github.com/kaicataldo [@kamilic]: https://github.com/kamilic [@lydell]: https://github.com/lydell +[@mattleff]: https://github.com/mattleff [@rreverser]: https://github.com/RReverser [@selvazhagan]: https://github.com/selvazhagan [@sosukesuzuki]: https://github.com/sosukesuzuki From f6aa51a2a5adb3d957c063ea647cf69314e04b68 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 4 Nov 2019 18:13:10 +0100 Subject: [PATCH 03/13] Fix link --- website/blog/2019-11-03-1.19.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/blog/2019-11-03-1.19.0.md b/website/blog/2019-11-03-1.19.0.md index 3599d37337fa..79c7e51a3f76 100644 --- a/website/blog/2019-11-03-1.19.0.md +++ b/website/blog/2019-11-03-1.19.0.md @@ -1462,7 +1462,7 @@ Thanks to [@fisker] for updating lots of Prettier’s dependencies! [#6412]: https://github.com/prettier/prettier/pull/6412 [#6420]: https://github.com/prettier/prettier/pull/6420 [#6423]: https://github.com/prettier/prettier/pull/6423 -[#6438]: https://github.com/prettier/prettier/pull/6411 +[#6438]: https://github.com/prettier/prettier/pull/6438 [#6441]: https://github.com/prettier/prettier/pull/6441 [#6446]: https://github.com/prettier/prettier/pull/6446 [#6467]: https://github.com/prettier/prettier/pull/6467 From a827f678d52ad6a5b946d4d02e2fa09274626f7a Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Nov 2019 19:35:36 +0100 Subject: [PATCH 04/13] Add changelog for Babel error recovery --- website/blog/2019-11-03-1.19.0.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/website/blog/2019-11-03-1.19.0.md b/website/blog/2019-11-03-1.19.0.md index 6da4c9123b56..75e05c850d61 100644 --- a/website/blog/2019-11-03-1.19.0.md +++ b/website/blog/2019-11-03-1.19.0.md @@ -191,6 +191,36 @@ eventStore.update( eventStore.update(id, _.flow(updater, incrementVersion)); ``` +#### Enable formatting even if there are parse errors in some cases ([#6816] by [@thorn0] and the Babel team) + +We updated the Babel parser to the latest version and got an awesome feature for free. Prettier is now able to format your code even if it is invalid in some cases, which should make your coding experience smoother. This will get better over time as Babel improves their error recovery parsing mode. Read more in the [Babel 7.7.0 blog post](https://babeljs.io/blog/2019/11/05/7.7.0#parser-error-recovery-10363-https-githubcom-babel-babel-pull-10363)! + + +```js +// Input +let a = { + __proto__ : x, + __proto__ : y +} +let a = 2 + +// Prettier 1.18 +SyntaxError: Redefinition of __proto__ property (3:3) + 1 | let a = { + 2 | __proto__ : x, +> 3 | __proto__ : y + | ^ + 4 | } + 5 | let a = 2 + +// Prettier 1.19 +let a = { + __proto__: x, + __proto__: y +}; +let a = 2; +``` + ## Other changes ### TypeScript @@ -1499,6 +1529,7 @@ Thanks to [@fisker] for updating lots of Prettier’s dependencies! [#6728]: https://github.com/prettier/prettier/pull/6728 [#6785]: https://github.com/prettier/prettier/pull/6785 [#6796]: https://github.com/prettier/prettier/pull/6796 +[#6816]: https://github.com/prettier/prettier/pull/6816 [@andersk]: https://github.com/andersk [@ascorbic]: https://github.com/ascorbic [@bakkot]: https://gibhub.com/bakkot From 32a6389aded3ef02b47afa67f01a47f4d49f1ccb Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Wed, 6 Nov 2019 20:36:46 +0100 Subject: [PATCH 05/13] Add changelog for Flow enums --- website/blog/2019-11-03-1.19.0.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/website/blog/2019-11-03-1.19.0.md b/website/blog/2019-11-03-1.19.0.md index 75e05c850d61..da66a5f4d815 100644 --- a/website/blog/2019-11-03-1.19.0.md +++ b/website/blog/2019-11-03-1.19.0.md @@ -574,6 +574,21 @@ const foo = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( ### Flow +#### Add support for enums ([#6833] by [@gkz]) + +```js +// Input +enum E of string { + A = "a", B = "b" +} + +// Prettier 1.19 +enum E of string { + A = "a", + B = "b", +} +``` + #### Parentheses around arrow functions' return types that have `FunctionTypeAnnotation` nested in `ObjectTypeAnnotation` ([#6717] by [@sosukesuzuki]) This is a workaround for a [bug](https://github.com/facebook/flow/pull/8163) in the Flow parser. Without the parentheses, the parser throws an error. @@ -1530,6 +1545,7 @@ Thanks to [@fisker] for updating lots of Prettier’s dependencies! [#6785]: https://github.com/prettier/prettier/pull/6785 [#6796]: https://github.com/prettier/prettier/pull/6796 [#6816]: https://github.com/prettier/prettier/pull/6816 +[#6833]: https://github.com/prettier/prettier/pull/6833 [@andersk]: https://github.com/andersk [@ascorbic]: https://github.com/ascorbic [@bakkot]: https://gibhub.com/bakkot @@ -1542,6 +1558,7 @@ Thanks to [@fisker] for updating lots of Prettier’s dependencies! [@fisker]: https://github.com/fisker [@g-harel]: https://github.com/g-harel [@gavinjoyce]: https://github.com/gavinjoyce +[@gkz]: https://github.com/gkz [@ikatyang]: https://github.com/ikatyang/ [@jjaffeux]: https://github.com/jjaffeux [@jounqin]: https://github.com/JounQin From 1d9a3c27542b1c5bfcd6b70bd955a8c538c23597 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 8 Nov 2019 17:26:36 +0100 Subject: [PATCH 06/13] Organize changelog entries added recently --- website/blog/2019-11-03-1.19.0.md | 108 +++++++++++++++--------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/website/blog/2019-11-03-1.19.0.md b/website/blog/2019-11-03-1.19.0.md index c6ff69d73a13..0744a7271334 100644 --- a/website/blog/2019-11-03-1.19.0.md +++ b/website/blog/2019-11-03-1.19.0.md @@ -134,7 +134,7 @@ addTen(2); // 12 let newScore = player.score |> add(7, ?) |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`. ``` -#### JavaScript: Update `??` precedence to match stage 3 proposal ([#6404] by [@vjeux], [#6863] by [@jridgewell]) +#### Update `??` precedence to match stage 3 proposal ([#6404] by [@vjeux], [#6863] by [@jridgewell]) We've updated Prettier's support for the nullish coalescing operator to match a spec update that no longer allows it to immediately contain, or be contained within an `&&` or `||` operation. @@ -1026,6 +1026,36 @@ const bigints = [200000n, 0x0000000an, 0b01111111n]; const bigints = [200_000n, 0x0000_000an, 0b0111_1111n]; ``` +#### Better formatting for inline `await` expression nested in calls ([#6856] by [@thorn0]) + + +```js +// Input +async function f() { + const admins = (await(db.select('*').from('admins').leftJoin('bla').where('id', 'in', [1,2,3,4]))).map(({id, name})=>({id, name})) +} + +// Prettier 1.18 +async function f() { + const admins = (await db + .select("*") + .from("admins") + .leftJoin("bla") + .where("id", "in", [1, 2, 3, 4])).map(({ id, name }) => ({ id, name })); +} + +// Prettier 1.19 +async function f() { + const admins = ( + await db + .select("*") + .from("admins") + .leftJoin("bla") + .where("id", "in", [1, 2, 3, 4]) + ).map(({ id, name }) => ({ id, name })); +} +``` + ### HTML #### Don't wrap `template` elements on lines shorter than `printWidth` ([#6284] by [@sosukesuzuki]) @@ -1437,6 +1467,22 @@ SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag. Did you 123 ``` +### Less + +#### Don't lowercase variable names and remove whitespace between variable and colon ([#6778] by [@fisker]) + + +```less +// Input +@FoO : bar; + +// Prettier 1.18 +@foo : bar; + +// Prettier 1.19 +@FoO: bar; +``` + ### API #### Add `resolveConfig` option to `getFileInfo()` ([#6666] by [@kaicataldo]) @@ -1490,49 +1536,7 @@ Prior to this change, the CLI would resolve the config for a file before checkin This change relocates the config-resolution phase until after the file is confirmed to not be ignored. -### Other - -Thanks to [@fisker] for updating lots of Prettier’s dependencies! - -#### VS Code: add support for .mongo files ([#6848] by [@aymericbouzy]) - -When using the Azure Cosmos DB extension for VS Code, you can create .mongo files to write MongoDB queries, which use Javascript syntax. This change allows VS Code to format your file using Prettier. - -```js -db.users.find({ someField: { $exists: true } }); -``` - -#### JavaScript: Better formatting for inline `await` expression nested in calls ([#6856] by [@thorn0]) - - -```js -// Input -async function f() { - const admins = (await(db.select('*').from('admins').leftJoin('bla').where('id', 'in', [1,2,3,4]))).map(({id, name})=>({id, name})) -} - -// Prettier 1.18 -async function f() { - const admins = (await db - .select("*") - .from("admins") - .leftJoin("bla") - .where("id", "in", [1, 2, 3, 4])).map(({ id, name }) => ({ id, name })); -} - -// Prettier 1.19 -async function f() { - const admins = ( - await db - .select("*") - .from("admins") - .leftJoin("bla") - .where("id", "in", [1, 2, 3, 4]) - ).map(({ id, name }) => ({ id, name })); -} -``` - -#### CLI: Display invalid config filename in error message ([#6865] by [@fisker]) +#### Display invalid config filename in error message ([#6865] by [@fisker]) ``` @@ -1546,18 +1550,16 @@ Invalid configuration file: ... Invalid configuration file `.invalid-config`: ... ``` -#### Less: don't lowercase variable names, remove whitespace between variable and colon ([#6778] by [@fisker]) +### Other - -```less -// Input -@FoO : bar; +Thanks to [@fisker] for updating lots of Prettier’s dependencies! -// Prettier 1.18 -@foo : bar; +#### VS Code: add support for .mongo files ([#6848] by [@aymericbouzy]) -// Prettier 1.19 -@FoO: bar; +When using the Azure Cosmos DB extension for VS Code, you can create .mongo files to write MongoDB queries, which use Javascript syntax. This change allows VS Code to format your file using Prettier. + +```js +db.users.find({ someField: { $exists: true } }); ``` [#5682]: https://github.com/prettier/prettier/pull/5682 From 55271aab07e514134e26347bfe6c0eca66f54431 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 8 Nov 2019 21:33:58 +0100 Subject: [PATCH 07/13] Fix indent in cspell.json --- cspell.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cspell.json b/cspell.json index a94c0b965172..2dcef816911a 100644 --- a/cspell.json +++ b/cspell.json @@ -288,7 +288,7 @@ "React's", "readline", "readlines", - "rebalance", + "rebalance", "rebeccapurple", "recurse", "recurses", @@ -399,4 +399,4 @@ "ve{2,}r{2,}y", "ve+r+y+long\\w*" ] -} \ No newline at end of file +} From 3668d7e6516db44d2496b5d358dda152b5fe4f6f Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 8 Nov 2019 21:39:29 +0100 Subject: [PATCH 08/13] Update docs --- docs/integrating-with-linters.md | 2 +- website/versioned_docs/version-stable/api.md | 2 +- .../versioned_docs/version-stable/browser.md | 22 ++++++++++--------- .../version-stable/comparison.md | 4 ++-- .../version-stable/configuration.md | 2 +- .../versioned_docs/version-stable/index.md | 2 +- .../integrating-with-linters.md | 2 +- .../version-stable/technical-details.md | 2 +- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/docs/integrating-with-linters.md b/docs/integrating-with-linters.md index 57fa98f72a63..3264d4293c4f 100644 --- a/docs/integrating-with-linters.md +++ b/docs/integrating-with-linters.md @@ -124,7 +124,7 @@ Then in `tslint.json`: ### Disable formatting rules -[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your `devDependencies`, then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. +[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your [`devDependencies`], then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. ```bash yarn add --dev stylelint-config-prettier diff --git a/website/versioned_docs/version-stable/api.md b/website/versioned_docs/version-stable/api.md index 53276a878203..6b2ff844b35e 100644 --- a/website/versioned_docs/version-stable/api.md +++ b/website/versioned_docs/version-stable/api.md @@ -50,7 +50,7 @@ prettier.resolveConfig(filePath).then(options => { }); ``` -If `options.editorconfig` is `true` and an [`.editorconfig` file](http://editorconfig.org/) is in your project, Prettier will parse it and convert its properties to the corresponding prettier configuration. This configuration will be overridden by `.prettierrc`, etc. Currently, the following EditorConfig properties are supported: +If `options.editorconfig` is `true` and an [`.editorconfig` file](https://editorconfig.org/) is in your project, Prettier will parse it and convert its properties to the corresponding prettier configuration. This configuration will be overridden by `.prettierrc`, etc. Currently, the following EditorConfig properties are supported: - `end_of_line` - `indent_style` diff --git a/website/versioned_docs/version-stable/browser.md b/website/versioned_docs/version-stable/browser.md index 03fd05eb0f07..8933399545ef 100644 --- a/website/versioned_docs/version-stable/browser.md +++ b/website/versioned_docs/version-stable/browser.md @@ -4,7 +4,7 @@ title: Browser original_id: browser --- -Run Prettier in the browser with the `standalone.js` UMD bundle shipped in the NPM package (starting in version 1.13). The new UMD bundle only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins. +Run Prettier in the browser with the `standalone.js` UMD bundle shipped in the NPM package (starting in version 1.13). The UMD bundle only formats the code and has no support for config files, ignore files, CLI usage, or automatic loading of plugins. ### `prettier.format(code, options)` @@ -16,12 +16,14 @@ See [Usage](#usage) below for examples. ### Global - ```html - - - + + ``` @@ -41,8 +43,8 @@ prettier.format("query { }", { ```js define([ - "https://unpkg.com/prettier@1.13.0/standalone.js", - "https://unpkg.com/prettier@1.13.0/parser-graphql.js" + "https://unpkg.com/prettier@1.18.2/standalone.js", + "https://unpkg.com/prettier@1.18.2/parser-graphql.js" ], (prettier, ...plugins) => { prettier.format("query { }", { parser: "graphql", plugins }); }); @@ -61,7 +63,7 @@ This syntax doesn't necessarily work in the browser, but it can be used when bun ### Worker ```js -importScripts("https://unpkg.com/prettier@1.13.0/standalone.js"); -importScripts("https://unpkg.com/prettier@1.13.0/parser-graphql.js"); +importScripts("https://unpkg.com/prettier@1.18.2/standalone.js"); +importScripts("https://unpkg.com/prettier@1.18.2/parser-graphql.js"); prettier.format("query { }", { parser: "graphql", plugins: prettierPlugins }); ``` diff --git a/website/versioned_docs/version-stable/comparison.md b/website/versioned_docs/version-stable/comparison.md index f356e2eec3b6..8d02eff6bef0 100644 --- a/website/versioned_docs/version-stable/comparison.md +++ b/website/versioned_docs/version-stable/comparison.md @@ -8,10 +8,10 @@ original_id: comparison Linters have two categories of rules: -**Formatting rules**: eg: [max-len](http://eslint.org/docs/rules/max-len), [no-mixed-spaces-and-tabs](http://eslint.org/docs/rules/no-mixed-spaces-and-tabs), [keyword-spacing](http://eslint.org/docs/rules/keyword-spacing), [comma-style](http://eslint.org/docs/rules/comma-style)... +**Formatting rules**: eg: [max-len](https://eslint.org/docs/rules/max-len), [no-mixed-spaces-and-tabs](https://eslint.org/docs/rules/no-mixed-spaces-and-tabs), [keyword-spacing](https://eslint.org/docs/rules/keyword-spacing), [comma-style](https://eslint.org/docs/rules/comma-style)... Prettier alleviates the need for this whole category of rules! Prettier is going to reprint the entire program from scratch in a consistent way, so it's not possible for the programmer to make a mistake there anymore :) -**Code-quality rules**: eg [no-unused-vars](http://eslint.org/docs/rules/no-unused-vars), [no-extra-bind](http://eslint.org/docs/rules/no-extra-bind), [no-implicit-globals](http://eslint.org/docs/rules/no-implicit-globals), [prefer-promise-reject-errors](http://eslint.org/docs/rules/prefer-promise-reject-errors)... +**Code-quality rules**: eg [no-unused-vars](https://eslint.org/docs/rules/no-unused-vars), [no-extra-bind](https://eslint.org/docs/rules/no-extra-bind), [no-implicit-globals](https://eslint.org/docs/rules/no-implicit-globals), [prefer-promise-reject-errors](https://eslint.org/docs/rules/prefer-promise-reject-errors)... Prettier does nothing to help with those kind of rules. They are also the most important ones provided by linters as they are likely to catch real bugs with your code! diff --git a/website/versioned_docs/version-stable/configuration.md b/website/versioned_docs/version-stable/configuration.md index 9028ed59ed3c..384c82f81dd0 100644 --- a/website/versioned_docs/version-stable/configuration.md +++ b/website/versioned_docs/version-stable/configuration.md @@ -64,7 +64,7 @@ singleQuote = true Overrides let you have different configuration for certain file extensions, folders and specific files. -Prettier borrows ESLint’s [override format](http://eslint.org/docs/user-guide/configuring#example-configuration). +Prettier borrows ESLint’s [override format](https://eslint.org/docs/user-guide/configuring#example-configuration). JSON: diff --git a/website/versioned_docs/version-stable/index.md b/website/versioned_docs/version-stable/index.md index 0de7d5d10abf..c373e77e5f59 100644 --- a/website/versioned_docs/version-stable/index.md +++ b/website/versioned_docs/version-stable/index.md @@ -19,7 +19,7 @@ Prettier is an opinionated code formatter with support for: - [Markdown](https://commonmark.org/), including [GFM](https://github.github.com/gfm/) and [MDX](https://mdxjs.com/) - [YAML](https://yaml.org/) -It removes all original styling[\*](#footnotes) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter)) +It removes all original styling[\*](#footnotes) and ensures that all outputted code conforms to a consistent style. (See this [blog post](https://jlongster.com/A-Prettier-Formatter)) Prettier takes your code and reprints it from scratch by taking the line length into account. diff --git a/website/versioned_docs/version-stable/integrating-with-linters.md b/website/versioned_docs/version-stable/integrating-with-linters.md index e310e0e1bbc9..a6b762f5bf57 100644 --- a/website/versioned_docs/version-stable/integrating-with-linters.md +++ b/website/versioned_docs/version-stable/integrating-with-linters.md @@ -125,7 +125,7 @@ Then in `tslint.json`: ### Disable formatting rules -[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your `devDependencies`, then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. +[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your [`devDependencies`], then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. ```bash yarn add --dev stylelint-config-prettier diff --git a/website/versioned_docs/version-stable/technical-details.md b/website/versioned_docs/version-stable/technical-details.md index 48259bfd9816..253fdab69623 100644 --- a/website/versioned_docs/version-stable/technical-details.md +++ b/website/versioned_docs/version-stable/technical-details.md @@ -4,7 +4,7 @@ title: Technical Details original_id: technical-details --- -This printer is a fork of [recast](https://github.com/benjamn/recast)'s printer with its algorithm replaced by the one described by Wadler in "[A prettier printer](http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)". There still may be leftover code from recast that needs to be cleaned up. +This printer is a fork of [recast](https://github.com/benjamn/recast)'s printer with its algorithm replaced by the one described by Wadler in "[A prettier printer](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)". There still may be leftover code from recast that needs to be cleaned up. The basic idea is that the printer takes an AST and returns an intermediate representation of the output, and the printer uses that to generate a string. The advantage is that the printer can "measure" the IR and see if the output is going to fit on a line, and break if not. From 69c6d6476bc73415236a22e23e18f6fe03d49d4b Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 8 Nov 2019 22:33:50 +0100 Subject: [PATCH 09/13] Update release date --- website/blog/{2019-11-03-1.19.0.md => 2019-11-08-1.19.0.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/blog/{2019-11-03-1.19.0.md => 2019-11-08-1.19.0.md} (100%) diff --git a/website/blog/2019-11-03-1.19.0.md b/website/blog/2019-11-08-1.19.0.md similarity index 100% rename from website/blog/2019-11-03-1.19.0.md rename to website/blog/2019-11-08-1.19.0.md From 8de26e1a3e1b378322e3db58c228d59c9a169ad5 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 8 Nov 2019 22:41:51 +0100 Subject: [PATCH 10/13] Final fixes --- website/blog/2019-11-08-1.19.0.md | 83 ++++++++++++++++--------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/website/blog/2019-11-08-1.19.0.md b/website/blog/2019-11-08-1.19.0.md index 234fa6f2c2a3..de0e050fbc06 100644 --- a/website/blog/2019-11-08-1.19.0.md +++ b/website/blog/2019-11-08-1.19.0.md @@ -134,47 +134,6 @@ addTen(2); // 12 let newScore = player.score |> add(7, ?) |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`. ``` -#### Update `??` precedence to match stage 3 proposal ([#6404] by [@vjeux], [#6863] by [@jridgewell]) - -We've updated Prettier's support for the nullish coalescing operator to match a spec update that no longer allows it to immediately contain, or be contained within an `&&` or `||` operation. - - -```js -// Input -(foo ?? bar) || baz; -(foo || bar) ?? baz; - -// Prettier 1.18 -foo ?? bar || baz; -foo || bar ?? baz; - -// Prettier 1.19 -(foo ?? bar) || baz; -(foo || bar) ?? baz; -``` - -Please note that since we have updated our parsers with versions that support this spec update, code without the parentheses will throw a parse error. - -#### Don't require parens for same-operator logical expressions ([#6864] by [@jridgewell]) - - -```js -// Input -foo && (bar && baz); -foo || (bar || baz); -foo ?? (bar ?? baz); - -// Prettier 1.18 -foo && (bar && baz); -foo || (bar || baz); -foo ?? (bar ?? baz); - -// Prettier 1.19 -foo && bar && baz; -foo || bar || baz; -foo ?? bar ?? baz; -``` - #### Use function literals in arguments to detect function composition ([#6033] by [@brainkim]) Previously, we used a set of hard-coded names related to functional programming (`compose`, `flow`, `pipe`, etc.) to detect function composition and chaining patterns in code. This was done so that Prettier would not put code like the following call to `pipe` on the same line even if it fit within the allotted column budget: @@ -687,6 +646,47 @@ new Map([ ]); ``` +#### Update `??` precedence to match stage 3 proposal ([#6404] by [@vjeux], [#6863] by [@jridgewell]) + +We've updated Prettier's support for the nullish coalescing operator to match a spec update that no longer allows it to immediately contain, or be contained within an `&&` or `||` operation. + + +```js +// Input +(foo ?? bar) || baz; +(foo || bar) ?? baz; + +// Prettier 1.18 +foo ?? bar || baz; +foo || bar ?? baz; + +// Prettier 1.19 +(foo ?? bar) || baz; +(foo || bar) ?? baz; +``` + +Please note that since we have updated our parsers with versions that support this spec update, code without the parentheses will throw a parse error. + +#### Don't require parens for same-operator logical expressions ([#6864] by [@jridgewell]) + + +```js +// Input +foo && (bar && baz); +foo || (bar || baz); +foo ?? (bar ?? baz); + +// Prettier 1.18 +foo && (bar && baz); +foo || (bar || baz); +foo ?? (bar ?? baz); + +// Prettier 1.19 +foo && bar && baz; +foo || bar || baz; +foo ?? bar ?? baz; +``` + #### More readable parentheses for `new` call ([#6412] by [@bakkot]) @@ -1688,6 +1688,7 @@ db.users.find({ someField: { $exists: true } }); [@gavinjoyce]: https://github.com/gavinjoyce [@gkz]: https://github.com/gkz [@ikatyang]: https://github.com/ikatyang/ +[@jamesreggio]: https://github.com/jamesreggio [@jjaffeux]: https://github.com/jjaffeux [@jounqin]: https://github.com/JounQin [@jridgewell]: https://github.com/jridgewell From 18595d396156d610464df429b8c5995dc599629d Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 8 Nov 2019 22:45:10 +0100 Subject: [PATCH 11/13] Fix comment --- changelog_unreleased/TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog_unreleased/TEMPLATE.md b/changelog_unreleased/TEMPLATE.md index c5886b13a4d8..a7ebe3c0aaa9 100644 --- a/changelog_unreleased/TEMPLATE.md +++ b/changelog_unreleased/TEMPLATE.md @@ -16,7 +16,7 @@ 6. Change ```jsx to your language. For example, ```yaml. -7. Change the `// Input` and `// Output` comments to the comment syntax of your language. For example, `# Input`. +7. Change the `// Input` and `// Prettier` comments to the comment syntax of your language. For example, `# Input`. 8. Choose some nice input example code. Paste it along with the output before and after your PR. From 116454694fd7df0ed657909d700f9712ca0f0274 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 9 Nov 2019 01:20:13 +0100 Subject: [PATCH 12/13] Bump date --- website/blog/{2019-11-08-1.19.0.md => 2019-11-09-1.19.0.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/blog/{2019-11-08-1.19.0.md => 2019-11-09-1.19.0.md} (100%) diff --git a/website/blog/2019-11-08-1.19.0.md b/website/blog/2019-11-09-1.19.0.md similarity index 100% rename from website/blog/2019-11-08-1.19.0.md rename to website/blog/2019-11-09-1.19.0.md From 12c410d29aced199747c0472dffd9b86db88da72 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 9 Nov 2019 01:20:56 +0100 Subject: [PATCH 13/13] Update docs --- .../version-stable/integrating-with-linters.md | 2 +- website/versioned_docs/version-stable/rationale.md | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/website/versioned_docs/version-stable/integrating-with-linters.md b/website/versioned_docs/version-stable/integrating-with-linters.md index e310e0e1bbc9..a6b762f5bf57 100644 --- a/website/versioned_docs/version-stable/integrating-with-linters.md +++ b/website/versioned_docs/version-stable/integrating-with-linters.md @@ -125,7 +125,7 @@ Then in `tslint.json`: ### Disable formatting rules -[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your `devDependencies`, then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. +[`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your [`devDependencies`], then extend from it within your `.stylelintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. ```bash yarn add --dev stylelint-config-prettier diff --git a/website/versioned_docs/version-stable/rationale.md b/website/versioned_docs/version-stable/rationale.md index 0a68fdee33b7..292931df8b32 100644 --- a/website/versioned_docs/version-stable/rationale.md +++ b/website/versioned_docs/version-stable/rationale.md @@ -133,9 +133,11 @@ One final thing: TC39 has [not yet decided if decorators come before or after `e ```js @decorator -export class Foo { } +export class Foo {} -export @decorator class Foo { } +export +@decorator +class Foo {} ``` ### Semicolons