From 31987133ef00b918a03a6993ced27b57fb74f7fb Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 09:33:57 +0200 Subject: [PATCH 1/3] 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 e2011cfe..3ca23e22 --- 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 f8ae7050..9f4867a8 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -21,11 +21,17 @@ fatal() { error "$@"; exit 1; } CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" NUM_CHECKS_FAILED=0 +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" ) for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do @@ -35,6 +41,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 aeac4f27bc77244a83cf502fe5c857ff77ff6f0b Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 12:03:57 +0200 Subject: [PATCH 2/3] PR feedback --- 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 3ca23e22..eefa5850 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 d6c172088b25d202ae0ec9ed0bf6f29c12a34457 Mon Sep 17 00:00:00 2001 From: Honza Dvorsky Date: Wed, 25 Oct 2023 12:08:02 +0200 Subject: [PATCH 3/3] 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 9f4867a8..45ee0f30 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -42,7 +42,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))