Merge branch 'main' into next

# Conflicts:
#	package.json
#	src/language-css/printer-postcss.js
#	src/language-handlebars/printer-glimmer.js
#	src/language-markdown/clean.js
#	src/language-markdown/printer-markdown.js
#	yarn.lock
This commit is contained in:
fisker Cheung committed 2022-12-15 19:16:59 +08:00
commit daeb90f1ca
25 files changed
+423 -45

No files matched your search

+2
View File
@@ -19,10 +19,12 @@ concurrency:
jobs:
build:
if: github.event_name != 'schedule' || github.repository == 'prettier/prettier'
name: Build
uses: ./.github/workflows/_build.yml
webpack:
if: github.event_name != 'schedule' || github.repository == 'prettier/prettier'
name: Bundle Prettier with webpack
runs-on: ubuntu-latest
needs: [build]
+1
View File
@@ -21,6 +21,7 @@ concurrency:
jobs:
test:
if: github.event_name != 'schedule' || github.repository == 'prettier/prettier'
timeout-minutes: 60
strategy:
fail-fast: false
+1
View File
@@ -10,6 +10,7 @@ permissions:
jobs:
lock:
if: github.event_name != 'schedule' || github.repository == 'prettier/prettier'
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v4
+3 -2
View File
@@ -7,14 +7,15 @@ on:
types:
- created
schedule:
# “At minute 0.” https://crontab.guru/#0_*_*_*_*
- cron: "0 * * * *"
# “At 00:00.” https://crontab.guru/#0_0_*_*_*
- cron: "0 0 * * *"
permissions:
issues: write
jobs:
no-response:
if: github.event_name != 'schedule' || github.repository == 'prettier/prettier'
runs-on: ubuntu-latest
steps:
- uses: lee-dohm/no-response@v0.5.0
+42
View File
@@ -0,0 +1,42 @@
#### Allow custom "else if"-like blocks with block params (#13930 by @jamescdavis)
#13507 added support for custom block keywords used with `else`, but failed to allow block params. This updates printer-glimmer to allow block params with custom "else if"-like blocks.
<!-- prettier-ignore -->
```hbs
{{! Input }}
{#when isAtWork as |work|}}
Ship that
{{work}}!
{{else when isReading as |book|}}
You can finish
{{book}}
eventually...
{{else}}
Go to bed!
{{/when}}
{{! Prettier stable }}
{{#when isAtWork as |work|}}
Ship that
{{work}}!
{{else when isReading}}
You can finish
{{book}}
eventually...
{{else}}
Go to bed!
{{/when}}
{{! Prettier main }}
{#when isAtWork as |work|}}
Ship that
{{work}}!
{{else when isReading as |book|}}
You can finish
{{book}}
eventually...
{{else}}
Go to bed!
{{/when}}
```
+20
View File
@@ -0,0 +1,20 @@
#### Don't lowercase link references (#13155 by @DerekNonGeneric & @fisker)
<!-- prettier-ignore -->
```markdown
<!-- Input -->
We now don't strictly follow the release notes format suggested by [Keep a Changelog].
[Keep a Changelog]: https://example.com/
<!-- Prettier stable -->
We now don't strictly follow the release notes format suggested by [Keep a Changelog].
[keep a changelog]: https://example.com/
<!--
^^^^^^^^^^^^^^^^^^ lowercased
-->
<!-- Prettier main -->
<Same as input>
```
+36
View File
@@ -0,0 +1,36 @@
#### Preserve empty lines between nested SCSS maps (#13931 by @jneander)
<!-- prettier-ignore -->
```scss
/* Input */
$map: (
'one': (
'key': 'value',
),
'two': (
'key': 'value',
),
)
/* Prettier stable */
$map: (
'one': (
'key': 'value',
),
'two': (
'key': 'value',
),
)
/* Prettier main */
$map: (
'one': (
'key': 'value',
),
'two': (
'key': 'value',
),
)
```
+2 -1
View File
@@ -66,9 +66,10 @@ Read more at [mirror of prettier package for pre-commit](https://github.com/pre-
**Use Case:** A dotnet solution to use Prettier along with other code quality tools (e.g. dotnet-format, ESLint, Stylelint, etc.). It supports multiple file states (staged - last-commit, git-files etc.)
```bash
dotnet new tool-manifest
dotnet tool install husky
dotnet husky install
dotnet husky add .husky/pre-commit
dotnet husky add pre-commit
```
after installation you can add prettier task to the `task-runner.json`.
+2 -1
View File
@@ -47,7 +47,8 @@
"chalk": "5.1.2",
"ci-info": "3.7.0",
"cjk-regex": "2.0.1",
"cosmiconfig": "8.0.0",
"collapse-white-space": "1.0.6",
"cosmiconfig": "7.0.1",
"css-units-list": "2.0.1",
"dashify": "2.0.0",
"diff": "5.1.0",
+9 -4
View File
@@ -914,7 +914,7 @@ function genericPrint(path, options, print) {
);
const shouldPrintComma =
!isLast || (isVarFunction && hasComma());
const printed = [
let printed = [
printedGroups[index],
shouldPrintComma ? "," : "",
];
@@ -929,7 +929,7 @@ function genericPrint(path, options, print) {
) {
const parts = getDocParts(printed[0].contents.contents);
parts[1] = group(parts[1]);
return group(dedent(printed));
printed = [group(dedent(printed))];
}
if (
@@ -937,9 +937,14 @@ function genericPrint(path, options, print) {
child.type === "value-comma_group" &&
isNonEmptyArray(child.groups)
) {
const last = child.groups.at(-1);
let last = child.groups.at(-1);
// `value-paren_group` does not have location info, but its closing parenthesis does.
if (!last.source && last.close) {
last = last.close;
}
if (
// `value-paren_group` missing location info
last.source &&
isNextLineEmpty(options.originalText, last, locEnd)
) {
+19 -7
View File
@@ -545,16 +545,28 @@ function isElseIfLike(path) {
);
}
function printElseIfLikeBlock(path, print) {
const { grandparent } = path;
return [
function printElseIfLikeBlock(path, print, ) {
const { node, grandparent } = path;
let blockParams = [];
if (isNonEmptyArray(node.program.blockParams)) {
blockParams = [line, printBlockParams(node.program)];
}
return group([
printInverseBlockOpeningMustache(grandparent),
"else ",
grandparent.inverse.body[0].path.parts[0],
" ",
indent(
group([
group(["else", line, grandparent.inverse.body[0].path.parts[0]]),
line,
printParams(path, print),
])
),
indent(blockParams),
softline,
printParams(path, print),
printInverseBlockClosingMustache(grandparent),
];
]);
}
function printCloseBlock(path, print, options) {
+7 -5
View File
@@ -1,3 +1,4 @@
import collapseWhiteSpace from "collapse-white-space";
import { isFrontMatterNode } from "../common/util.js";
import { startWithPragma } from "./pragma.js";
@@ -40,11 +41,12 @@ function clean(ast, newObj, parent) {
newObj.value = ast.value.trim().replaceAll(/[\t\n]+/g, " ");
}
if (ast.type === "definition" || ast.type === "linkReference") {
newObj.label = ast.label
.trim()
.replaceAll(/[\t\n ]+/g, " ")
.toLowerCase();
if (
ast.type === "definition" ||
ast.type === "linkReference" ||
ast.type === "imageReference"
) {
newObj.label = collapseWhiteSpace(ast.label);
}
if (
+19 -9
View File
@@ -1,3 +1,5 @@
import collapseWhiteSpace from "collapse-white-space";
import {
getMinNotPresentContinuousCount,
getMaxContinuousCount,
@@ -339,7 +341,7 @@ function genericPrint(path, options, print) {
printChildren(path, options, print),
"]",
node.referenceType === "full"
? ["[", node.identifier, "]"]
? printLinkReference(node)
: node.referenceType === "collapsed"
? "[]"
: "",
@@ -347,7 +349,7 @@ function genericPrint(path, options, print) {
case "imageReference":
switch (node.referenceType) {
case "full":
return ["![", node.alt || "", "][", node.identifier, "]"];
return ["![", node.alt || "", "]", printLinkReference(node)];
default:
return [
"![",
@@ -359,9 +361,8 @@ function genericPrint(path, options, print) {
case "definition": {
const lineOrSpace = options.proseWrap === "always" ? line : " ";
return group([
"[",
node.identifier,
"]:",
printLinkReference(node),
":",
indent([
lineOrSpace,
printUrl(node.url),
@@ -377,7 +378,7 @@ function genericPrint(path, options, print) {
case "footnote":
return ["[^", printChildren(path, options, print), "]"];
case "footnoteReference":
return ["[^", node.identifier, "]"];
return printFootnoteReference(node);
case "footnoteDefinition": {
const shouldInlineFootnote =
node.children.length === 1 &&
@@ -387,9 +388,8 @@ function genericPrint(path, options, print) {
node.children[0].position.start.line ===
node.children[0].position.end.line));
return [
"[^",
node.identifier,
"]: ",
printFootnoteReference(node),
": ",
shouldInlineFootnote
? printChildren(path, options, print)
: group([
@@ -833,6 +833,16 @@ function hasPrettierIgnore(path) {
return path.index > 0 && isPrettierIgnore(path.previous) === "next";
}
// `remark-parse` lowercase the `label` as `identifier`, we don't want do that
// https://github.com/remarkjs/remark/blob/daddcb463af2d5b2115496c395d0571c0ff87d15/packages/remark-parse/lib/tokenize/reference.js
function printLinkReference(node) {
return `[${collapseWhiteSpace(node.label)}]`;
}
function printFootnoteReference(node) {
return `[^${node.label}]`;
}
const printer = {
preprocess,
print: genericPrint,
@@ -274,6 +274,26 @@ printWidth: 80
Another thing
{{~/when~}}
{{#when a as |b|}}
{{b}}
{{else when c as |d|}}
{{d}}
{{else when e as |f|}}
{{f}}
{{else when g as |h|}}
{{h}}
{{else}}
j
{{/when}}
{{#when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst as |b|}}
{{b}}
{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop as |d|}}
{{d}}
{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz as |f|}}
{{f}}
{{/when}}
=====================================output=====================================
<h1>
{{#when isAtWork}}
@@ -381,6 +401,34 @@ printWidth: 80
{{~else when anotherCondition~}}
Another thing
{{~/when~}}
{{#when a as |b|}}
{{b}}
{{else when c as |d|}}
{{d}}
{{else when e as |f|}}
{{f}}
{{else when g as |h|}}
{{h}}
{{else}}
j
{{/when}}
{{#when
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
as |b|
}}
{{b}}
{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop
as |d|
}}
{{d}}
{{else when
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
as |f|
}}
{{f}}
{{/when}}
================================================================================
`;
@@ -106,3 +106,23 @@
{{~else when anotherCondition~}}
Another thing
{{~/when~}}
{{#when a as |b|}}
{{b}}
{{else when c as |d|}}
{{d}}
{{else when e as |f|}}
{{f}}
{{else when g as |h|}}
{{h}}
{{else}}
j
{{/when}}
{{#when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst as |b|}}
{{b}}
{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop as |d|}}
{{d}}
{{else when abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz as |f|}}
{{f}}
{{/when}}
@@ -0,0 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`case-and-space.md format 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
# \`linkReference\`
[ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ]
# \`imageReference\`
![ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ]
# \`definition\`
[ See \`AsyncGeneratorFunction\` ]: ./index.html
# \`footnoteReference\`
[^See\`AsyncGeneratorFunction\`]
# \`footnoteDefinition\`
[^See\`AsyncGeneratorFunction\`]: ./index.html
=====================================output=====================================
# \`linkReference\`
[ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ]
# \`imageReference\`
![ See \`AsyncGeneratorFunction\` ][ See \`AsyncGeneratorFunction\` ]
# \`definition\`
[ See \`AsyncGeneratorFunction\` ]: ./index.html
# \`footnoteReference\`
[^See\`AsyncGeneratorFunction\`]
# \`footnoteDefinition\`
[^See\`AsyncGeneratorFunction\`]: ./index.html
================================================================================
`;
exports[`issue-3835.md format 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
[1][Test Text](http://example.com)
=====================================output=====================================
[1][Test Text](http://example.com)
================================================================================
`;
exports[`issue-7118.md format 1`] = `
====================================options=====================================
parsers: ["markdown"]
printWidth: 80
| printWidth
=====================================input======================================
- see[Link to Foo][master-LinkToFoo]
[master-LinkToFoo]: http://foo.com
Bla bla [PascalCase][] bla.
[PascalCase]: ./PascalCase.md
## [Unreleased]
…
[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD
[darktable]: https://www.darktable.org/
[js;dr]: https://indieweb.org/js;dr
[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/
[OpenStreetMap]: https://www.openstreetmap.org/about
[SeaGL]: https://seagl.org/
[uBlock Origin]: https://github.com/gorhill/uBlock
=====================================output=====================================
- see[Link to Foo][master-LinkToFoo]
[master-LinkToFoo]: http://foo.com
Bla bla [PascalCase][] bla.
[PascalCase]: ./PascalCase.md
## [Unreleased]
…
[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD
[darktable]: https://www.darktable.org/
[js;dr]: https://indieweb.org/js;dr
[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/
[OpenStreetMap]: https://www.openstreetmap.org/about
[SeaGL]: https://seagl.org/
[uBlock Origin]: https://github.com/gorhill/uBlock
================================================================================
`;
@@ -0,0 +1,19 @@
# `linkReference`
[ See `AsyncGeneratorFunction` ][ See `AsyncGeneratorFunction` ]
# `imageReference`
![ See `AsyncGeneratorFunction` ][ See `AsyncGeneratorFunction` ]
# `definition`
[ See `AsyncGeneratorFunction` ]: ./index.html
# `footnoteReference`
[^See`AsyncGeneratorFunction`]
# `footnoteDefinition`
[^See`AsyncGeneratorFunction`]: ./index.html
@@ -0,0 +1 @@
[1][Test Text](http://example.com)
@@ -0,0 +1,18 @@
- see[Link to Foo][master-LinkToFoo]
[master-LinkToFoo]: http://foo.com
Bla bla [PascalCase][] bla.
[PascalCase]: ./PascalCase.md
## [Unreleased]
…
[Unreleased]: https://github.com/username/project/compare/v1.0.0...HEAD
[darktable]: https://www.darktable.org/
[js;dr]: https://indieweb.org/js;dr
[LinuxFest Northwest]: https://www.linuxfestnorthwest.org/
[OpenStreetMap]: https://www.openstreetmap.org/about
[SeaGL]: https://seagl.org/
[uBlock Origin]: https://github.com/gorhill/uBlock
@@ -0,0 +1 @@
run_spec(__dirname, ["markdown"]);
@@ -3231,7 +3231,7 @@ proseWrap: "always"
[Foo*bar\\]]
=====================================output=====================================
[foo*bar\\]]: my_(url) "title (with parens)"
[Foo*bar\\]]: my_(url) "title (with parens)"
[Foo*bar\\]]
@@ -3252,7 +3252,7 @@ proseWrap: "always"
[Foo bar]
=====================================output=====================================
[foo bar]: my%20url "title"
[Foo bar]: my%20url "title"
[Foo bar]
@@ -3392,7 +3392,7 @@ proseWrap: "always"
[Foo]
=====================================output=====================================
[foo]: /url
[FOO]: /url
[Foo]
@@ -3411,7 +3411,7 @@ proseWrap: "always"
[αγω]
=====================================output=====================================
[αγω]: /φου
[ΑΓΩ]: /φου
[αγω]
@@ -9046,7 +9046,7 @@ proseWrap: "always"
[bar]: /url "title"
=====================================output=====================================
[foo][bar]
[foo][BaR]
[bar]: /url "title"
@@ -9065,9 +9065,9 @@ proseWrap: "always"
[ТОЛПОЙ]: /url
=====================================output=====================================
[Толпой][толпой] is a Russian word.
[Толпой][Толпой] is a Russian word.
[толпой]: /url
[ТОЛПОЙ]: /url
================================================================================
`;
@@ -9085,9 +9085,9 @@ proseWrap: "always"
[Baz][Foo bar]
=====================================output=====================================
[foo bar]: /url
[Foo bar]: /url
[Baz][foo bar]
[Baz][Foo bar]
================================================================================
`;
@@ -9715,7 +9715,7 @@ proseWrap: "always"
=====================================output=====================================
![foo *bar*][foobar]
[foobar]: train.jpg "train & tracks"
[FOOBAR]: train.jpg "train & tracks"
================================================================================
`;
@@ -9813,7 +9813,7 @@ proseWrap: "always"
=====================================output=====================================
![foo][bar]
[bar]: /url
[BAR]: /url
================================================================================
`;
@@ -28,6 +28,7 @@ $icons: (
left: 253,
top: 73,
),
/* Should preserve empty lines */ cal-week-group:
(
left: 1,
+1 -1
View File
@@ -100,7 +100,7 @@ const TldrSection = ({ language }) => (
<div style={{ display: "flex", flexDirection: "column" }}>
<h2>Why?</h2>
<ul style={{ flex: "1" }}>
<li>You press save and code is formatted</li>
<li>Your code is formatted on save</li>
<li>No need to discuss style in code review</li>
<li>Saves you time and energy</li>
<li>
@@ -67,9 +67,10 @@ Read more at [mirror of prettier package for pre-commit](https://github.com/pre-
**Use Case:** A dotnet solution to use Prettier along with other code quality tools (e.g. dotnet-format, ESLint, Stylelint, etc.). It supports multiple file states (staged - last-commit, git-files etc.)
```bash
dotnet new tool-manifest
dotnet tool install husky
dotnet husky install
dotnet husky add .husky/pre-commit
dotnet husky add pre-commit
```
after installation you can add prettier task to the `task-runner.json`.
+24 -3
View File
@@ -1681,6 +1681,13 @@ __metadata:
languageName: node
linkType: hard
"@types/parse-json@npm:^4.0.0":
version: 4.0.0
resolution: "@types/parse-json@npm:4.0.0"
checksum: fd6bce2b674b6efc3db4c7c3d336bd70c90838e8439de639b909ce22f3720d21344f52427f1d9e57b265fcb7f6c018699b99e5e0c208a1a4823014269a6bf35b
languageName: node
linkType: hard
"@types/prettier@npm:^2.1.5":
version: 2.7.0
resolution: "@types/prettier@npm:2.7.0"
@@ -2563,7 +2570,7 @@ __metadata:
languageName: node
linkType: hard
"collapse-white-space@npm:^1.0.2":
"collapse-white-space@npm:1.0.6, collapse-white-space@npm:^1.0.2":
version: 1.0.6
resolution: "collapse-white-space@npm:1.0.6"
checksum: 9673fb797952c5c888341435596c69388b22cd5560c8cd3f40edb72734a9c820f56a7c9525166bcb7068b5d5805372e6fd0c4b9f2869782ad070cb5d3faf26e7
@@ -2724,7 +2731,20 @@ __metadata:
languageName: node
linkType: hard
"cosmiconfig@npm:8.0.0, cosmiconfig@npm:^8.0.0":
"cosmiconfig@npm:7.0.1":
version: 7.0.1
resolution: "cosmiconfig@npm:7.0.1"
dependencies:
"@types/parse-json": ^4.0.0
import-fresh: ^3.2.1
parse-json: ^5.0.0
path-type: ^4.0.0
yaml: ^1.10.0
checksum: 4be63e7117955fd88333d7460e4c466a90f556df6ef34efd59034d2463484e339666c41f02b523d574a797ec61f4a91918c5b89a316db2ea2f834e0d2d09465b
languageName: node
linkType: hard
"cosmiconfig@npm:^8.0.0":
version: 8.0.0
resolution: "cosmiconfig@npm:8.0.0"
dependencies:
@@ -6742,7 +6762,8 @@ __metadata:
chalk: 5.1.2
ci-info: 3.7.0
cjk-regex: 2.0.1
cosmiconfig: 8.0.0
collapse-white-space: 1.0.6
cosmiconfig: 7.0.1
cross-env: 7.0.3
cspell: 6.17.0
css-units-list: 2.0.1