Skip to content

Commit

Permalink
dependencies: Upgrade Prettier to 3.0.0-alpha.4.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk authored and timabbott committed Nov 2, 2022
1 parent 6ef5736 commit 683a6b0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"nyc": "^15.0.0",
"openapi-examples-validator": "^4.0.0",
"openapi-types": "^12.0.0",
"prettier": "^2.0.5",
"prettier": "^3.0.0-alpha.4",
"puppeteer": "^17.1.0",
"source-map": "https://codeload.github.com/benthemonkey/source-map/tar.gz/d95423f77edef6cbb9e21d2d6014c7de85ae220a",
"stylelint": "^14.0.1",
Expand Down
76 changes: 44 additions & 32 deletions tools/check-openapi
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async function checkFile(file) {

let ok = true;
const reformats = new Map();
const promises = [];

visit(doc, {
Map(key, node) {
Expand Down Expand Up @@ -70,43 +71,54 @@ async function checkFile(file) {
node.value instanceof Scalar &&
typeof node.value.value === "string"
) {
let formatted = Prettier.format(node.value.value, {parser: "markdown"});
if (![Scalar.BLOCK_FOLDED, Scalar.BLOCK_LITERAL].includes(node.value.type)) {
formatted = formatted.replace(/\n$/, "");
}
if (formatted !== node.value.value) {
if (argv.fix) {
reformats.set(node.value.range[0], {
value: formatted,
context: {afterKey: true},
promises.push(
(async () => {
let formatted = await Prettier.format(node.value.value, {
parser: "markdown",
});
} else {
ok = false;
const {line, col} = lineCounter.linePos(node.value.range[0]);
console.error(
"%s:%d:%d: Format description with Prettier:",
file,
line,
col,
);
let diff = "";
for (const part of Diff.diffLines(node.value.value, formatted)) {
const prefix = part.added
? "\u001B[32m+"
: part.removed
? "\u001B[31m-"
: "\u001B[34m ";
diff += prefix;
diff += part.value.replace(/\n$/, "").replace(/\n/g, "\n" + prefix);
diff += "\n";
if (
![Scalar.BLOCK_FOLDED, Scalar.BLOCK_LITERAL].includes(node.value.type)
) {
formatted = formatted.replace(/\n$/, "");
}
diff += "\u001B[0m";
console.error(diff);
}
}
if (formatted !== node.value.value) {
if (argv.fix) {
reformats.set(node.value.range[0], {
value: formatted,
context: {afterKey: true},
});
} else {
ok = false;
const {line, col} = lineCounter.linePos(node.value.range[0]);
console.error(
"%s:%d:%d: Format description with Prettier:",
file,
line,
col,
);
let diff = "";
for (const part of Diff.diffLines(node.value.value, formatted)) {
const prefix = part.added
? "\u001B[32m+"
: part.removed
? "\u001B[31m-"
: "\u001B[34m ";
diff += prefix;
diff += part.value
.replace(/\n$/, "")
.replace(/\n/g, "\n" + prefix);
diff += "\n";
}
diff += "\u001B[0m";
console.error(diff);
}
}
})(),
);
}
},
});
await Promise.all(promises);

if (!ok) {
process.exitCode = 1;
Expand Down
2 changes: 1 addition & 1 deletion tools/lint
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def run() -> None:
)
linter_config.external_linter(
"prettier",
["node_modules/.bin/prettier", "--check", "--loglevel=warn"],
["node_modules/.bin/prettier", "--check", "--log-level=warn"],
["css", "flow", "js", "json", "md", "ts", "yaml", "yml"],
fix_arg=["--write"],
description="Formats CSS, JavaScript, YAML",
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
# historical commits sharing the same major version, in which case a
# minor version bump suffices.

PROVISION_VERSION = (207, 0)
PROVISION_VERSION = (208, 0)
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8335,10 +8335,10 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==

prettier@^2.0.5:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
prettier@^3.0.0-alpha.4:
version "3.0.0-alpha.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.0-alpha.4.tgz#eee71d6b520b970f44e4045f2dc772bf6f80815f"
integrity sha512-+KeqJv4E5kaRsDRgSx9IeVygLKGHRmcoPvRJvPFp3bC1mw8opsva555gGb8TaJzUiHXoLZcus1EX+nlHPda7Pw==

pretty-error@^4.0.0:
version "4.0.0"
Expand Down

0 comments on commit 683a6b0

Please sign in to comment.