惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

Prettier Blog

Prettier 3.8: Support for Angular v21.1 Prettier 3.7: Improved formatting consistency and new plugin features! Prettier 3.6: Experimental fast CLI and new OXC and Hermes plugins! Prettier 3.5: New objectWrap option, experimentalOperatorPosition option and TS config file support! Prettier 3.4: A lot of bug fixes Prettier 3.3: New Flow features and a lot of bug fixes Prettier 3.2: Support JSONC and Angular’s ICU expression Prettier's CLI: A Performance Deep Dive $20k Bounty was Claimed! Prettier 3.1: New experimental ternaries formatting and Angular control flow syntax! A curious case of the ternaries Prettier 3.0: Hello, ECMAScript Modules! Prettier 2.8: improve --cache CLI option and TypeScript 4.9 satisfies operator! Prettier 2.7: new --cache CLI option and TypeScript 4.7 syntax! Prettier begins paying maintainers Prettier 2.5: TypeScript 4.5 and MDX v2 comment syntax! Prettier 2.4: new bracketSameLine option and TypeScript 4.4 support! Prettier 2.3. In which assignments are consistent, short keys non-breaking, and Handlebars official Prettier for Ruby goes v1.0 🎉
Prettier 2.6: new singleAttributePerLine option and new JavaScript features!
Sosuke Suzuki · 2022-03-16 · via Prettier Blog

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, 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 and Vue’s style guide recommend the single attribute per line style. A PR to add this feature was opened in October 2019, and both it and the corresponding issue 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.

As discussed in a blog post from earlier this year, 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:

If you enjoy Prettier and would like to support our work, consider sponsoring us directly via our OpenCollective or by sponsoring the projects we depend on, including typescript-eslint, remark, and Babel.

Highlights

TypeScript

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. 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 by @kankje)

Added the singleAttributePerLine option for specifying if Prettier should enforce single attribute per line in HTML, Vue and JSX.

<!-- Input -->

<div data-a="1">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<div data-a="1" data-b="2" data-c="3">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<!-- Prettier 2.5 -->

<div data-a="1">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<div data-a="1" data-b="2" data-c="3">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<!-- Prettier 2.6, with `{"singleAttributePerLine": false}` -->

<div data-a="1">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<div data-a="1" data-b="2" data-c="3">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<!-- Prettier 2.6, with `{"singleAttributePerLine": true}` -->

<div data-a="1">

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

<div

data-a="1"

data-b="2"

data-c="3"

>

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

</div>

Other Changes

JavaScript

