Skip to content

Commit 8661646

Browse files
authored
fix frameworkLint + clean coding (#121)
- frameworkLint - fixed bug skipping some files - File::detectBashFile replaced return by continue - excludes files with -options.sh or -main.sh suffix from being checked - warnings count 73 -> 62 - better error management and added logs - Github::defaultInstall - Github::defaultInstall - clean coding - extracted Log::getLevelText - changed some log messages levels
1 parent 6c69897 commit 8661646

25 files changed

+565
-456
lines changed

.framework-config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FRAMEWORK_FUNCTIONS_IGNORE_REGEXP="${FRAMEWORK_FUNCTIONS_IGNORE_REGEXP:-^(Namesp
1111
# describe the files that do not contain function to be imported
1212
NON_FRAMEWORK_FILES_REGEXP="${NON_FRAMEWORK_FILES_REGEXP:-(^bin/|^hooks/|^test.sh$|^preCommitTest.sh$|^.github/|^.docker/createUser.|.framework-config|.bats$|/testsData/|^manualTests/|/_.sh$|/ZZZ.sh$|/__all.sh$|^src/_binaries|^src/_includes|^src/batsHeaders.sh$|^src/_standalone)}"
1313
# describe the files that are allowed to not have an associated bats file
14-
BATS_FILE_NOT_NEEDED_REGEXP="${BATS_FILE_NOT_NEEDED_REGEXP:-(^bin/|.framework-config|^.docker/|^.github/|.bats$|/testsData/|^manualTests/|/_.sh$|/ZZZ.sh$|/__all.sh$|^src/batsHeaders.sh$|^src/_includes)}"
14+
BATS_FILE_NOT_NEEDED_REGEXP="${BATS_FILE_NOT_NEEDED_REGEXP:-(^bin/|.framework-config|^.docker/|^.github/|.bats$|/testsData/|^manualTests/|/_.sh$|/ZZZ.sh$|/__all.sh$|^src/batsHeaders.sh$|^src/_includes|-(main|options)\.sh$)}"
1515
# describe the files that are allowed to not have a function matching the filename
1616
FRAMEWORK_FILES_FUNCTION_MATCHING_IGNORE_REGEXP="${FRAMEWORK_FILES_FUNCTION_MATCHING_IGNORE_REGEXP:-^bin/|^.github/|^\.framework-config$|/testsData/|^manualTests/|\.bats$|src/Options/_bats.sh}"
1717
# Source directories

.pre-commit-config-github.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ repos:
160160
args:
161161
[
162162
--expected-warnings-count,
163-
"73",
163+
"62",
164164
--format,
165165
plain,
166166
--theme,
@@ -172,7 +172,7 @@ repos:
172172
args:
173173
[
174174
--expected-warnings-count,
175-
"73",
175+
"62",
176176
--format,
177177
checkstyle,
178178
--theme,

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ repos:
155155
args:
156156
[
157157
--expected-warnings-count,
158-
"73",
158+
"62",
159159
--format,
160160
plain,
161161
--theme,
@@ -167,7 +167,7 @@ repos:
167167
args:
168168
[
169169
--expected-warnings-count,
170-
"73",
170+
"62",
171171
--format,
172172
checkstyle,
173173
--theme,

bin/awkLint

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Conf::loadNearestFile() {
385385
fi
386386
done
387387

388-
Log::displayWarning "Config file '${configFileName}' not found in any source directories provided"
388+
Log::displayDebug "Config file '${configFileName}' not found in any source directories provided"
389389
return 1
390390
}
391391

@@ -626,6 +626,35 @@ Log::fatal() {
626626
}
627627

628628

629+
# @description Get the text representation of a log level
630+
# @arg $1 level:String the log level to convert
631+
# @exitcode 1 if the level is invalid
632+
Log::getLevelText() {
633+
local level="$1"
634+
case "${level}" in
635+
"${__LEVEL_OFF}")
636+
echo OFF
637+
;;
638+
"${__LEVEL_ERROR}")
639+
echo ERROR
640+
;;
641+
"${__LEVEL_WARNING}")
642+
echo WARNING
643+
;;
644+
"${__LEVEL_INFO}")
645+
echo INFO
646+
;;
647+
"${__LEVEL_DEBUG}")
648+
echo DEBUG
649+
;;
650+
*)
651+
Log::displayError "Command ${SCRIPT_NAME} - Invalid level ${level}"
652+
return 1
653+
;;
654+
esac
655+
}
656+
657+
629658
# @description log message to file
630659
# @arg $1 message:String the message to display
631660
Log::logDebug() {
@@ -999,31 +1028,6 @@ getLevel() {
9991028
esac
10001029
}
10011030

1002-
getLevelText() {
1003-
local level="$1"
1004-
case "${level}" in
1005-
"${__LEVEL_OFF}")
1006-
echo OFF
1007-
;;
1008-
"${__LEVEL_ERROR}")
1009-
echo ERROR
1010-
;;
1011-
"${__LEVEL_WARNING}")
1012-
echo WARNING
1013-
;;
1014-
"${__LEVEL_INFO}")
1015-
echo INFO
1016-
;;
1017-
"${__LEVEL_DEBUG}")
1018-
echo DEBUG
1019-
;;
1020-
*)
1021-
Log::displayError "Command ${SCRIPT_NAME} - Invalid level ${level}"
1022-
return 1
1023-
;;
1024-
esac
1025-
}
1026-
10271031
getVerboseLevel() {
10281032
local levelName="$1"
10291033
case "${levelName^^}" in
@@ -1057,7 +1061,7 @@ optionDisplayLevelCallback() {
10571061
}
10581062

10591063
optionDisplayLevelDefaultValueFunction() {
1060-
getLevelText "${BASH_FRAMEWORK_DISPLAY_LEVEL:-${__LEVEL_INFO}}"
1064+
Log::getLevelText "${BASH_FRAMEWORK_DISPLAY_LEVEL:-${__LEVEL_INFO}}"
10611065
}
10621066

10631067
# shellcheck disable=SC2317 # if function is overridden
@@ -1072,7 +1076,7 @@ optionLogLevelCallback() {
10721076
}
10731077

10741078
optionLogLevelDefaultValueFunction() {
1075-
getLevelText "${BASH_FRAMEWORK_LOG_LEVEL:-${__LEVEL_OFF}}"
1079+
Log::getLevelText "${BASH_FRAMEWORK_LOG_LEVEL:-${__LEVEL_OFF}}"
10761080
}
10771081

10781082
# shellcheck disable=SC2317 # if function is overridden
@@ -1566,13 +1570,15 @@ awkLintCommandHelp() {
15661570
echo -e " - ${__OPTION_COLOR}INFO${__RESET_COLOR}"
15671571
echo -e " - ${__OPTION_COLOR}DEBUG${__RESET_COLOR}"
15681572
echo -e " - ${__OPTION_COLOR}TRACE${__RESET_COLOR}"
1573+
15691574
Array::wrap2 ' ' 76 6 " Default value: " "$(optionLogLevelDefaultValueFunction)"
15701575
echo
15711576

15721577
echo -e " ${__HELP_OPTION_COLOR}--log-file <log-file>${__HELP_NORMAL} {single}"
15731578
Array::wrap2 ' ' 76 4 " " "Set log file"
15741579
echo
15751580

1581+
15761582
Array::wrap2 ' ' 76 6 " Default value: " "$(optionLogFileDefaultValueFunction)"
15771583
echo
15781584

@@ -1589,6 +1595,7 @@ awkLintCommandHelp() {
15891595
echo -e " - ${__OPTION_COLOR}INFO${__RESET_COLOR}"
15901596
echo -e " - ${__OPTION_COLOR}DEBUG${__RESET_COLOR}"
15911597
echo -e " - ${__OPTION_COLOR}TRACE${__RESET_COLOR}"
1598+
15921599
Array::wrap2 ' ' 76 6 " Default value: " "$(optionDisplayLevelDefaultValueFunction)"
15931600
echo
15941601

@@ -1605,6 +1612,7 @@ awkLintCommandHelp() {
16051612
echo -e " - ${__OPTION_COLOR}default${__RESET_COLOR}"
16061613
echo -e " - ${__OPTION_COLOR}default-force${__RESET_COLOR}"
16071614
echo -e " - ${__OPTION_COLOR}noColor${__RESET_COLOR}"
1615+
16081616
Array::wrap2 ' ' 76 6 " Default value: " "default"
16091617
echo
16101618

bin/buildPushDockerImage

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Conf::loadNearestFile() {
336336
fi
337337
done
338338

339-
Log::displayWarning "Config file '${configFileName}' not found in any source directories provided"
339+
Log::displayDebug "Config file '${configFileName}' not found in any source directories provided"
340340
return 1
341341
}
342342

@@ -589,19 +589,6 @@ Log::displayInfo() {
589589
}
590590

591591

592-
# @description Display message using warning color (yellow)
593-
# @arg $1 message:String the message to display
594-
# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs
595-
# @env LOG_CONTEXT String allows to contextualize the log
596-
Log::displayWarning() {
597-
if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_WARNING)); then
598-
Log::computeDuration
599-
echo -e "${__WARNING_COLOR}WARN - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2
600-
fi
601-
Log::logWarning "$1"
602-
}
603-
604-
605592
# @description Display message using error color (red) and exit immediately with error status 1
606593
# @arg $1 message:String the message to display
607594
# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs
@@ -614,6 +601,35 @@ Log::fatal() {
614601
}
615602

616603

604+
# @description Get the text representation of a log level
605+
# @arg $1 level:String the log level to convert
606+
# @exitcode 1 if the level is invalid
607+
Log::getLevelText() {
608+
local level="$1"
609+
case "${level}" in
610+
"${__LEVEL_OFF}")
611+
echo OFF
612+
;;
613+
"${__LEVEL_ERROR}")
614+
echo ERROR
615+
;;
616+
"${__LEVEL_WARNING}")
617+
echo WARNING
618+
;;
619+
"${__LEVEL_INFO}")
620+
echo INFO
621+
;;
622+
"${__LEVEL_DEBUG}")
623+
echo DEBUG
624+
;;
625+
*)
626+
Log::displayError "Command ${SCRIPT_NAME} - Invalid level ${level}"
627+
return 1
628+
;;
629+
esac
630+
}
631+
632+
617633
# @description log message to file
618634
# @arg $1 message:String the message to display
619635
Log::logDebug() {
@@ -685,15 +701,6 @@ Log::logMessage() {
685701
}
686702

687703

688-
# @description log message to file
689-
# @arg $1 message:String the message to display
690-
Log::logWarning() {
691-
if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_WARNING)); then
692-
Log::logMessage "${2:-WARNING}" "$1"
693-
fi
694-
}
695-
696-
697704
# @description activate or not Log::display* and Log::log* functions
698705
# based on BASH_FRAMEWORK_DISPLAY_LEVEL and BASH_FRAMEWORK_LOG_LEVEL
699706
# environment variables loaded by Env::requireLoad
@@ -987,31 +994,6 @@ getLevel() {
987994
esac
988995
}
989996

