diff --git a/Makefile b/Makefile index f94f22672c..910124d3b8 100644 --- a/Makefile +++ b/Makefile @@ -145,10 +145,13 @@ cppcheck: @#(env bash ${PWD}/scripts/core_build.sh -l) @(env bash ${PWD}/scripts/check_cpp_fmt.sh) -rustcheck: +rustfmt: @echo "Running cargo format" @env bash ${PWD}/scripts/run_cargo_format.sh ${PWD}/internal/core/thirdparty/tantivy/tantivy-binding/ +rustcheck: + @echo "Running cargo check" + @env bash ${PWD}/scripts/run_cargo_format.sh ${PWD}/internal/core/thirdparty/tantivy/tantivy-binding/ --check fmt: ifdef GO_DIFF_FILES diff --git a/scripts/run_cargo_format.sh b/scripts/run_cargo_format.sh index 49b1831229..495aa04687 100644 --- a/scripts/run_cargo_format.sh +++ b/scripts/run_cargo_format.sh @@ -1,6 +1,17 @@ #!/bin/bash ( - cd $1 - cargo fmt + cd "$1" || exit 1 + + if [ "$2" == "--check" ]; then + if ! cargo fmt --all -- --check; then + echo "Rust code is not properly formatted." + exit 1 + fi + echo "Check rust format success" + else + cargo fmt --all + fi + + exit 0 ) \ No newline at end of file