format-code: add option to disable linter
Add an option that allows users to disable a linter. This
is useful when the repository currently has code that is failing
a linter (like gitlint) but you don't want the script to halt.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I9bcfba475e1783e3763e45e4191728824b1ab166
diff --git a/scripts/format-code.sh b/scripts/format-code.sh
index 6ad5de2..d51fede 100755
--- a/scripts/format-code.sh
+++ b/scripts/format-code.sh
@@ -10,28 +10,54 @@
#
function display_help()
{
- echo "usage: format-code.sh [-h | --help] [--no-diff]"
- echo " [<path>]"
+ echo "usage: format-code.sh [-h | --help] [--no-diff] [--disable <tool>]"
+ echo " [--list-tools] [<path>]"
echo
echo "Format and lint a repository."
echo
echo "Arguments:"
- echo " --no-diff Don't show final diff output"
- echo " path Path to git repository (default to pwd)"
+ echo " --list-tools Display available linters and formatters"
+ echo " --no-diff Don't show final diff output"
+ echo " --disable <tool> Disable linter"
+ echo " path Path to git repository (default to pwd)"
}
-eval set -- "$(getopt -o 'h' --long 'help,no-diff' -n 'format-code.sh' -- "$@")"
+LINTERS_ALL=( \
+ commit_gitlint \
+ commit_spelling \
+ clang_format \
+ eslint \
+ pycodestyle \
+ shellcheck \
+ )
+LINTERS_DISABLED=()
+LINTERS_ENABLED=()
+
+eval set -- "$(getopt -o 'h' --long 'help,list-tools,no-diff,disable:' -n 'format-code.sh' -- "$@")"
while true; do
case "$1" in
'-h'|'--help')
display_help && exit 0
;;
+ '--list-tools')
+ echo "Available tools:"
+ for t in "${LINTERS_ALL[@]}"; do
+ echo " $t"
+ done
+ exit 0
+ ;;
+
'--no-diff')
OPTION_NO_DIFF=1
shift
;;
+ '--disable')
+ LINTERS_DISABLED+=("$2")
+ shift && shift
+ ;;
+
'--')
shift
break
@@ -79,18 +105,10 @@
cd "${DIR}"
echo -e " ${BLUE}Formatting code under${NORMAL} $DIR"
-LINTERS_ALL=( \
- commit_gitlint \
- commit_spelling \
- clang_format \
- eslint \
- pycodestyle \
- shellcheck \
- )
+
declare -A LINTER_REQUIRE=()
declare -A LINTER_CONFIG=()
declare -A LINTER_IGNORE=()
-LINTERS_ENABLED=()
declare -A LINTER_TYPES=()
LINTER_REQUIRE+=([commit_spelling]="codespell")
@@ -181,6 +199,10 @@
TITLE="$1"
IFS=";" read -r -a ARGS <<< "$2"
+ if [[ "${LINTERS_DISABLED[*]}" =~ $1 ]]; then
+ return
+ fi
+
EXE="${ARGS[0]}"
if [ ! -x "${EXE}" ]; then
if ! which "${EXE}" > /dev/null 2>&1 ; then