Skip to content

Commit 23b982d

Browse files
Simplify swift-format soundness script (#108)
### Motivation The `run-swift-format.sh` script run as part of soundness explicitly lists the directories to format. This is to avoid running `swift-format` on the contents of `.build/` which contains a checkouts of all the dependencies. This isn't necessary, as we can use Git to tell us what files need to be formatted, which can also make for a more robust script/command as we add new directories. Additionally, with the previous strategy, `Package.swift` at the root of the repository was ignored. This was deliberate, but in hindsight I don't think the lack of trailing comma enforcement is worth us excluding it. ### Modifications - Use `git ls-files` to determine which files need to be passed to `swift-format`. ### Result - Script is simpler (also easier to add a one-shot command as a pre-commit hook). - Package.swift is also formatted. ### Test Plan None.
1 parent fe76c0d commit 23b982d

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ let package = Package(
9090
.testTarget(
9191
name: "OpenAPIGeneratorCoreTests",
9292
dependencies: [
93-
"_OpenAPIGeneratorCore",
93+
"_OpenAPIGeneratorCore"
9494
]
9595
),
9696

@@ -103,7 +103,7 @@ let package = Package(
103103
.product(name: "SwiftFormatConfiguration", package: "swift-format"),
104104
],
105105
resources: [
106-
.copy("Resources"),
106+
.copy("Resources")
107107
]
108108
),
109109

@@ -113,7 +113,7 @@ let package = Package(
113113
.testTarget(
114114
name: "PetstoreConsumerTests",
115115
dependencies: [
116-
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
116+
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")
117117
]
118118
),
119119

@@ -131,7 +131,7 @@ let package = Package(
131131
name: "OpenAPIGenerator",
132132
capability: .buildTool(),
133133
dependencies: [
134-
"swift-openapi-generator",
134+
"swift-openapi-generator"
135135
]
136136
),
137137
]

scripts/run-swift-format.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,16 @@ REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
2323

2424
SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH"
2525

26-
"${SWIFTFORMAT_BIN}" lint \
27-
--parallel --recursive --strict \
28-
"${REPO_ROOT}/Examples" \
29-
"${REPO_ROOT}/IntegrationTest" \
30-
"${REPO_ROOT}/Plugins" \
31-
"${REPO_ROOT}/Sources" \
32-
"${REPO_ROOT}/Tests" \
26+
git -C "${REPO_ROOT}" ls-files -z '*.swift' \
27+
| xargs -0 "${SWIFTFORMAT_BIN}" lint --parallel --strict \
3328
&& SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
3429

3530
if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then
3631
fatal "❌ Running swift-format produced errors.
3732
3833
To fix, run the following command:
3934
40-
% swift-format format --parallel --recursive --in-place Examples IntegrationTest Plugins Sources Tests
35+
% git ls-files -z '*.swift' | xargs -0 swift-format --in-place --parallel
4136
"
4237
exit "${SWIFT_FORMAT_RC}"
4338
fi

0 commit comments

Comments
 (0)