diff --git a/.ci/docker.sh b/.ci/docker.sh index a9fcfcc5b..911488ecf 100644 --- a/.ci/docker.sh +++ b/.ci/docker.sh @@ -137,10 +137,11 @@ if [[ $SAVE ]]; then fi # Set compile function, runs the compile script on the image, passes arguments to the script +# shellcheck disable=2120 function RUN () { echo "running image:" - if [[ $(docker images) =~ "$IMAGE_NAME" ]]; then + if [[ $(docker images) =~ $IMAGE_NAME ]]; then local args=(--mount "type=bind,source=$PWD,target=/src") args+=(--workdir "/src") args+=(--user "$(id -u):$(id -g)") @@ -151,6 +152,7 @@ function RUN () if [[ -n "$CMAKE_GENERATOR" ]]; then args+=(--env "CMAKE_GENERATOR=$CMAKE_GENERATOR") fi + # shellcheck disable=2086 docker run "${args[@]}" $RUN_ARGS "$IMAGE_NAME" bash "$BUILD_SCRIPT" $RUN_OPTS "$@" return $? else @@ -164,5 +166,6 @@ function RUN () if [[ $INTERACTIVE ]]; then export BUILD_SCRIPT="-i" export RUN_ARGS="$RUN_ARGS -it" + # shellcheck disable=2119 RUN fi diff --git a/.ci/lint_cpp.sh b/.ci/lint_cpp.sh index b08efab1a..cfb1e1f07 100755 --- a/.ci/lint_cpp.sh +++ b/.ci/lint_cpp.sh @@ -11,11 +11,19 @@ if ! git merge-base origin/master HEAD; then fi # Check formatting using format.sh -echo "Checking your code using clang-format/cmake-format..." +echo "Checking your code using format.sh..." -diff="$(./format.sh --diff --cmake --cf-version --branch origin/master)" +diff="$(./format.sh --diff --cmake --shell --print-version --branch origin/master)" err=$? +sep=" +---------- +" +used_version="${diff%%"$sep"*}" +diff="${diff#*"$sep"}" +changes_to_make="${diff%%"$sep"*}" +files_to_edit="${diff#*"$sep"}" + case $err in 1) cat </dev/null; then exit 3 fi +# check availability of shellcheck +if [[ $do_shell ]] && ! hash shellcheck 2>/dev/null; then + echo "could not find shellcheck" >&2 + exit 3 +fi + if [[ $branch ]]; then # get all dirty files through git if ! base=$(git merge-base "$branch" HEAD); then @@ -224,6 +256,15 @@ if [[ $branch ]]; then done done fi + if [[ $do_shell ]]; then + shell_names=() + for name in "${basenames[@]}"; do + filerx="(^|/)$scripts$" + if [[ $name =~ $filerx ]]; then + shell_names+=("$name") + fi + done + fi else exts_o=() for ext in "${exts[@]}"; do @@ -235,6 +276,9 @@ else mapfile -t cmake_names < <(find . -maxdepth 2 -type f -name "$cmakefile" -o -path "./${cmakedir/.}") cmake_names+=("${cmakeinclude[@]}") fi + if [[ $do_shell ]]; then + mapfile -t shell_names < <(find . -maxdepth 5 -type f -name "$scripts") + fi fi # filter excludes @@ -250,14 +294,18 @@ done # optionally print version if [[ $print_version ]]; then $cf_cmd -version - [[ $do_cmake ]] && echo "cmake-format $(cmake-format --version)" - echo "----------" + [[ $do_cmake ]] && echo "cmake-format version $(cmake-format --version)" + [[ $do_shell ]] && echo "shellcheck $(shellcheck --version | grep "version:")" + echo "$sep" fi if [[ ! ${cmake_names[*]} ]]; then unset do_cmake fi -if [[ ! ( ${names[*]} || $do_cmake ) ]]; then +if [[ ! ${shell_names[*]} ]]; then + unset do_shell +fi +if [[ ! ( ${names[*]} || $do_cmake || $do_shell ) ]]; then exit 0 # nothing to format means format is successful! fi @@ -265,16 +313,31 @@ fi case $mode in diff) declare -i code=0 + files_to_format=() for name in "${names[@]}"; do if ! $cf_cmd "$name" | diff "$name" - -p "$color"; then code=1 + files_to_format+=("$name") fi done for name in "${cmake_names[@]}"; do if ! cmake-format "$name" | diff "$name" - -p "$color"; then code=1 + files_to_format+=("$name") fi done + for name in "${shell_names[@]}"; do + if ! shellcheck "$name"; then + code=1 + files_to_format+=("$name") + fi + done + if (( code>0 )); then + echo "$sep" + for name in "${files_to_format[@]}"; do + echo "$name" + done + fi exit $code ;; name) @@ -291,6 +354,12 @@ case $mode in code=1 fi done + for name in "${shell_names[@]}"; do + if ! shellcheck "$name" >/dev/null; then + echo "$name" + code=1 + fi + done exit $code ;; code) @@ -300,6 +369,9 @@ case $mode in for name in "${cmake_names[@]}"; do cmake-format "$name" --check || exit 1 done + for name in "${shell_names[@]}"; do + shellcheck "$name" >/dev/null || exit 1 + done ;; *) if [[ "${names[*]}" ]]; then @@ -308,5 +380,16 @@ case $mode in if [[ $do_cmake ]]; then cmake-format -i "${cmake_names[@]}" fi + if [[ $do_shell ]]; then + echo "warning: --shell is not compatible with the current mode but shell files were modified!" >&2 + echo "recommendation: try $0 --diff --shell" >&2 + fi + if (( verbosity>0 )); then + count="${#names[*]}" + if [[ $do_cmake ]]; then + (( count+=${#cmake_names[*]} )) + fi + echo "parsed $count files that differ from base $branch" + fi ;; esac diff --git a/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h b/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h index fdbded4ba..d2577a99b 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h +++ b/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h @@ -146,7 +146,9 @@ public: const QString & /* logMessage */, LogMessage_TargetType /* targetType */, const int /* targetId */, - const QString & /* targetName */){}; + const QString & /* targetName */) + { + } virtual bool checkUserIsBanned(Server_ProtocolHandler * /* session */, QString & /* banReason */, int & /* banSecondsRemaining */) diff --git a/oracle/src/oraclewizard.h b/oracle/src/oraclewizard.h index 2733bf1ad..fe0bf1a21 100644 --- a/oracle/src/oraclewizard.h +++ b/oracle/src/oraclewizard.h @@ -182,7 +182,9 @@ class LoadSpoilersPage : public SimpleDownloadFilePage { Q_OBJECT public: - explicit LoadSpoilersPage(QWidget * = nullptr){}; + explicit LoadSpoilersPage(QWidget * = nullptr) + { + } void retranslateUi() override; protected: @@ -197,7 +199,9 @@ class LoadTokensPage : public SimpleDownloadFilePage { Q_OBJECT public: - explicit LoadTokensPage(QWidget * = nullptr){}; + explicit LoadTokensPage(QWidget * = nullptr) + { + } void retranslateUi() override; protected: diff --git a/oracle/src/pagetemplates.h b/oracle/src/pagetemplates.h index 874652d17..372aa2fef 100644 --- a/oracle/src/pagetemplates.h +++ b/oracle/src/pagetemplates.h @@ -13,7 +13,9 @@ class OracleWizardPage : public QWizardPage { Q_OBJECT public: - explicit OracleWizardPage(QWidget *parent = nullptr) : QWizardPage(parent){}; + explicit OracleWizardPage(QWidget *parent = nullptr) : QWizardPage(parent) + { + } virtual void retranslateUi() = 0; signals: diff --git a/servatrice/check_schema_version.sh b/servatrice/check_schema_version.sh index ed8772349..c4aadf356 100755 --- a/servatrice/check_schema_version.sh +++ b/servatrice/check_schema_version.sh @@ -6,6 +6,7 @@ version_line="$(grep 'INSERT INTO cockatrice_schema_version' servatrice/servatri version_line="${version_line#*VALUES(}" declare -i schema_ver="${version_line%%)*}" +# shellcheck disable=2012 latest_migration="$(ls -1 servatrice/migrations/ | tail -n1)" xtoysql="${latest_migration#servatrice_}" xtoy="${xtoysql%.sql}" @@ -23,7 +24,7 @@ if ((schema_ver != new_ver)); then fi expected_sql="^UPDATE cockatrice_schema_version SET version=${new_ver} WHERE version=${old_ver};$" -if ! grep -q "$expected_sql" servatrice/migrations/$latest_migration; then +if ! grep -q "$expected_sql" "servatrice/migrations/$latest_migration"; then echo "$latest_migration does not contain expected sql: $expected_sql" exit 1 fi diff --git a/servatrice/src/serversocketinterface.h b/servatrice/src/serversocketinterface.h index edf3d9f79..e522ea6c1 100644 --- a/servatrice/src/serversocketinterface.h +++ b/servatrice/src/serversocketinterface.h @@ -146,7 +146,9 @@ public: AbstractServerSocketInterface(Servatrice *_server, Servatrice_DatabaseInterface *_databaseInterface, QObject *parent = 0); - ~AbstractServerSocketInterface(){}; + ~AbstractServerSocketInterface() + { + } bool initSession(); virtual QHostAddress getPeerAddress() const = 0; diff --git a/servatrice/src/signalhandler.h b/servatrice/src/signalhandler.h index af9f40cb8..bf8d9e52a 100644 --- a/servatrice/src/signalhandler.h +++ b/servatrice/src/signalhandler.h @@ -10,7 +10,9 @@ class SignalHandler : public QObject Q_OBJECT public: SignalHandler(QObject *parent = 0); - ~SignalHandler(){}; + ~SignalHandler() + { + } static void sigHupHandler(int /* sig */); static void sigSegvHandler(int sig);