Skip to content

Commit

Permalink
chore: use rustfmt cli via dprint for faster format (denoland#13735)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Feb 21, 2022
1 parent 5d7e122 commit 877c0b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
9 changes: 7 additions & 2 deletions .dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
"json": {
"deno": true
},
"exec": {
"associations": "**/*.rs",
"rustfmt": "rustfmt"
},
"includes": [
"**/*.{ts,tsx,js,jsx,json,md,toml}"
"**/*.{ts,tsx,js,jsx,json,md,toml,rs}"
],
"excludes": [
".cargo_home",
Expand Down Expand Up @@ -44,6 +48,7 @@
"https://plugins.dprint.dev/typescript-0.61.0.wasm",
"https://plugins.dprint.dev/json-0.14.0.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"
]
}
23 changes: 1 addition & 22 deletions tools/format.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
// 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() {
const configFile = join(ROOT_PATH, ".dprint.json");
const execPath = getPrebuiltToolPath("dprint");
console.log("dprint");
const p = Deno.run({
cmd: [execPath, "fmt", "--config=" + configFile],
});
Expand All @@ -16,29 +15,9 @@ async function dprint() {
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() {
await Deno.chdir(ROOT_PATH);
await dprint();
await rustfmt();

if (Deno.args.includes("--check")) {
const git = Deno.run({
Expand Down

0 comments on commit 877c0b7

Please sign in to comment.