From 65717439ddd00692883a8dc494b33572961e65c2 Mon Sep 17 00:00:00 2001 From: Ara Adkins Date: Thu, 3 Oct 2024 16:31:54 -0600 Subject: [PATCH] Fix the clippy check precommit hook (#71) It turns out that `clippy-driver` can only accept single files as input, while `lint-staged` calls by default with batches of files. This uses the JS configuration option to instead create a separate task for each Rust file that needs to be linted. --- .gitignore | 1 + lint-staged.config.mjs | 12 ++++++++++++ package.json | 9 --------- 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 lint-staged.config.mjs diff --git a/.gitignore b/.gitignore index 9fb1267..6e04cfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Rust /target +main # Tooling .idea/ diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs new file mode 100644 index 0000000..3c82d1e --- /dev/null +++ b/lint-staged.config.mjs @@ -0,0 +1,12 @@ +export default { + // These are simple, as they can just run prettier directly on any number of files. + "(*.md|*.toml|*.json|*.yaml|*.yml|*.css|*.js|*.mjs|*.ts)": ["prettier --write"], + + // Unfortunately `clippy-driver` can only accept one file at a time, so we have to create an + // individual clippy task for each changed file. + "*.rs": async (stagedFiles) => + [ + `rustfmt --unstable-features --edition 2021 ${stagedFiles.join(" ")}`, + stagedFiles.map((filename) => `clippy-driver ${filename}`), + ].flat(), +}; diff --git a/package.json b/package.json index 03ea888..0a08cf3 100644 --- a/package.json +++ b/package.json @@ -5,15 +5,6 @@ "prettier": "3.3.3", "prettier-plugin-toml": "2.0.1" }, - "lint-staged": { - "(*.md|*.toml|*.json|*.yaml|*.yml|*.css|*.js|*.ts)": [ - "prettier --write" - ], - "*.rs": [ - "rustfmt --unstable-features --edition 2021", - "clippy-driver" - ] - }, "husky": { "hooks": { "pre-commit": "npx lint-staged"