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

推荐订阅源

博客园 - 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 2.6: new singleAttributePerLine option and new JavaScript features! Prettier begins paying maintainers 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.5: TypeScript 4.5 and MDX v2 comment syntax!
Sosuke Suzuki · 2021-11-25 · via Prettier Blog

This release adds support for TypeScript 4.5's new syntax and MDX v2 comment syntax!

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

Avoid extra offset in arrow function body when using long types (#11515 by @kachkaev and @thorn0)

Starting with Prettier 2.3.0, type declarations in arrow functions could affect function body indentation. Changing the length of the type annotation could produce large diffs and thus increased the chance of git conflicts. To prevent this, function body offset was stabilized.
Note: This change may affect a large number of lines in your codebase.

// Input

const MyComponentWithLongName: React.VoidFunctionComponent<MyComponentWithLongNameProps> = ({ x, y }) => {

const a = useA();

return <div>{x + y + a}</div>;

};

// Prettier 2.2 and below

const MyComponentWithLongName: React.VoidFunctionComponent<MyComponentWithLongNameProps> = ({

x,

y,

}) => {

const a = useA();

return <div>{x + y + a}</div>;

};

// Prettier 2.4

const MyComponentWithLongName: React.VoidFunctionComponent<MyComponentWithLongNameProps> =

({ x, y }) => {

const a = useA();

return <div>{x + y + a}</div>;

};

// Prettier 2.5

const MyComponentWithLongName: React.VoidFunctionComponent<

MyComponentWithLongNameProps

> = ({ x, y }) => {

const a = useA();

return <div>{x + y + a}</div>;

};

Support TypeScript 4.5 (#11721, #11723, #11813 by @sosukesuzuki)

We’ve added support for TypeScript 4.5’s new syntax features:

type Modifiers on Import Names

// Example

import { type A } from "mod";

Private Field Presence Checks

// Example

class Foo {

#prop1;

method() {

return #prop1 in this;

}

}

Import Assertions

// Example

import obj from "./something.json" assert { type: "json" };

Handle .mts and .cts

Prettier will now format files with .mts and .cts extensions as TypeScript.

HTML

Collapse HTML class attributes onto one line (#11827 by @jlongster)

Reverts #7865.

While this was intended to be useful for users of CSS libraries like Tailwind that tend to result in large numbers of classes on elements, it became clear that our heuristics for where to split the class list on to multiple lines were unable to consistently produce good results. We’re still considering better ways to format HTML with lots of classes — consider discussing with us.

<!-- Input -->

<div

class="SomeComponent__heading-row d-flex flex-column flex-lg-row justify-content-start justify-content-lg-between align-items-start align-items-lg-center"

></div>

<!-- Prettier 2.4 -->

<div

class="

SomeComponent__heading-row

d-flex

flex-column flex-lg-row

justify-content-start justify-content-lg-between

align-items-start align-items-lg-center

"

></div>

<!-- Prettier 2.5 -->

<div

class="SomeComponent__heading-row d-flex flex-column flex-lg-row justify-content-start justify-content-lg-between align-items-start align-items-lg-center"

></div>

MDX

This adds basic support for MDX v2 comment syntax (JavaScript-style comments) in addition to the existing support MDX v1 comment syntax (HTML-style comments).

Note: Prettier currently only supports the new comment syntax for single-line comments (so that {/* prettier-ignore */} can be used), and doesn’t support the rest of MDX v2.

Input:

{/*A comment*/}

Prettier 2.4:

{/_A comment_/}

Prettier 2.5:

{/*A comment*/}

Other Changes

JavaScript

Fix parentheses around sequence expression as body of arrow chain (#11593 by @bakkot)

The required parentheses around sequence expressions as the body of arrow functions are now preserved for chained arrows. Previously, Prettier removed them, which resulted in invalid syntax.

// Input

const f = () => () => (0, 1);

// Prettier 2.4

const f = () => () => 0, 1;

// Prettier 2.5

const f = () => () => (0, 1);

Ignore errors for sloppy mode syntax (#11750 by @fisker, #11778 by @sosukesuzuki)

JavaScript’s strict mode adds several useful errors to prevent mistakes. Some of these errors are syntax errors that occur at parse time. Since Prettier’s goal is to format all syntactically valid JavaScript code regardless of whether it will actually run, we’ve opted to leave this error checking to linters, compilers, and the runtime.

// Input

function foo() { var bar = 1; delete bar; }

// Prettier 2.4

SyntaxError: Deleting local variable in strict mode. (1:31)

> 1 | function foo() { var bar = 1; delete bar; }

| ^

// Prettier 2.5

function foo() {

var bar = 1;

delete bar;

}

Respect spacing for between expressions and parentheses in embedded CSS (#11800 by @sosukesuzuki)

// Input

const paragraph2 = css`

transform1: ${expr}(30px);

transform2: ${expr} (30px);

`;

// Prettier 2.4

const paragraph2 = css`

transform1: ${expr} (30px);

transform2: ${expr} (30px);

`;

// Prettier 2.5

const paragraph2 = css`

transform1: ${expr}(30px);

transform2: ${expr} (30px);

`;

Support ES2022 class-private-fields-in syntax in espree parser (#11835 by @fisker)

// Example

class Foo {

#brand;

static isC(obj) {

return #brand in Foo;

}

}

TypeScript

Remove unnecessary parentheses for decorators (#11717, #11849 by @sosukesuzuki)

// Input

class Test {

@foo`bar`

test1: string = "test"

@test().x("global").y()

test2: string = "test";

}

// Prettier 2.4

class Test {

@(foo`bar`)

test: string = "test"

@(test().x("global").y())

test2: string = "test";

}

// Prettier 2.5

class Test {

@foo`bar`

test: string = "test"

@test().x("global").y()

test2: string = "test";

}

SCSS

Improve @use with formatting (#11637 by @sosukesuzuki)

// Input

@use 'library' with (

$black: #222,

$border-radius: 0.1rem,

$font-family: 'Helvetica, sans-serif'

);

// Prettier 2.4

@use "library" with

($black: #222, $border-radius: 0.1rem, $font-family: "Helvetica, sans-serif");

// Prettier 2.5

@use 'library' with (

$black: #222,

$border-radius: 0.1rem,

$font-family: 'Helvetica, sans-serif'

);

Fix @forward with formatting error (#11683 by @sriramarul, @sosukesuzuki)

// Input

@forward 'foo.scss' with ($components: red);

// Prettier 2.4

TypeError: Cannot read properties of undefined (reading 'type')

// Prettier 2.5

@forward "foo.scss" with (

$components: red

);

Ember / Handlebars

Uses the opposite quote type for quotes inside mustache statements in attributes (#11524 by @bmaehr)

{{!-- Input --}}

<div title="{{t 'login.username.description'}}" />

{{!-- Prettier 2.5 --}}

<div title="{{t 'login.username.description'}}" />

{{!-- Prettier 2.4 --}}

<div title="{{t "login.username.description"}}" />

Markdown

Keep trailing commas for type parameters in embedded TSX (#11685 by @sosukesuzuki)

The trailing comma is necessary to prevent TypeScript from treating the <T> as the beginning of a JSX expression.

<!-- Input -->

```tsx

const test = <T,>(value: T) => {};

```

<!-- Prettier 2.4 -->

```tsx

const test = <T>(value: T) => {};

```

<!-- Prettier 2.5 -->

```tsx

const test = <T,>(value: T) => {};

```