From 53d90c82050c4a3cc23dc3d817b5cc9f7fa23955 Mon Sep 17 00:00:00 2001 From: xuxingliang Date: Wed, 16 Oct 2024 20:14:25 +0800 Subject: [PATCH] tools/checkpatch: fix isort doesn't return error Flag --diff will output the changes content. Flag --check-only will return exit code. It can be used together with --diff. Run isort again to format the code in place, to make the behavior same as before. Signed-off-by: xuxingliang --- tools/checkpatch.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index 4e591c3adf..50e7d30a49 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -83,9 +83,15 @@ check_file() { fi if [ ${@##*.} == 'py' ]; then - black --check $@ || fail=1 - flake8 --config ${TOOLDIR}/../.github/linters/setup.cfg $@ || fail=1 - isort --settings-path ${TOOLDIR}/../.github/linters/setup.cfg $@ || fail=1 + setupcfg="${TOOLDIR}/../.github/linters/setup.cfg" + black --check "$@" || fail=1 + flake8 --config "${setupcfg}" "$@" || fail=1 + isort --diff --check-only --settings-path "${setupcfg}" "$@" + if [ $? -ne 0 ]; then + # Format in place + isort --settings-path "${setupcfg}" "$@" + fail=1 + fi elif [ "$(is_rust_file $@)" == "1" ]; then if ! command -v rustfmt &> /dev/null; then fail=1