From f53eb3eea5066ee7a38e39d04b6d3154ddf5644a Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 6 Aug 2024 16:03:39 +0800 Subject: [PATCH] Add pre-commit hooks --- .pre-commit-config.yaml | 24 ++++++++++++++++++++++++ README.md | 9 +++++++++ flake.nix | 1 + 3 files changed, 34 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5afe7a2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/README.md b/README.md index bf6cff8..8f20914 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/flake.nix b/flake.nix index ace79eb..7897dd5 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,7 @@ packages = with pkgs; [ rust llvm openocd dfu-util + pre-commit ] ++ (with python3Packages; [ numpy matplotlib ]);