From 67add7f1ca9a18b381bae96f38dc5e7be06df02f Mon Sep 17 00:00:00 2001 From: newell Date: Sat, 5 Oct 2024 17:21:02 -0700 Subject: [PATCH 1/8] Add pre-commit hooks --- flake.nix | 1 + src/.clang-format | 32 ++++++++++++++++++++++++++++++++ src/.clippy.toml | 1 + src/.pre-commit-config.yaml | 24 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 src/.clang-format create mode 100644 src/.clippy.toml create mode 100644 src/.pre-commit-config.yaml diff --git a/flake.nix b/flake.nix index 8cba76d..2beb96e 100644 --- a/flake.nix +++ b/flake.nix @@ -384,6 +384,7 @@ artiqpkgs.artiq artiqpkgs.vivado binutils-arm + pre-commit ]; XARGO_RUST_SRC = "${rust}/lib/rustlib/src/rust/library"; CLANG_EXTRA_INCLUDE_DIR = "${llvmPackages_11.clang-unwrapped.lib}/lib/clang/11.1.0/include"; diff --git a/src/.clang-format b/src/.clang-format new file mode 100644 index 0000000..9fc7f42 --- /dev/null +++ b/src/.clang-format @@ -0,0 +1,32 @@ +BasedOnStyle: LLVM + +Language: Cpp +Standard: Cpp11 + +AccessModifierOffset: -1 +AlignEscapedNewlines: Left +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: Inline +BinPackParameters: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +BreakInheritanceList: AfterColon +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ContinuationIndentWidth: 4 +DerivePointerAlignment: false +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +MaxEmptyLinesToKeep: 1 +PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: true +SpaceAfterTemplateKeyword: false +SpacesBeforeTrailingComments: 2 +TabWidth: 4 +UseTab: Never diff --git a/src/.clippy.toml b/src/.clippy.toml new file mode 100644 index 0000000..434d402 --- /dev/null +++ b/src/.clippy.toml @@ -0,0 +1 @@ +doc-valid-idents = ["CPython", "NumPy", ".."] \ No newline at end of file diff --git a/src/.pre-commit-config.yaml b/src/.pre-commit-config.yaml new file mode 100644 index 0000000..1d37807 --- /dev/null +++ b/src/.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: nac3-cargo-fmt + name: nac3 cargo format + entry: nix + language: system + types: [file, rust] + pass_filenames: false + description: Runs cargo fmt on the codebase. + args: [develop, -c, cargo, fmt, --all] + - id: nac3-cargo-clippy + name: nac3 cargo clippy + entry: nix + language: system + types: [file, rust] + pass_filenames: false + description: Runs cargo clippy on the codebase. + args: [develop, -c, cargo, clippy, --tests] -- 2.44.1 From 25cf9a80984df440f524a51032ca08764ec2702f Mon Sep 17 00:00:00 2001 From: newell Date: Sat, 5 Oct 2024 17:36:04 -0700 Subject: [PATCH 2/8] Update yaml to reference src/Cargo.toml --- src/.pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/.pre-commit-config.yaml b/src/.pre-commit-config.yaml index 1d37807..f71d002 100644 --- a/src/.pre-commit-config.yaml +++ b/src/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: types: [file, rust] pass_filenames: false description: Runs cargo fmt on the codebase. - args: [develop, -c, cargo, fmt, --all] + args: [develop, -c, cargo, fmt, --manifest-path, src/Cargo.toml, --all] - id: nac3-cargo-clippy name: nac3 cargo clippy entry: nix @@ -21,4 +21,4 @@ repos: types: [file, rust] pass_filenames: false description: Runs cargo clippy on the codebase. - args: [develop, -c, cargo, clippy, --tests] + args: [develop, -c, cargo, clippy, --manifest-path, src/Cargo.toml, --tests] -- 2.44.1 From 8741b23b08fa535b68b4f2470cc8f6b78011dfe3 Mon Sep 17 00:00:00 2001 From: newell Date: Sat, 5 Oct 2024 17:47:40 -0700 Subject: [PATCH 3/8] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index f270c31..e780f55 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,16 @@ Notes: - Firmware type must be either ``runtime`` for DRTIO-less or DRTIO master variants, or ``satman`` for DRTIO satellite. - If the board is connected to the local machine, use the ``local_run.sh`` script. +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. + License ------- -- 2.44.1 From 7749958c54e185f9f65d658a18443e6e2d7c50f3 Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 7 Oct 2024 10:00:12 -0700 Subject: [PATCH 4/8] Add hook for clang-format --- src/.pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/.pre-commit-config.yaml b/src/.pre-commit-config.yaml index f71d002..18a14f7 100644 --- a/src/.pre-commit-config.yaml +++ b/src/.pre-commit-config.yaml @@ -22,3 +22,11 @@ repos: pass_filenames: false description: Runs cargo clippy on the codebase. args: [develop, -c, cargo, clippy, --manifest-path, src/Cargo.toml, --tests] + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.0 + hooks: + - id: clang-format + name: clang-format + description: Checks formatting of C++ files using clang-format. + files: \.(cpp|h|hpp|c)$ + args: [-style=file, -fallback-style=none, -assume-filename=src/.clang-format] -- 2.44.1 From e3f170924e27d1705d11f757f611d9c79cf8f3c1 Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 7 Oct 2024 10:02:46 -0700 Subject: [PATCH 5/8] Update description in clang-format hook --- src/.pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.pre-commit-config.yaml b/src/.pre-commit-config.yaml index 18a14f7..ec57537 100644 --- a/src/.pre-commit-config.yaml +++ b/src/.pre-commit-config.yaml @@ -27,6 +27,6 @@ repos: hooks: - id: clang-format name: clang-format - description: Checks formatting of C++ files using clang-format. + description: Runs clang-format on the codebase. files: \.(cpp|h|hpp|c)$ args: [-style=file, -fallback-style=none, -assume-filename=src/.clang-format] -- 2.44.1 From c09e9d679f7cef0d019acb8a6ef9dd032f901e1b Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 7 Oct 2024 10:24:13 -0700 Subject: [PATCH 6/8] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e780f55..55807e4 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,12 @@ Notes: 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. +You are strongly recommended to use the provided pre-commit hooks to automatically reformat files and check for non-optimal Rust/C/C++ practices. Run `pre-commit install` to install the hook and `pre-commit` will automatically run `cargo fmt`, `cargo clippy`, and `clang-format` 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. +- If `cargo fmt`, `cargo clippy`, or `clang-format` returns an error, the pre-commit hook will fail. You should fix all errors before trying to commit again. +- If `cargo fmt` or `clang-format` reformats some files, the pre-commit hook will also fail. You should review the changes and, if satisfied, try to commit again. License ------- -- 2.44.1 From ff03737439408d221073b6effe452552f2744b64 Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 7 Oct 2024 23:12:15 -0700 Subject: [PATCH 7/8] Cleanup straggling nac3 references --- src/.pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/.pre-commit-config.yaml b/src/.pre-commit-config.yaml index ec57537..a871251 100644 --- a/src/.pre-commit-config.yaml +++ b/src/.pre-commit-config.yaml @@ -6,16 +6,16 @@ default_stages: [commit] repos: - repo: local hooks: - - id: nac3-cargo-fmt - name: nac3 cargo format + - id: cargo-fmt + name: artiq-zynq cargo format entry: nix language: system types: [file, rust] pass_filenames: false description: Runs cargo fmt on the codebase. args: [develop, -c, cargo, fmt, --manifest-path, src/Cargo.toml, --all] - - id: nac3-cargo-clippy - name: nac3 cargo clippy + - id: cargo-clippy + name: artiq-zynq cargo clippy entry: nix language: system types: [file, rust] @@ -26,7 +26,7 @@ repos: rev: v19.1.0 hooks: - id: clang-format - name: clang-format + name: artiq-zynq-clang-format description: Runs clang-format on the codebase. files: \.(cpp|h|hpp|c)$ args: [-style=file, -fallback-style=none, -assume-filename=src/.clang-format] -- 2.44.1 From 96c36eaa7fb5e63ec295dd89e8225d9e25160249 Mon Sep 17 00:00:00 2001 From: newell Date: Mon, 7 Oct 2024 23:15:31 -0700 Subject: [PATCH 8/8] Delete extra hyphen --- src/.pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.pre-commit-config.yaml b/src/.pre-commit-config.yaml index a871251..abe1608 100644 --- a/src/.pre-commit-config.yaml +++ b/src/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: rev: v19.1.0 hooks: - id: clang-format - name: artiq-zynq-clang-format + name: artiq-zynq clang-format description: Runs clang-format on the codebase. files: \.(cpp|h|hpp|c)$ args: [-style=file, -fallback-style=none, -assume-filename=src/.clang-format] -- 2.44.1