From f5c9ea23129c0fd2d56340cff2aa177b2f6db854 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Mon, 12 Aug 2019 15:11:28 +0200 Subject: [PATCH] fix(code-style): Use a blacklist instead of a big if block Co-authored-by: Mateusz Zalega <mateusz@appliedsourcery.com> Signed-off-by: Rahix <rahix@rahix.de> --- tools/code-style.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/code-style.sh b/tools/code-style.sh index c02d0ff4..7ef93e62 100755 --- a/tools/code-style.sh +++ b/tools/code-style.sh @@ -37,21 +37,40 @@ fi script_dir="$(dirname "$0")" +formatter_blacklist=( + lib/ff13/ + lib/FreeRTOS/ + lib/FreeRTOS-Plus/ + lib/gfx/ + lib/micropython/ + lib/mx25lba/ + lib/sdk/ + lib/vendor/ + openocd/ + docker/ +) + for source_file in "$@"; do # Check if file is actually one which we want to check rel_path="$(realpath --relative-to="$script_dir/.." "$source_file")" - if [[ ( "$rel_path" == lib/* && "$rel_path" != lib/card10/* ) || - ( "$rel_path" == openocd/* ) ]]; then - echo " - Ignoring $source_file" + format_item=true + for blacklist_item in "${formatter_blacklist[@]}"; do + if [[ "$rel_path" == "$blacklist_item"* ]]; then + format_item=false + break + fi + done + if [[ "$format_item" == false ]]; then + echo -e "\tIGN\t\t$source_file" continue fi if [[ "$source_file" == *.c ]]; then - echo " - Formatting $source_file ..." + echo -e "\tCLANG-FORMAT\t$source_file" clang-format -i "$source_file" python3 "$script_dir/fix-multi-decl.py" "$source_file" elif [[ "$source_file" == *.py ]]; then - echo " - Formatting $source_file ..." + echo -e "\tBLACK\t\t$source_file" black -q "$source_file" else echo " - Ignoring $source_file" >&2 -- GitLab