diff --git a/changelog_unreleased/blog-post-intro.md b/changelog_unreleased/blog-post-intro.md new file mode 100644 index 000000000..0bde962fd --- /dev/null +++ b/changelog_unreleased/blog-post-intro.md @@ -0,0 +1,31 @@ +--- +author: "Sosuke Suzuki (@sosukesuzuki)" +authorURL: "https://github.com/sosukesuzuki" +title: "Prettier 2.6: new singleAttributePerLine option and new JavaScript features!" +--- + +This release includes a new `singleAttributePerLine` option. This is an option to print only one attribute per line in Vue SFC templates, HTML, and JSX. Per our [Option Philosophy](https://prettier.io/docs/en/option-philosophy.html), we would prefer not to add such an option. However, there are many users who want this feature, and major style guides like [Airbnb’s JavaScript Style Guide](https://github.com/airbnb/javascript/blob/274c8d570155a05b016980294d4204c5711bce86/packages/eslint-config-airbnb/rules/react.js#L97-L99) and [Vue’s style guide](https://vuejs.org/style-guide/rules-strongly-recommended.html#multi-attribute-elements) recommend the single attribute per line style. A [PR](https://github.com/prettier/prettier/pull/6644) to add this feature was opened in October 2019, and both it and the [corresponding issue](https://github.com/prettier/prettier/issues/5501) have received a significant amount of support from users. For us it was a hard decision to add this option. We hope the addition of this option will benefit many users without significantly harming our principles. + +We've also added support formatting for some new JavaScript syntax proposals via Babel. + + + +## Thanks to our sponsors! + +As discussed in [a blog post from earlier this year](https://prettier.io/blog/2022/01/06/prettier-begins-paying-maintainers.html), we have begun paying our maintainers from funds received from our sponsors. We would like to thank our many sponsors who have made this possible! We’re especially grateful to the following companies and individuals, who have donated over $1,000 to us: + +- [Frontend Masters](https://frontendmasters.com/) +- [Salesforce](https://www.salesforce.com/) +- [Indeed](https://indeed.com/) +- [Sentry](https://sentry.io/welcome/) +- [Airbnb](https://www.airbnb.com/) +- [LINE](https://engineering.linecorp.com/en/) +- [AMP Project](https://www.ampproject.org/) +- [InVision AG](https://www.ivx.com/) +- [Ubie](https://ubiehealth.com/) +- [Shogun Labs, Inc](https://getshogun.com/) +- [Underbelly](https://www.underbelly.is/) +- [Principal Financial Group](https://www.principal.com/about-us) +- [Suhail Doshi](https://twitter.com/suhail) + +If you enjoy Prettier and would like to support our work, consider sponsoring us directly via [our OpenCollective](https://opencollective.com/prettier) or by sponsoring the projects we depend on, including [typescript-eslint](https://opencollective.com/typescript-eslint), [remark](https://opencollective.com/unified), and [Babel](https://opencollective.com/babel). diff --git a/changelog_unreleased/cli/10274.md b/changelog_unreleased/cli/10274.md index 4c810005e..a2cbe3191 100644 --- a/changelog_unreleased/cli/10274.md +++ b/changelog_unreleased/cli/10274.md @@ -1,4 +1,4 @@ -#### Add `--no-plugin-search` to turn off plugin autoloading (#10274 by @fisker) +#### Add `--no-plugin-search` option to turn off plugin autoloading (#10274 by @fisker) To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI or add `{ pluginSearchDirs: false }` to options in `prettier.format()` or to the config file. diff --git a/changelog_unreleased/css/12210.md b/changelog_unreleased/css/12210.md index 7b597087e..00b326557 100644 --- a/changelog_unreleased/css/12210.md +++ b/changelog_unreleased/css/12210.md @@ -1,6 +1,6 @@ -#### Preserve empty line in CSS paren groups (#12210 by @duailibe) +#### Preserve blank lines in SCSS maps (#12210 by @duailibe) - +This change also applies to some PostCSS features with similar syntax. ```css diff --git a/changelog_unreleased/html/6644.md b/changelog_unreleased/html/6644.md index 7e12acbf1..ec9899c55 100644 --- a/changelog_unreleased/html/6644.md +++ b/changelog_unreleased/html/6644.md @@ -1,4 +1,4 @@ -#### Enforce Single Attribute Per Line (#6644 by @kankje) +#### [HIGHLIGHT]Enforce Single Attribute Per Line (#6644 by @kankje) Added the `singleAttributePerLine` option for specifying if Prettier should enforce single attribute per line in HTML, Vue and JSX. diff --git a/changelog_unreleased/javascript/12017.md b/changelog_unreleased/javascript/12017.md index 726ce45c5..daf90bba6 100644 --- a/changelog_unreleased/javascript/12017.md +++ b/changelog_unreleased/javascript/12017.md @@ -1,4 +1,4 @@ -#### Preserve end-of-line comment for if statements without blocks (#12017 by @sosukesuzuki) +#### Preserve end-of-line comments after if statements without blocks (#12017 by @sosukesuzuki) ```jsx diff --git a/changelog_unreleased/javascript/12075.md b/changelog_unreleased/javascript/12075.md index 4b136d048..594de4749 100644 --- a/changelog_unreleased/javascript/12075.md +++ b/changelog_unreleased/javascript/12075.md @@ -1,6 +1,4 @@ -#### Print end-of-line comment for `continue`/`break` statements (#12075 by @sosukesuzuki) - - +#### Print end-of-line comments for `continue`/`break` statements (#12075 by @sosukesuzuki) ```jsx diff --git a/changelog_unreleased/javascript/12241.md b/changelog_unreleased/javascript/12241.md index 2c8edf8a7..61ca01b97 100644 --- a/changelog_unreleased/javascript/12241.md +++ b/changelog_unreleased/javascript/12241.md @@ -1,8 +1,8 @@ -#### Support Unicode Set Notation proposal (#12241 by @fisker) +#### Add support for Unicode Set Notation in regular expressions (#12241 by @fisker) -Support [Stage 3 proposal Unicode Set Notation](https://github.com/tc39/proposal-regexp-set-notation/) via [Babel 7.17.0](https://babeljs.io/blog/2022/02/02/7.17.0). +The Stage 3 proposal for [Unicode Set Notation](https://github.com/tc39/proposal-regexp-set-notation/) in regular expressions is now supported via [Babel 7.17.0](https://babeljs.io/blog/2022/02/02/7.17.0). -See [the release blog post of Babel v7.17.0](https://babeljs.io/blog/2022/02/02/7.17.0#regexp-set-notation-and-properties-of-strings-14125httpsgithubcombabelbabelpull14125) and [the README of this proposal](https://github.com/tc39/proposal-regexp-set-notation/) for details. +See [the release blog post of Babel v7.17.0](https://babeljs.io/blog/2022/02/02/7.17.0#regexp-set-notation-and-properties-of-strings-14125httpsgithubcombabelbabelpull14125) and [the README of this proposal](https://github.com/tc39/proposal-regexp-set-notation/) for details. Also keep in mind our [policy on non-standardized syntax](https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax) before using this proposed syntax feature with Prettier. ```jsx diff --git a/changelog_unreleased/javascript/12268.md b/changelog_unreleased/javascript/12268.md index 7450c9665..a36d863e6 100644 --- a/changelog_unreleased/javascript/12268.md +++ b/changelog_unreleased/javascript/12268.md @@ -24,7 +24,7 @@ type Props = }; ``` -And for TS that comment would not be stable with a second format: +This change also fixes an issue where a similarly-placed comment in TypeScript would be moved again after a second formatting operation: ```ts diff --git a/changelog_unreleased/javascript/12276.md b/changelog_unreleased/javascript/12276.md index e6ea8c2f2..db5f49b76 100644 --- a/changelog_unreleased/javascript/12276.md +++ b/changelog_unreleased/javascript/12276.md @@ -1,6 +1,6 @@ -#### Support destructuring private proposal (#12276 by @sosukesuzuki) +#### Add support for destructuring of private fields (#12276 by @sosukesuzuki) -Support [Stage 2 TC39 proposal destructuring private fields](https://github.com/tc39/proposal-destructuring-private) via [Babel 7.17](https://babeljs.io/blog/2022/02/02/7.17.0). +The Stage 2 TC39 proposal for [destructuring of private fields](https://github.com/tc39/proposal-destructuring-private) is now supported via [Babel 7.17](https://babeljs.io/blog/2022/02/02/7.17.0). Please read our [policy on non-standardized syntax](https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax) before you decide to use this proposed syntax feature with Prettier. ```jsx diff --git a/changelog_unreleased/javascript/12299.md b/changelog_unreleased/javascript/12299.md index a8cd28519..46d941dc7 100644 --- a/changelog_unreleased/javascript/12299.md +++ b/changelog_unreleased/javascript/12299.md @@ -1,6 +1,6 @@ #### Support decorator auto accessors syntax (#12299 by @sosukesuzuki) -Support auto accessors syntax that is introduced in [new decorators proposal](https://github.com/tc39/proposal-decorators). +Support auto accessors syntax that is introduced in [new decorators proposal](https://github.com/tc39/proposal-decorators). Please read our [policy on non-standardized syntax](https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax) before you decide to use this proposed syntax feature with Prettier. ```jsx diff --git a/changelog_unreleased/misc/.gitkeep b/changelog_unreleased/misc/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/changelog_unreleased/misc/12055.md b/changelog_unreleased/misc/12055.md new file mode 100644 index 000000000..7ba3bb93d --- /dev/null +++ b/changelog_unreleased/misc/12055.md @@ -0,0 +1,3 @@ +#### Switch to `esbuild` (#12055 by @fisker) + +We've switched our build process from Rollup to [esbuild](https://esbuild.github.io). esbuild is much faster and has improved our development experience. This is an internal change and should not affect users. If something isn’t working for you after upgrading, please [open an issue](https://github.com/prettier/prettier/issues/new?assignees=&labels=&template=integration.md)! diff --git a/changelog_unreleased/typescript/12351.md b/changelog_unreleased/typescript/12351.md index 11f0276d2..f10b5cc7b 100644 --- a/changelog_unreleased/typescript/12351.md +++ b/changelog_unreleased/typescript/12351.md @@ -1,6 +1,6 @@ #### Refactor printing definite assignment assertions (#12351 by @thorn0) -Also now definite assignment assertions are printed even when they aren't followed by type annotations, which is an error in TS but not a parse error. +Definite assignment assertions are now printed even when they aren't followed by type annotations. This is an error in TypeScript, but TS is still able to parse the file. ```ts diff --git a/changelog_unreleased/typescript/12390.md b/changelog_unreleased/typescript/12390.md index 21be549b9..4a7296a6e 100644 --- a/changelog_unreleased/typescript/12390.md +++ b/changelog_unreleased/typescript/12390.md @@ -1,7 +1,7 @@ #### Print trailing comma for rest elements in tuple types (#12390 by @sosukesuzuki) -TypeScript allows to put rest elements in places other than the end of tuple types since [4.2](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#leadingmiddle-rest-elements-in-tuple-types). -Prettier now prints a trailing comma for the trailing rest element as the it may be followed by the next element. +TypeScript has allowed rest elements in tuple types (`...T`) to have normal elements come after them since [TypeScript 4.2](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#leadingmiddle-rest-elements-in-tuple-types). +Prettier now prints a trailing comma for the trailing rest element (when trailing commas are enabled) for consistency and to reduce diffs if you decide to add more elements after the final element in the future. ```tsx diff --git a/changelog_unreleased/typescript/12400.md b/changelog_unreleased/typescript/12400.md new file mode 100644 index 000000000..31f89f98a --- /dev/null +++ b/changelog_unreleased/typescript/12400.md @@ -0,0 +1,3 @@ +#### [HIGHLIGHT]TypeScript 4.6 support (#12400 by @dependabot) + +We’ve updated the version of TypeScript that we use to parse TS code to [TypeScript 4.6](https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/). However, no new syntax was added in this release of TypeScript so we have not had to make any other changes. diff --git a/cspell.json b/cspell.json index 689fff064..d9f69aeb1 100644 --- a/cspell.json +++ b/cspell.json @@ -80,6 +80,7 @@ "doctag", "Dodds", "Dolzhykov", + "Doshi", "dotfile", "dotfiles", "duailibe", @@ -309,6 +310,7 @@ "Stylesheet", "subvalue", "suchipi", + "Suhail", "supertypes", "Supprimer", "swcrc", @@ -327,6 +329,7 @@ "typecasted", "typecheck", "typeof", + "Ubie", "Umidbek", "unaries", "uncook", diff --git a/scripts/draft-blog-post.mjs b/scripts/draft-blog-post.mjs index 03ba75d19..91bdb26a3 100644 --- a/scripts/draft-blog-post.mjs +++ b/scripts/draft-blog-post.mjs @@ -49,6 +49,7 @@ const categories = [ { dir: "yaml", title: "YAML" }, { dir: "api", title: "API" }, { dir: "cli", title: "CLI" }, + { dir: "misc", title: "Miscellaneous" }, ]; const categoriesByDir = new Map( @@ -68,12 +69,17 @@ for (const dir of changelogUnreleasedDirs) { rimraf.sync(postGlob); +const introFileData = fs.readFileSync(introFile, "utf8").trim(); + +const TRUNCATE_COMMENT = ""; +const shouldPrintTruncate = introFileData.includes(TRUNCATE_COMMENT); + fs.writeFileSync( postFile, replaceVersions( [ - fs.readFileSync(introFile, "utf8").trim(), - "", + introFileData, + shouldPrintTruncate ? TRUNCATE_COMMENT : "", ...printEntriesWithTitle({ title: "Highlights", filter: (entry) => entry.section === "highlight", @@ -90,7 +96,9 @@ fs.writeFileSync( title: "Other Changes", filter: (entry) => !entry.section, }), - ].join("\n\n") + "\n", + ] + .filter(Boolean) + .join("\n\n") + "\n", previousVersion, version ) diff --git a/scripts/utils/changelog-categories.mjs b/scripts/utils/changelog-categories.mjs index 6bd6fccc3..a5b25175b 100644 --- a/scripts/utils/changelog-categories.mjs +++ b/scripts/utils/changelog-categories.mjs @@ -17,4 +17,5 @@ export const CHANGELOG_CATEGORIES = [ "typescript", "vue", "yaml", + "misc", ]; diff --git a/website/blog/2022-03-16-2.6.0.md b/website/blog/2022-03-16-2.6.0.md new file mode 100644 index 000000000..03f618864 --- /dev/null +++ b/website/blog/2022-03-16-2.6.0.md @@ -0,0 +1,826 @@ +--- +author: "Sosuke Suzuki (@sosukesuzuki)" +authorURL: "https://github.com/sosukesuzuki" +title: "Prettier 2.6: new singleAttributePerLine option and new JavaScript features!" +--- + +This release includes a new `singleAttributePerLine` option. This is an option to print only one attribute per line in Vue SFC templates, HTML, and JSX. Per our [Option Philosophy](https://prettier.io/docs/en/option-philosophy.html), we would prefer not to add such an option. However, there are many users who want this feature, and major style guides like [Airbnb’s JavaScript Style Guide](https://github.com/airbnb/javascript/blob/274c8d570155a05b016980294d4204c5711bce86/packages/eslint-config-airbnb/rules/react.js#L97-L99) and [Vue’s style guide](https://vuejs.org/style-guide/rules-strongly-recommended.html#multi-attribute-elements) recommend the single attribute per line style. A [PR](https://github.com/prettier/prettier/pull/6644) to add this feature was opened in October 2019, and both it and the [corresponding issue](https://github.com/prettier/prettier/issues/5501) have received a significant amount of support from users. For us it was a hard decision to add this option. We hope the addition of this option will benefit many users without significantly harming our principles. + +We've also added support formatting for some new JavaScript syntax proposals via Babel. + + + +## Thanks to our sponsors! + +As discussed in [a blog post from earlier this year](https://prettier.io/blog/2022/01/06/prettier-begins-paying-maintainers.html), we have begun paying our maintainers from funds received from our sponsors. We would like to thank our many sponsors who have made this possible! We’re especially grateful to the following companies and individuals, who have donated over $1,000 to us: + +- [Frontend Masters](https://frontendmasters.com/) +- [Salesforce](https://www.salesforce.com/) +- [Indeed](https://indeed.com/) +- [Sentry](https://sentry.io/welcome/) +- [Airbnb](https://www.airbnb.com/) +- [LINE](https://engineering.linecorp.com/en/) +- [AMP Project](https://www.ampproject.org/) +- [InVision AG](https://www.ivx.com/) +- [Ubie](https://ubiehealth.com/) +- [Shogun Labs, Inc](https://getshogun.com/) +- [Underbelly](https://www.underbelly.is/) +- [Principal Financial Group](https://www.principal.com/about-us) +- [Suhail Doshi](https://twitter.com/suhail) + +If you enjoy Prettier and would like to support our work, consider sponsoring us directly via [our OpenCollective](https://opencollective.com/prettier) or by sponsoring the projects we depend on, including [typescript-eslint](https://opencollective.com/typescript-eslint), [remark](https://opencollective.com/unified), and [Babel](https://opencollective.com/babel). + + + +## Highlights + +### TypeScript + +#### TypeScript 4.6 support ([#12400](https://github.com/prettier/prettier/pull/12400) by [@dependabot](https://github.com/dependabot)) + +We’ve updated the version of TypeScript that we use to parse TS code to [TypeScript 4.6](https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/). However, no new syntax was added in this release of TypeScript so we have not had to make any other changes. + +### HTML + +#### Enforce Single Attribute Per Line ([#6644](https://github.com/prettier/prettier/pull/6644) by [@kankje](https://github.com/kankje)) + +Added the `singleAttributePerLine` option for specifying if Prettier should enforce single attribute per line in HTML, Vue and JSX. + + +```html + +
\
+\\
+\\\
+ +{{! Prettier 2.5 }} +\\
+\\\
+\\\\
+ +{{! Prettier 2.6 }} +\
+\\
+\\\
+``` + +### GraphQL + +#### Print descriptions on graphql schema definition nodes ([#11901](https://github.com/prettier/prettier/pull/11901) by [@trevor-scheer](https://github.com/trevor-scheer)) + + +```graphql +# Input +"""SchemaDefinition description is lost""" +schema { + query: Query +} + +# Prettier 2.5 +schema { + query: Query +} + +# Prettier 2.6 +""" +SchemaDefinition description is lost +""" +schema { + query: Query +} + +``` + +### YAML + +#### Fix unexpected deletion of block-literal lines which starts with U+3000 ([#12305](https://github.com/prettier/prettier/pull/12305) by [@Quramy](https://github.com/Quramy)) + + +```yaml +# Input +block_with_ideographic_space: | + line-content # This line starts with U+3000 + +# Prettier 2.5 +block_with_ideographic_space: | + +// Prettier 2.6 +block_with_ideographic_space: | + line-content # This line starts with U+3000 +``` + +### CLI + +#### Add `--no-plugin-search` option to turn off plugin autoloading ([#10274](https://github.com/prettier/prettier/pull/10274) by [@fisker](https://github.com/fisker)) + +To turn off plugin autoloading, use `--no-plugin-search` when using Prettier CLI or add `{ pluginSearchDirs: false }` to options in `prettier.format()` or to the config file. + + +```cli +// Prettier 2.5 +$ prettier . --plugin-search-dir=a-dir-without-plugins + +// Prettier 2.6 +$ prettier . --no-plugin-search +``` + +#### Infer parser for `.swcrc` ([#12320](https://github.com/prettier/prettier/pull/12320) by [@sosukesuzuki](https://github.com/sosukesuzuki)) + +A [`.swcrc`](https://swc.rs/docs/configuration/swcrc) is handled using `json` parser. + +### Miscellaneous + +#### Switch to `esbuild` ([#12055](https://github.com/prettier/prettier/pull/12055) by [@fisker](https://github.com/fisker)) + +We've switched our build process from Rollup to [esbuild](https://esbuild.github.io). esbuild is much faster and has improved our development experience. This is an internal change and should not affect users. If something isn’t working for you after upgrading, please [open an issue](https://github.com/prettier/prettier/issues/new?assignees=&labels=&template=integration.md)!