Skip to content

Commit

Permalink
build: check and update fmt
Browse files Browse the repository at this point in the history
Use common script for linting, rather than spread commands...

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Dec 11, 2024
1 parent 24fd03a commit c9ed89c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ repos:
- id: rust-lint
name: Rust lint
description: Run cargo clippy on files included in the commit. clippy should be installed before-hand.
entry: nix-shell --pure --run 'cargo-clippy --all --all-targets -- -D warnings'
entry: nix-shell --pure --run './scripts/rust/linter.sh clippy'
pass_filenames: false
types: [file, rust]
language: system
- id: rust-style
name: Rust style
description: Run cargo fmt on files included in the commit. rustfmt should be installed before-hand.
entry: nix-shell --pure --run 'cargo-fmt --all -- --check'
entry: nix-shell --pure --run './scripts/rust/linter.sh fmt'
exclude: openapi/
pass_filenames: false
types: [file, rust]
Expand Down
3 changes: 1 addition & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ pipeline {
steps {
sh 'printenv'
sh 'nix-shell --run "./scripts/rust/generate-openapi-bindings.sh"'
sh 'nix-shell --run "cargo fmt --all -- --check"'
sh 'nix-shell --run "cargo clippy --all-targets -- -D warnings"'
sh 'nix-shell --run "./scripts/rust/linter.sh"'
sh 'nix-shell --run "black --check tests/bdd"'
sh 'nix-shell --run "./scripts/git/check-submodule-branches.sh"'
}
Expand Down
32 changes: 28 additions & 4 deletions scripts/rust/linter.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

cargo fmt -- --version
cargo fmt --all -- --config imports_granularity=Crate
set -e

FMT_ERROR=

OP="${1:-}"

case "$OP" in
"" | "fmt" | "clippy")
;;
*)
echo "linter $OP not supported"
exit 2
esac

cargo fmt -- --version
cargo clippy -- --version
cargo clippy --all --all-targets $1 -- -D warnings

if [ -z "$OP" ] || [ "$OP" = "fmt" ]; then
cargo fmt --all --check || FMT_ERROR=$?
if [ -n "$FMT_ERROR" ]; then
cargo fmt --all
fi
fi

if [ -z "$OP" ] || [ "$OP" = "clippy" ]; then
cargo clippy --all --all-targets -- -D warnings
fi

exit ${FMT_ERROR:-0}

0 comments on commit c9ed89c

Please sign in to comment.