990-
getLevelText() {
991-
local level="$1"
992-
case "${level}" in
993-
"${__LEVEL_OFF}")
994-
echo OFF
995-
;;
996-
"${__LEVEL_ERROR}")
997-
echo ERROR
998-
;;
999-
"${__LEVEL_WARNING}")
1000-
echo WARNING
1001-
;;
1002-
"${__LEVEL_INFO}")
1003-
echo INFO
1004-
;;
1005-
"${__LEVEL_DEBUG}")
1006-
echo DEBUG
1007-
;;
1008-
*)
1009-
Log::displayError "Command ${SCRIPT_NAME} - Invalid level ${level}"
1010-
return 1
1011-
;;
1012-
esac
1013-
}
1014-
1015997
getVerboseLevel() {
1016998
local levelName="$1"
1017999
case "${levelName^^}" in
@@ -1045,7 +1027,7 @@ optionDisplayLevelCallback() {
10451027
}
10461028

10471029
optionDisplayLevelDefaultValueFunction() {
1048-
getLevelText "${BASH_FRAMEWORK_DISPLAY_LEVEL:-${__LEVEL_INFO}}"
1030+
Log::getLevelText "${BASH_FRAMEWORK_DISPLAY_LEVEL:-${__LEVEL_INFO}}"
10491031
}
10501032

10511033
# shellcheck disable=SC2317 # if function is overridden
@@ -1060,7 +1042,7 @@ optionLogLevelCallback() {
10601042
}
10611043

10621044
optionLogLevelDefaultValueFunction() {
1063-
getLevelText "${BASH_FRAMEWORK_LOG_LEVEL:-${__LEVEL_OFF}}"
1045+
Log::getLevelText "${BASH_FRAMEWORK_LOG_LEVEL:-${__LEVEL_OFF}}"
10641046
}
10651047

10661048
# shellcheck disable=SC2317 # if function is overridden
@@ -1677,13 +1659,15 @@ buildPushDockerImageCommandHelp() {
16771659
echo -e " - ${__OPTION_COLOR}INFO${__RESET_COLOR}"
16781660
echo -e " - ${__OPTION_COLOR}DEBUG${__RESET_COLOR}"
16791661
echo -e " - ${__OPTION_COLOR}TRACE${__RESET_COLOR}"
1662+
16801663
Array::wrap2 ' ' 76 6 " Default value: " "$(optionLogLevelDefaultValueFunction)"
16811664
echo
16821665

16831666
echo -e " ${__HELP_OPTION_COLOR}--log-file <log-file>${__HELP_NORMAL} {single}"
16841667
Array::wrap2 ' ' 76 4 " " "Set log file"
16851668
echo
16861669

1670+
16871671
Array::wrap2 ' ' 76 6 " Default value: " "$(optionLogFileDefaultValueFunction)"
16881672
echo
16891673

@@ -1700,6 +1684,7 @@ buildPushDockerImageCommandHelp() {
17001684
echo -e " - ${__OPTION_COLOR}INFO${__RESET_COLOR}"
17011685
echo -e " - ${__OPTION_COLOR}DEBUG${__RESET_COLOR}"
17021686
echo -e " - ${__OPTION_COLOR}TRACE${__RESET_COLOR}"
1687+
17031688
Array::wrap2 ' ' 76 6 " Default value: " "$(optionDisplayLevelDefaultValueFunction)"
17041689
echo
17051690

@@ -1716,6 +1701,7 @@ buildPushDockerImageCommandHelp() {
17161701
echo -e " - ${__OPTION_COLOR}default${__RESET_COLOR}"
17171702
echo -e " - ${__OPTION_COLOR}default-force${__RESET_COLOR}"
17181703
echo -e " - ${__OPTION_COLOR}noColor${__RESET_COLOR}"
1704+
17191705
Array::wrap2 ' ' 76 6 " Default value: " "default"
17201706
echo
17211707

@@ -1744,6 +1730,7 @@ buildPushDockerImageCommandHelp() {
17441730
echo
17451731
Array::wrap2 ' ' 76 8 " - ${__OPTION_COLOR}ubuntu:${__RESET_COLOR} ubuntu based docker image"
17461732
echo
1733+
17471734
Array::wrap2 ' ' 76 6 " Default value: " "ubuntu"
17481735
echo
17491736

@@ -1756,13 +1743,15 @@ buildPushDockerImageCommandHelp() {
17561743
echo -e " - ${__OPTION_COLOR}5.0${__RESET_COLOR}"
17571744
echo -e " - ${__OPTION_COLOR}5.1${__RESET_COLOR}"
17581745
echo -e " - ${__OPTION_COLOR}5.2${__RESET_COLOR}"
1746+
17591747
Array::wrap2 ' ' 76 6 " Default value: " "5.2"
17601748
echo
17611749

17621750
echo -e " ${__HELP_OPTION_COLOR}--bash-base-image <bash-base-image>${__HELP_NORMAL} {single}"
17631751
Array::wrap2 ' ' 76 4 " " "bash bash image to use (eg: ubuntu:20.04, amd64/bash:4.4-alpine3.18)"
17641752
echo
17651753

1754+
17661755
Array::wrap2 ' ' 76 6 " Default value: " "ubuntu:20.04"
17671756
echo
17681757
# ------------------------------------------

0 commit comments

Comments
 (0)