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 <tiagolobocastro@gmail.com>
  • Loading branch information
tiagolobocastro committed Dec 11, 2024
1 parent b7dd0fb commit 8a2c311
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ repos:
- id: rust-lint
name: Rust lint
description: Run cargo clippy on files included in the commit.
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.
entry: nix-shell --pure --run 'cargo-fmt --all -- --check'
entry: nix-shell --pure --run './scripts/rust/linter.sh fmt'
pass_filenames: false
types: [file, rust]
language: system
Expand Down
3 changes: 1 addition & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ pipeline {
steps {
sh 'printenv'
sh 'nix-shell --run "./dependencies/control-plane/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 "./scripts/git/check-submodule-branches.sh"'
}
}
Expand Down
34 changes: 29 additions & 5 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
set -e

cargo clippy --version
cargo clippy --all --all-targets $1 -- -D warnings
FMT_ERROR=

OP="${1:-}"

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

cargo fmt -- --version
cargo clippy -- --version

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 8a2c311

Please sign in to comment.