Add pre-commit hooks

This commit is contained in:
atse 2024-08-06 16:03:39 +08:00
parent 8d0aad31d4
commit f53eb3eea5
3 changed files with 34 additions and 0 deletions

24
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,24 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_stages: [commit]
repos:
- repo: local
hooks:
- id: cargo-fmt
name: cargo format
entry: cargo
language: system
types: [file, rust]
pass_filenames: false
description: Runs cargo fmt on the codebase.
args: [fmt]
- id: cargo-clippy
name: cargo clippy
entry: cargo
language: system
types: [file, rust]
pass_filenames: false
description: Runs cargo clippy on the codebase.
args: [clippy]

View File

@ -25,6 +25,15 @@ The resulting ELF file will be located under `target/thumbv7em-none-eabihf/relea
Alternatively, you can install the Rust toolchain without Nix using rustup; see the Rust manifest file pulled in `flake.nix` to determine which Rust version to use.
#### Pre-Commit Hooks
You are strongly recommended to use the provided pre-commit hooks to automatically reformat files and check for non-optimal Rust practices using Clippy. Run pre-commit install to install the hook and pre-commit will automatically run cargo fmt and cargo clippy for you.
Several things to note:
If cargo fmt or cargo clippy returns an error, the pre-commit hook will fail. You should fix all errors before trying to commit again.
If cargo fmt reformats some files, the pre-commit hook will also fail. You should review the changes and, if satisfied, try to commit again.
## Debugging
Connect SWDIO/SWCLK/RST/GND to a programmer such as ST-Link v2.1. Run OpenOCD:

View File

@ -64,6 +64,7 @@
packages = with pkgs; [
rust llvm
openocd dfu-util
pre-commit
] ++ (with python3Packages; [
numpy matplotlib
]);