From fce33a57535dc9f5eb712de26184526286322e79 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 09:31:31 +0200 Subject: [PATCH 1/4] Add a soundness --fix flag --- scripts/run-swift-format.sh | 13 ++++++++++--- scripts/soundness.sh | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) mode change 100644 => 100755 scripts/run-swift-format.sh diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh old mode 100644 new mode 100755 index e2011cf..3ca23e2 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -21,10 +21,17 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" +FORMAT_COMMAND="lint --strict" +for arg in "$@"; do + if [ "$arg" == "--fix" ]; then + FORMAT_COMMAND="format --in-place" + fi +done + SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" -"${SWIFTFORMAT_BIN}" lint \ - --parallel --recursive --strict \ +"${SWIFTFORMAT_BIN}" $FORMAT_COMMAND \ + --parallel --recursive \ "${REPO_ROOT}/Sources" "${REPO_ROOT}/Tests" \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? @@ -33,7 +40,7 @@ if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then To fix, run the following command: - % swift-format format --parallel --recursive --in-place Sources Tests + % ./scripts/run-swift-format.sh --fix " exit "${SWIFT_FORMAT_RC}" fi diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 1baf17f..56f3783 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -22,11 +22,17 @@ CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" NUM_CHECKS_FAILED=0 export DOCC_TARGET=OpenAPIAsyncHTTPClient +FIX_FORMAT="" +for arg in "$@"; do + if [ "$arg" == "--fix" ]; then + FIX_FORMAT="--fix" + fi +done + SCRIPT_PATHS=( "${CURRENT_SCRIPT_DIR}/check-for-broken-symlinks.sh" "${CURRENT_SCRIPT_DIR}/check-for-unacceptable-language.sh" "${CURRENT_SCRIPT_DIR}/check-license-headers.sh" - "${CURRENT_SCRIPT_DIR}/run-swift-format.sh" "${CURRENT_SCRIPT_DIR}/check-for-docc-warnings.sh" ) @@ -37,6 +43,13 @@ for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do fi done +log "Running swift-format..." +bash ${CURRENT_SCRIPT_DIR}/run-swift-format.sh $FIX_FORMAT > /dev/null +FORMAT_EXIT_CODE=$? +if [ $FORMAT_EXIT_CODE -ne 0 ]; then + ((NUM_CHECKS_FAILED+=1)) +fi + if [ "${NUM_CHECKS_FAILED}" -gt 0 ]; then fatal "❌ ${NUM_CHECKS_FAILED} soundness check(s) failed." fi From 7abe17feeb970041dff9b8bf1f990dba5b77bdd7 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 10:12:19 +0200 Subject: [PATCH 2/4] Update scripts/soundness.sh Co-authored-by: George Barnett --- scripts/soundness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 56f3783..7543915 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -44,7 +44,7 @@ for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do done log "Running swift-format..." -bash ${CURRENT_SCRIPT_DIR}/run-swift-format.sh $FIX_FORMAT > /dev/null +bash "${CURRENT_SCRIPT_DIR}"/run-swift-format.sh $FIX_FORMAT > /dev/null FORMAT_EXIT_CODE=$? if [ $FORMAT_EXIT_CODE -ne 0 ]; then ((NUM_CHECKS_FAILED+=1)) From 217166659c723faa5f52961657439865fd15e38c Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 10:57:59 +0200 Subject: [PATCH 3/4] PR feedback - use an array --- scripts/run-swift-format.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh index 3ca23e2..86aa038 100755 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -21,16 +21,16 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" -FORMAT_COMMAND="lint --strict" +FORMAT_COMMAND=(lint --strict) for arg in "$@"; do if [ "$arg" == "--fix" ]; then - FORMAT_COMMAND="format --in-place" + FORMAT_COMMAND=(format --in-place) fi done SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" -"${SWIFTFORMAT_BIN}" $FORMAT_COMMAND \ +"${SWIFTFORMAT_BIN}" "$FORMAT_COMMAND" \ --parallel --recursive \ "${REPO_ROOT}/Sources" "${REPO_ROOT}/Tests" \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? From 93699928f8c5119cb27cb63d0de1c5b9c40fff8d Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 11:01:49 +0200 Subject: [PATCH 4/4] Expand array correctly --- scripts/run-swift-format.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh index 86aa038..eefa585 100755 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -30,7 +30,7 @@ done SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" -"${SWIFTFORMAT_BIN}" "$FORMAT_COMMAND" \ +"${SWIFTFORMAT_BIN}" "${FORMAT_COMMAND[@]}" \ --parallel --recursive \ "${REPO_ROOT}/Sources" "${REPO_ROOT}/Tests" \ && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?