5.0 KiB
JavaScript: Don't break simple template literals (#5979 by @jwbay)
// Input
console.log(chalk.white(`Covered Lines below threshold: ${coverageSettings.lines}%. Actual: ${coverageSummary.total.lines.pct}%`))
// Output (Prettier stable)
console.log(
chalk.white(
`Covered Lines below threshold: ${coverageSettings.lines}%. Actual: ${
coverageSummary.total.lines.pct
}%`
)
);
// Output (Prettier master)
console.log(
chalk.white(
`Covered Lines below threshold: ${coverageSettings.lines}%. Actual: ${coverageSummary.total.lines.pct}%`
)
);
TypeScript: Keep trailing comma in tsx type parameters (#6115 by @sosukesuzuki)
Previously, a trailing comma after single type parameter in arrow function was cleaned up. The formatted result is valid as ts, but is invalid as tsx. Prettier master fixes this issue.
// Input
type G<T> = any;
const myFunc = <T,>(arg1: G<T>) => false;
// Output (Prettier stable)
type G<T> = any;
const myFunc = <T>(arg1: G<T>) => false;
// Output (prettier master)
type G<T> = any;
const myFunc = <T,>(arg1: G<T>) => false;
TypeScript: Don’t breakup call expressions when the last argument is an arrow function with a simple return type (#6106 by @brainkim)
Fixes [an edge-case](#6099) where we were splitting up call expressions containing arrow functions with simple return types.
app.get("/", (req, res): void => {
res.send("Hello World!");
});
// Output (Prettier stable)
app.get(
"/",
(req, res): void => {
res.send("Hello World!");
},
);
// Output (Prettier master)
app.get("/", (req, res): void => {
res.send("Hello World!");
});
JavaScript: Fix closure typecasts without spaces (#6116 by @jridgewell)
Previously, a space was required between the @type
and opening {
of a closure typecast, or else the enclosing parenthesis would be removed. Closure itself does not require a space.
// Input
const v = /** @type{string} */(value);
// Output (Prettier stable)
const v = /** @type{string} */ value;
// Output (prettier master)
const v = /** @type{string} */ (value);
JavaScript: Prevent adding quotes when using --quote-props=consistent
and one of the keys were a computed "complex" expression (#6119 by @duailibe)
Previously, Prettier added unnecessary quotes to keys of an object, or properties and methods of classes, if there was at least one computed key with a "complex" expression (e.g. a member expression).
// Input
const obj = {
foo: "",
[foo.bar]: "",
}
// Output (Prettier stable)
const obj = {
"foo": "",
[foo.bar]: "",
}
// Output (Prettier master)
const obj = {
foo: "",
[foo.bar]: "",
}
Markdown: correctly determine count of backticks in inline code (#6110 by @belochub)
By the CommonMark spec, it is required to 'choose a string of n
backtick characters as delimiters, where the code does not contain any strings of exactly n
backtick characters.'
This changes the method of finding the required count of backticks from using 2 backticks, when there is a backtick string of length 1 inside the inline code block, and using 1 backtick in all other cases, to finding a minimum length backtick string that can correctly be used as a delimiter.
<!-- Input -->
``` 3 ``22`` `1` ```
`` 2 ```123``` `1` ``
<!-- Output (Prettier stable) -->
` 3 ``22`` `1` `
` 2 ```123``` `1` `
<!-- Output (Prettier master) -->
``` 3 ``22`` `1` ```
`` 2 ```123``` `1` ``