Recognize waitForAsync as test-statement in Angular (#11992 by @HendrikN)

// Input

test("foo bar", waitForAsync(() => {

const foo = "bar";

expect(foo).toEqual("bar")

}));

// Prettier 2.5

test(

"foo bar",

waitForAsync(() => {

const foo = "bar";

expect(foo).toEqual("bar");

})

);

// Prettier 2.6

test("foo bar", waitForAsync(() => {

const foo = "bar";

expect(foo).toEqual("bar");

}));

// Input

if (condition1) expression1; // comment A

else if (condition2) expression2; // comment B

else expression3; // comment C

// Prettier 2.5

if (condition1) expression1;

// comment A

else if (condition2) expression2;

// comment B

else expression3; // comment C

// Prettier 2.6

if (condition1) expression1; // comment A

else if (condition2) expression2; // comment B

else expression3; // comment C

// Input

let foo: (

// comment

never

);

// Prettier 2.5

Error: Comment "comment" was not printed. Please report this error!

// Prettier 2.6

let foo: // comment

never;

// Input

for (;;) continue // comment

;

// Prettier 2.5

Error: Comment "comment" was not printed. Please report this error!

// Prettier 2.6

for (;;)

continue; // comment

Inline await expressions in JSX (#12088 & #12109 by @j-f1)

await expressions in JSX are now inlined if their argument would be inlined.

// Input

{await Promise.all(

someVeryLongExpression

)}

{await (

<div>Lorem ipsum ...</div>

)}

// Prettier 2.5

{

await Promise.all(

someVeryLongExpression

)

}

{

await (

<div>Lorem ipsum ...</div>

)

}

// Prettier 2.6

{await Promise.all(

someVeryLongExpression

)}

{await (

<div>Lorem ipsum ...</div>

)}

Add acorn parser (#12172 by @fisker)

A new value for the parser option has been added: acorn - A small, fast, JavaScript-based JavaScript parser.

Keep comments right after default cases (in switch statements) in the same line, when possible.

// Input

function read_statement() {

switch (peek_keyword()) {

case Keyword.impl: // impl<T> Growling<T> for Wolf {}

return ImplDeclaration.read();

default: // expression;

return ExpressionStatement.read();

}

}

// Prettier 2.5

function read_statement() {

switch (peek_keyword()) {

case Keyword.impl: // impl<T> Growling<T> for Wolf {}

return ImplDeclaration.read();

default:

// expression;

return ExpressionStatement.read();

}

}

// Prettier 2.6

function read_statement() {

switch (peek_keyword()) {

case Keyword.impl: // impl<T> Growling<T> for Wolf {}

return ImplDeclaration.read();

default: // expression;

return ExpressionStatement.read();

}

}

// Input

abstract class Foo {

abstract bar(

/** comment explaining userId param */

userId

)

}

// Prettier 2.5

abstract class Foo {

abstract bar(userId);

/** comment explaining userId param */

}

// Prettier 2.6

abstract class Foo {

abstract bar(

/** comment explaining userId param */

userId

);

}

Fix typecast of superclass in class declarations (#12222 & #12226 by @duailibe)

This was a combination of two separate bugs: moving the comments before the superclass and adding multiple parenthesis around the superclass.

// Input

class Foo extends /** @type {Type} */ (Bar) {}

// Prettier 2.5

class Foo /** @type {Type} */ extends ((Bar)) {}

// Prettier 2.6

class Foo extends /** @type {Type} */ (Bar) {}

Add support for Unicode Set Notation in regular expressions (#12241 by @fisker)

The Stage 3 proposal for Unicode Set Notation in regular expressions is now supported via Babel 7.17.0.

See the release blog post of Babel v7.17.0 and the README of this proposal for details. Also keep in mind our policy on non-standardized syntax before using this proposed syntax feature with Prettier.

// Examples

/[\p{Decimal_Number}--[0-9]]/v; // Non-ASCII decimal digits

"Did you see the 👩🏿‍❤️‍💋‍👩🏾 emoji?".match(/\p{RGI_Emoji}/v). // ["👩🏿‍❤️‍💋‍👩🏾"]

/[\r\n\q{\r\n|NEWLINE}]/v; // Matches \r, \n, \r\n or NEWLINE

Add parens to ClassExpression with decorators (#12260 by @fisker)

// Input

(@f() class {});

// Prettier 2.5

@f()

class {};

// Prettier 2.5 (Second format)

SyntaxError: A class name is required. (2:7)

1 | @f()

> 2 | class {};

| ^

3 |

// Prettier 2.6

(

@f()

class {}

);

For Flow, the comments will now be more aligned to how we print comments in assignments where the right-hand side is an object expression:

// Input

type Props = // comment explaining the props

{

isPlaying: boolean

};

// Prettier 2.5

// comment explaining the props

type Props = {

isPlaying: boolean,

};

// Prettier 2.6

type Props =

// comment explaining the props

{

isPlaying: boolean,

};

This change also fixes an issue where a similarly-placed comment in TypeScript would be moved again after a second formatting operation:

// Input

type Props = // comment explaining the props

{

isPlaying: boolean

};

// Prettier 2.5

type Props = { // comment explaining the props

isPlaying: boolean;

};

// Prettier 2.5 (2nd format)

type Props = {

// comment explaining the props

isPlaying: boolean;

};

// Prettier 2.6

type Props =

// comment explaining the props

{

isPlaying: boolean,

};

Add support for destructuring of private fields (#12276 by @sosukesuzuki)

The Stage 2 TC39 proposal for destructuring of private fields is now supported via Babel 7.17. Please read our policy on non-standardized syntax before you decide to use this proposed syntax feature with Prettier.

// Example

class Foo {

constructor() {

console.log(this.#x); // => 1

const { #x: x } = this;

console.log(x); // => 1

}

}

Support decorator auto accessors syntax (#12299 by @sosukesuzuki)

Support auto accessors syntax that is introduced in new decorators proposal. Please read our policy on non-standardized syntax before you decide to use this proposed syntax feature with Prettier.

// Example

@defineElement("my-class")

class C extends HTMLElement {

@reactive accessor clicked = false;

}

// Input

const kochabCooieGameOnOboleUnweave = // !!!

rhubarbRhubarb(annularCooeedSplicesWalksWayWay);

// Prettier 2.5, first format

const kochabCooieGameOnOboleUnweave = rhubarbRhubarb( // !!!

annularCooeedSplicesWalksWayWay

);

// Prettier 2.5, second format

const kochabCooieGameOnOboleUnweave = rhubarbRhubarb(

// !!!

annularCooeedSplicesWalksWayWay

);

// Prettier 2.6

const kochabCooieGameOnOboleUnweave = // !!!

rhubarbRhubarb(annularCooeedSplicesWalksWayWay);

TypeScript

Refactor printing definite assignment assertions (#12351 by @thorn0)

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.

// Input

let a!;

// Prettier 2.5

let a;

// Prettier 2.6

let a!;

TypeScript has allowed rest elements in tuple types (...T) to have normal elements come after them since TypeScript 4.2. 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.

// { trailingCommma: "all" }

// Input

type Foo = [

Element,

Element,

Element,

Element,

Element,

Element,

...RestElement,

];

// Prettier 2.5

type Foo = [

Element,

Element,

Element,

Element,

Element,

Element,

...RestElement

];

// Prettier 2.6

type Foo = [

Element,

Element,

Element,

Element,

Element,

Element,

...RestElement,

];

Flow

Fix Flow's class declaration's static indexer formatting (#12009 by @gkz)

// Input

declare class A {

static [string]: boolean;

}

// Prettier 2.5

declare class A {

[string]: boolean;

}

// Prettier 2.6

declare class A {

static [string]: boolean;

}

CSS

Preserve blank lines in SCSS maps (#12210 by @duailibe)

This change also applies to some PostCSS features with similar syntax.

/* Input */

$colours: (

"text": $light-100,

"background-primary": $dark-300,

"background-secondary": $dark-200,

"background-tertiary": $dark-100

);

/* Prettier 2.5 */

$colours: (

"text": $light-100,

"background-primary": $dark-300,

"background-secondary": $dark-200,

"background-tertiary": $dark-100

);

/* Prettier 2.6 */

$colours: (

"text": $light-100,

"background-primary": $dark-300,

"background-secondary": $dark-200,

"background-tertiary": $dark-100

);

Fix lowercasing postcss values (#12393 by @niklasvatn)

PostCSS values can start with digits. Prettier interprets this as a number followed by a unit in the example below.

// Input

@value 4XLarge 28/36px;

.test {

font: 4XLarge Helvetica;

}

// Prettier 2.5

@value 4XLarge 28/36px;

.test {

font: 4xlarge Helvetica;

}

// Prettier 2.6

@value 4XLarge 28/36px;

.test {

font: 4XLarge Helvetica;

}

SCSS

// Input

.ag-theme-balham {

@include ag-theme-balham(

(

foreground-color: $custom-foreground-color,

disabled-foreground-color: null, // TODO some comment

)

);

}

// Prettier 2.5

.ag-theme-balham {

@include ag-theme-balham(

(

foreground-color: $custom-foreground-color,

disabled-foreground-color: null,

r: null, // TODO som

)

);

}

// Prettier 2.6

.ag-theme-balham {

@include ag-theme-balham(

(

foreground-color: $custom-foreground-color,

disabled-foreground-color: null,

// TODO some comment

)

);

}

Fixes printing parameters of a mixin named selector() (#12213 by @duailibe)

/* Input */

@mixin selector($param: 'value') {

}

/* Prettier 2.5 */

@mixin selector($param: 'value) {

}

/* Prettier 2.6 */

@mixin selector($param: 'value') {

}

Vue

Fix hangs on invalid v-for (#12113 by @fisker)

// Input

<template>

<div>

<div v-for=" a in ">aaaaa</div>

</div>

</template>

// Prettier 2.5

// Hangs

// Prettier 2.6

<template>

<div>

<div v-for=" a in ">aaaaa</div>

</div>

</template>;

Allow lang attribute of <template> to be empty (#12394 by @HallvardMM)

Template tag should allow empty string lang="" or undefined lang

<!-- Input -->

<template lang="">

<v-app-bar>

<v-menu offset-y>

<template></template>

</v-menu>

</v-app-bar>

</template>

<template lang>

<v-app-bar>

<v-menu offset-y>

<template></template>

</v-menu>

</v-app-bar>

</template>

<!-- Prettier 2.5 -->

SyntaxError: Unexpected closing tag "v-menu". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (5:5)

[error] 3 | <v-menu offset-y>

[error] 4 | <template></template>

[error] > 5 | </v-menu>

[error] | ^^^^^^^^^

[error] 6 | </v-app-bar>

[error] 7 | </template>

<!-- Prettier 2.6 -->

<template lang="">

<v-app-bar>

<v-menu offset-y>

<template></template>

</v-menu>

</v-app-bar>

</template>

<template lang>

<v-app-bar>

<v-menu offset-y>

<template></template>

</v-menu>

</v-app-bar>

</template>

Ember / Handlebars

Correctly identify which backslashes are removed by glimmer (#12302 by @MattTheNub)

This caused Prettier to unnecessarily add backslashes every time a file was formatted.

{{! Input }}

<p>\</p>

<p>\\</p>

<p>\\\</p>

{{! Prettier 2.5 }}

<p>\\</p>

<p>\\\</p>

<p>\\\\</p>

{{! Prettier 2.6 }}

<p>\</p>

<p>\\</p>

<p>\\\</p>

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 by @Quramy)

# 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 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.

// Prettier 2.5

$ prettier . --plugin-search-dir=a-dir-without-plugins

// Prettier 2.6

$ prettier . --no-plugin-search

Infer parser for .swcrc (#12320 by @sosukesuzuki)

Format the .swcrc file as a JSON file.

Miscellaneous

Switch to esbuild (#12055 by @fisker)

We've switched our build process from Rollup to esbuild. 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!