mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -05:00
chore: use rustfmt
cli via dprint for faster format (#13735)
This commit is contained in:
parent
5d7e1229db
commit
877c0b724e
2 changed files with 8 additions and 24 deletions
|
@ -9,8 +9,12 @@
|
||||||
"json": {
|
"json": {
|
||||||
"deno": true
|
"deno": true
|
||||||
},
|
},
|
||||||
|
"exec": {
|
||||||
|
"associations": "**/*.rs",
|
||||||
|
"rustfmt": "rustfmt"
|
||||||
|
},
|
||||||
"includes": [
|
"includes": [
|
||||||
"**/*.{ts,tsx,js,jsx,json,md,toml}"
|
"**/*.{ts,tsx,js,jsx,json,md,toml,rs}"
|
||||||
],
|
],
|
||||||
"excludes": [
|
"excludes": [
|
||||||
".cargo_home",
|
".cargo_home",
|
||||||
|
@ -44,6 +48,7 @@
|
||||||
"https://plugins.dprint.dev/typescript-0.61.0.wasm",
|
"https://plugins.dprint.dev/typescript-0.61.0.wasm",
|
||||||
"https://plugins.dprint.dev/json-0.14.0.wasm",
|
"https://plugins.dprint.dev/json-0.14.0.wasm",
|
||||||
"https://plugins.dprint.dev/markdown-0.12.1.wasm",
|
"https://plugins.dprint.dev/markdown-0.12.1.wasm",
|
||||||
"https://plugins.dprint.dev/toml-0.5.3.wasm"
|
"https://plugins.dprint.dev/toml-0.5.3.wasm",
|
||||||
|
"https://plugins.dprint.dev/exec-0.1.1.exe-plugin@42d3e30a14370b1a33dcc82c78528bd08979f2d4275014087d53472d3e229c62"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
|
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
import { getPrebuiltToolPath, getSources, join, ROOT_PATH } from "./util.js";
|
import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js";
|
||||||
|
|
||||||
async function dprint() {
|
async function dprint() {
|
||||||
const configFile = join(ROOT_PATH, ".dprint.json");
|
const configFile = join(ROOT_PATH, ".dprint.json");
|
||||||
const execPath = getPrebuiltToolPath("dprint");
|
const execPath = getPrebuiltToolPath("dprint");
|
||||||
console.log("dprint");
|
|
||||||
const p = Deno.run({
|
const p = Deno.run({
|
||||||
cmd: [execPath, "fmt", "--config=" + configFile],
|
cmd: [execPath, "fmt", "--config=" + configFile],
|
||||||
});
|
});
|
||||||
|
@ -16,29 +15,9 @@ async function dprint() {
|
||||||
p.close();
|
p.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rustfmt() {
|
|
||||||
const configFile = join(ROOT_PATH, ".rustfmt.toml");
|
|
||||||
const sourceFiles = await getSources(ROOT_PATH, ["*.rs"]);
|
|
||||||
|
|
||||||
if (!sourceFiles.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`rustfmt ${sourceFiles.length} file(s)`);
|
|
||||||
const p = Deno.run({
|
|
||||||
cmd: ["rustfmt", "--config-path=" + configFile, "--", ...sourceFiles],
|
|
||||||
});
|
|
||||||
const { success } = await p.status();
|
|
||||||
if (!success) {
|
|
||||||
throw new Error("rustfmt failed");
|
|
||||||
}
|
|
||||||
p.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await Deno.chdir(ROOT_PATH);
|
await Deno.chdir(ROOT_PATH);
|
||||||
await dprint();
|
await dprint();
|
||||||
await rustfmt();
|
|
||||||
|
|
||||||
if (Deno.args.includes("--check")) {
|
if (Deno.args.includes("--check")) {
|
||||||
const git = Deno.run({
|
const git = Deno.run({
|
||||||
|
|
Loading…
Add table
Reference in a new issue