chore: add lint-staged and edit pre-commit

This commit is contained in:
Slinetrac
2025-10-07 17:32:49 +08:00
parent bf4e1a3270
commit 0d12103085
6 changed files with 408 additions and 18 deletions

75
scripts/lint-all.mjs Normal file
View File

@@ -0,0 +1,75 @@
#!/usr/bin/env node
import { spawn, spawnSync } from "child_process";
import { exit } from "process";
// Function to run a command
function runCommand(command, args, cwd = ".") {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { stdio: "inherit", cwd, shell: true });
child.on("close", (code) => {
if (code === 0) {
resolve();
} else {
reject(
new Error(`${command} ${args.join(" ")} exited with code ${code}`),
);
}
});
});
}
// Function to check if a command exists
function commandExists(command) {
try {
const result = spawnSync(command, ["--version"], { stdio: "pipe" });
return result.status === 0;
} catch (error) {
return false;
}
}
async function lintAll() {
console.log("Starting comprehensive lint process...");
try {
// Run TypeScript/JavaScript linting
console.log("\n--- Linting TypeScript/JavaScript files ---");
await runCommand("pnpm", ["lint"]);
// Run TypeScript type checking
console.log("\n--- Type checking ---");
await runCommand("pnpm", ["type-check"]);
// Run prettier check
console.log("\n--- Checking formatting ---");
await runCommand("pnpm", ["format:check"]);
console.log("\n--- Linting Rust files ---");
// Check for rustfmt
if (!commandExists("cargo")) {
throw new Error("Cargo is not available. Please install Rust and Cargo.");
}
// Run rustfmt
console.log("Running rustfmt...");
await runCommand("cargo", ["fmt", "--", "--check"], "./src-tauri");
// Run clippy
console.log("Running clippy...");
await runCommand(
"cargo",
["clippy", "--", "-D", "warnings"],
"./src-tauri",
);
console.log("\n✅ All linting checks passed!");
} catch (error) {
console.error("\n[ERROR] Linting failed:", error.message);
exit(1);
}
}
lintAll();