Skip to content

Commit

Permalink
Fix the clippy check precommit hook (#71)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iamrecursion authored Oct 3, 2024
1 parent a7ce0fd commit 6571743
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Rust
/target
main

# Tooling
.idea/
Expand Down
12 changes: 12 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -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(),
};
9 changes: 0 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6571743

Please sign in to comment.