pre-commit-hooks #329

Merged
sb10q merged 8 commits from newell/artiq-zynq:pre-commit-hooks into master 2024-10-08 15:19:13 +08:00
4 changed files with 58 additions and 0 deletions
Showing only changes of commit 67add7f1ca - Show all commits

View File

@ -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";

32
src/.clang-format Normal file
View File

@ -0,0 +1,32 @@
BasedOnStyle: LLVM
newell marked this conversation as resolved
Review

Isn't rustfmt.toml enough already?

Isn't rustfmt.toml enough already?
Review

I don't know. I was modeling this branch after what nac3 does with its pre-commit hooks but there could very well be some parameters that should be changed (such as removing the line of code you are commenting on). Open to suggestions.

I don't know. I was modeling this branch after what `nac3` does with its pre-commit hooks but there could very well be some parameters that should be changed (such as removing the line of code you are commenting on). Open to suggestions.
Review

@esavkin Pay attention to the file name and its contents ("Language: Cpp"...), this is about Clang/C/C++ not Rust.

That being said I don't see this clang formatter being applied in the precommit hook, neither here nor in nac3. @derppening

@esavkin Pay attention to the file name and its contents ("Language: Cpp"...), this is about Clang/C/C++ not Rust. That being said I don't see this clang formatter being applied in the precommit hook, neither here nor in nac3. @derppening
Review
Also does it work with pure C code like https://git.m-labs.hk/M-Labs/artiq-zynq/src/branch/master/src/libc/src/printf.c ?
Review

Also does it work with pure C code like https://git.m-labs.hk/M-Labs/artiq-zynq/src/branch/master/src/libc/src/printf.c ?

Just tested with the C code and it doesn't catch it:

nac3 cargo format....................................(no files to check)Skipped
nac3 cargo clippy....................................(no files to check)Skipped
[pre-commit-hooks b7054d0] testing
 1 file changed, 3 insertions(+), 3 deletions(-)

NOTE: I did test with Rust code before creating the pull request and it does catch that.

> Also does it work with pure C code like https://git.m-labs.hk/M-Labs/artiq-zynq/src/branch/master/src/libc/src/printf.c ? Just tested with the C code and it doesn't catch it: ``` nac3 cargo format....................................(no files to check)Skipped nac3 cargo clippy....................................(no files to check)Skipped [pre-commit-hooks b7054d0] testing 1 file changed, 3 insertions(+), 3 deletions(-) ``` NOTE: I did test with Rust code before creating the pull request and it does catch that.
Review

@esavkin Pay attention to the file name and its contents ("Language: Cpp"...), this is about Clang/C/C++ not Rust.

That being said I don't see this clang formatter being applied in the precommit hook, neither here nor in nac3. @derppening

It's not in NAC3 at the moment. We should enable it at some point though.

> @esavkin Pay attention to the file name and its contents ("Language: Cpp"...), this is about Clang/C/C++ not Rust. > > That being said I don't see this clang formatter being applied in the precommit hook, neither here nor in nac3. @derppening It's not in NAC3 at the moment. We should enable it at some point though.
Review

I updated the branch with a clang-format hook.

I updated the branch with a clang-format hook.
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

1
src/.clippy.toml Normal file
View File

@ -0,0 +1 @@
doc-valid-idents = ["CPython", "NumPy", ".."]

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: 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]