Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a soundness --fix flag #345

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions scripts/run-swift-format.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ 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"

git -C "${REPO_ROOT}" ls-files -z '*.swift' \
| grep -z -v -e 'Tests/OpenAPIGeneratorReferenceTests/Resources' \
-e 'Sources/swift-openapi-generator/Documentation.docc' \
| xargs -0 "${SWIFTFORMAT_BIN}" lint --parallel --strict \
| xargs -0 "${SWIFTFORMAT_BIN}" "${FORMAT_COMMAND[@]}" --parallel \
&& SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?

if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then
fatal "❌ Running swift-format produced errors.

To fix, run the following command:

% git ls-files -z '*.swift' | grep -z -v -e 'Tests/OpenAPIGeneratorReferenceTests/Resources' -e 'Sources/swift-openapi-generator/Documentation.docc' | xargs -0 swift-format --in-place --parallel
% ./scripts/run-swift-format.sh --fix
"
exit "${SWIFT_FORMAT_RC}"
fi
Expand Down
15 changes: 14 additions & 1 deletion scripts/soundness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down