Skip to content

Commit

Permalink
Integrate swiftformat to infra
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Sep 6, 2024
1 parent 5f4d2e7 commit 5e676f0
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.9
29 changes: 29 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md
--exclude Sources/ShellParserGenerated
--indentcase true
--patternlet inline
--indentstrings true

# https://github.com/nicklockwood/SwiftFormat/issues/483 fix indentation for expressions nested in ternary
--wrapternary before-operators

--disable andOperator
--disable blankLinesBetweenScopes
--disable consecutiveSpaces
--disable consistentSwitchCaseSpacing
--disable hoistTry
--disable preferKeyPath
--disable redundantNilInit
--disable redundantParens
--disable redundantRawValues
--disable redundantReturn
--disable redundantSelf
--disable redundantStaticSelf
--disable redundantType
--disable spaceAroundComments
--disable spaceInsideComments
--disable wrapArguments
--disable wrapMultilineConditionalAssignment

# This rule is cool but buggy. It feels like heuristics are used instead of real code analysis
--disable unusedArguments
1 change: 0 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ only_rules:
- no_fallthrough_only
- no_space_in_method_call
- nsobject_prefer_isequal # NSObject subclasses should implement isEqual instead of ==
- opening_brace
- operator_whitespace
- optional_enum_case_matching
- redundant_discardable_let
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let package = Package(
.executableTarget(
name: "AeroSpaceApp",
dependencies: [
.target(name: "AppBundle")
.target(name: "AppBundle"),
]
),
.executableTarget(
Expand Down
3 changes: 3 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ swift test
./script/install-deps.sh --swiftlint
./swift-exec-deps/.build/debug/swiftlint lint --quiet

./script/install-deps.sh --swiftformat
./swift-exec-deps/.build/debug/swiftformat .

./generate.sh --all
./script/check-uncommitted-files.sh
12 changes: 12 additions & 0 deletions script/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all=1
antlr=0
complgen=0
swiftlint=0
swiftformat=0
xcodegen=0
while [[ $# -gt 0 ]]; do
case $1 in
Expand All @@ -29,6 +30,11 @@ while [[ $# -gt 0 ]]; do
xcodegen=1
shift
;;
--swiftformat)
all=0
swiftformat=1
shift
;;
*)
echo "Unknown option $1"
exit 1
Expand Down Expand Up @@ -70,3 +76,9 @@ if test $all == 1 || test $xcodegen == 1; then
swift run --package-path ./swift-exec-deps xcodegen --version
fi
fi

if test $all == 1 || test $swiftformat == 1; then
if ! check-version 0.54.4 ./swift-exec-deps/.build/debug/swiftformat --version; then
swift run --package-path ./swift-exec-deps swiftformat --version
fi
fi
9 changes: 9 additions & 0 deletions swift-exec-deps/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
"version" : "6.0.3"
}
},
{
"identity" : "swiftformat",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nicklockwood/SwiftFormat",
"state" : {
"revision" : "c6680dd33c013abdd18266538e302f6323fa130e",
"version" : "0.54.4"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
Expand Down
1 change: 1 addition & 0 deletions swift-exec-deps/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/yonaskolb/XcodeGen.git", exact: "2.42.0"),
.package(url: "https://github.com/realm/SwiftLint", exact: "0.56.2"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.54.4"),
],
targets: []
)

0 comments on commit 5e676f0

Please sign in to comment.