-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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.
- Loading branch information
1 parent
1d25937
commit 541a900
Showing
2 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/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." |