Skip to content

Commit 8445665

Browse files
committed
fix
1 parent 119b6d9 commit 8445665

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

tests/format.mjs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execFileSync } from "child_process";
2+
import { parseArgs } from "util";
23
import fs from "fs";
34

45
function formatAll() {
@@ -26,8 +27,7 @@ function runPrettier(files) {
2627

2728
function runEslint(files) {
2829
const jsTsFiles = files.filter((f) => /\.(js|mjs|jsx|ts|tsx)$/.test(f));
29-
if (jsTsFiles.length === 0)
30-
return;
30+
if (jsTsFiles.length === 0) return;
3131
try {
3232
console.log(`Running eslint on ${jsTsFiles.length} file(s)`);
3333
runInBatches("eslint", ["--fix"], jsTsFiles);
@@ -46,9 +46,31 @@ function getChangedFiles() {
4646
return [...new Set(files)];
4747
}
4848

49-
const isAll = process.argv.includes("--all");
49+
let values;
50+
try {
51+
({ values } = parseArgs({
52+
options: {
53+
all: { type: "boolean" },
54+
help: { type: "boolean", short: "h" },
55+
},
56+
strict: true,
57+
}));
58+
} catch (err) {
59+
console.error(err.message);
60+
console.error("Run 'node tests/format.mjs --help' for usage.");
61+
process.exit(1);
62+
}
63+
64+
if (values.help) {
65+
console.log(`Usage: node tests/format.mjs [options]
66+
67+
Options:
68+
--all Format all files across the repository instead of just changed files
69+
-h, --help Show this help message`);
70+
process.exit(0);
71+
}
5072

51-
if (isAll) {
73+
if (values.all) {
5274
formatAll();
5375
process.exit(0);
5476
}

0 commit comments

Comments
 (0)