Files
swift-nio/scripts/check-swift-format.sh
T
Franz Busch 541a90026a [CI] Add format ignore file (#2803)
# Motivation

Some repositories may want to exclude files from being format checked.

# Modification

This PR moves the formatting into a separate script and adds an optional `.swiftformatignore` file that can be placed at the repo root similar to the `.licenseignore` file.

# Result

Repos can now decide what files are ignored when running the formatter.
2024-07-24 14:57:59 +01:00

40 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
excluded_files=""
if [ -f .swiftformatignore ]; then
log "Found swiftformatignore file..."
excluded_files=$(cat .swiftformatignore | xargs -I% printf ":(exclude)% ")
fi
log "Running swift format format..."
git ls-files -z '*.swift' $excluded_files | xargs -0 swift format format --parallel --in-place
log "Running swift format lint..."
git ls-files -z '*.swift' $excluded_files | xargs -0 swift format lint --strict --parallel
log "Checking for modified files..."
GIT_PAGER= git diff --exit-code '*.swift'
log "✅ Found no formatting issues."