Skip to content

Commit ca81542

Browse files
authored
Standardize formatting (#55)
* Standardize style via lint script and editorconfig * Run shfmt * Run linter * Fix issues caught by linter * Add linter to CI * Minimum SwiftFormat version is the version that supports Swift 6.1 * Add convenience to modifier order
1 parent 1e9c0dc commit ca81542

20 files changed

+2033
-1951
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[*]
2+
insert_final_newline = true
3+
indent_size = 4 # We can remove this line if anyone has strong opinions.
4+
5+
# swift
6+
[*.swift]
7+
indent_style = tab
8+
9+
# sh
10+
[*.sh]
11+
indent_style = tab
12+
13+
# documentation, utils
14+
[*.{md,mdx,diff}]
15+
trim_trailing_whitespace = false

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,12 @@ jobs:
100100
uses: actions/checkout@v4
101101
- name: Link Checker
102102
uses: AlexanderDokuchaev/md-dead-link-check@v1.0.1
103+
lint-swift:
104+
name: Lint Swift
105+
runs-on: ubuntu-latest
106+
container: swift:6.0
107+
steps:
108+
- name: Checkout Repo
109+
uses: actions/checkout@v4
110+
- name: Lint Swift
111+
run: swift run --package-path CLI swiftformat . --lint

.swiftformat

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# format options
2+
--indent tab
3+
--modifierorder nonisolated,open,public,internal,fileprivate,private,private(set),final,override,required,convenience
4+
--ranges no-space
5+
--extensionacl on-declarations
6+
--funcattributes prev-line
7+
--typeattributes prev-line
8+
--storedvarattrs same-line
9+
--hexgrouping none
10+
--decimalgrouping 3
11+
12+
# rules
13+
--enable isEmpty
14+
--enable wrapEnumCases
15+
--enable wrapMultilineStatementBraces
16+
--disable consistentSwitchCaseSpacing
17+
--disable blankLineAfterSwitchCase
18+
19+
# global
20+
--swiftversion 6.0

CLI/Package.resolved

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CLI/Package.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "CLI",
8+
platforms: [
9+
.macOS(.v14),
10+
],
11+
products: [],
12+
dependencies: [
13+
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.56.1"),
14+
],
15+
targets: []
16+
)

Package.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "swift-async-queue",
8-
platforms: [
9-
.macOS(.v10_15),
10-
.iOS(.v13),
11-
.tvOS(.v13),
12-
.watchOS(.v6),
13-
.macCatalyst(.v13),
14-
.visionOS(.v1),
15-
],
16-
products: [
17-
.library(
18-
name: "AsyncQueue",
19-
targets: ["AsyncQueue"]
20-
),
21-
],
22-
targets: [
23-
.target(
24-
name: "AsyncQueue",
25-
dependencies: [],
26-
swiftSettings: [
27-
.swiftLanguageMode(.v6),
28-
]
29-
),
30-
.testTarget(
31-
name: "AsyncQueueTests",
32-
dependencies: ["AsyncQueue"],
33-
swiftSettings: [
34-
.swiftLanguageMode(.v6),
35-
]
36-
),
37-
]
7+
name: "swift-async-queue",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.tvOS(.v13),
12+
.watchOS(.v6),
13+
.macCatalyst(.v13),
14+
.visionOS(.v1),
15+
],
16+
products: [
17+
.library(
18+
name: "AsyncQueue",
19+
targets: ["AsyncQueue"]
20+
),
21+
],
22+
targets: [
23+
.target(
24+
name: "AsyncQueue",
25+
dependencies: [],
26+
swiftSettings: [
27+
.swiftLanguageMode(.v6),
28+
]
29+
),
30+
.testTarget(
31+
name: "AsyncQueueTests",
32+
dependencies: ["AsyncQueue"],
33+
swiftSettings: [
34+
.swiftLanguageMode(.v6),
35+
]
36+
),
37+
]
3838
)

Scripts/build.swift

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -5,111 +5,111 @@ import Foundation
55
// Usage: build.swift platforms
66

77
func execute(commandPath: String, arguments: [String]) throws {
8-
let task = Process()
9-
task.executableURL = .init(filePath: commandPath)
10-
task.arguments = arguments
11-
print("Launching command: \(commandPath) \(arguments.joined(separator: " "))")
12-
try task.run()
13-
task.waitUntilExit()
14-
guard task.terminationStatus == 0 else {
15-
throw TaskError.code(task.terminationStatus)
16-
}
8+
let task = Process()
9+
task.executableURL = .init(filePath: commandPath)
10+
task.arguments = arguments
11+
print("Launching command: \(commandPath) \(arguments.joined(separator: " "))")
12+
try task.run()
13+
task.waitUntilExit()
14+
guard task.terminationStatus == 0 else {
15+
throw TaskError.code(task.terminationStatus)
16+
}
1717
}
1818

1919
enum TaskError: Error {
20-
case code(Int32)
20+
case code(Int32)
2121
}
2222

2323
enum Platform: String, CaseIterable, CustomStringConvertible {
24-
case iOS_18
25-
case tvOS_18
26-
case macOS_15
27-
case macCatalyst_15
28-
case watchOS_11
29-
case visionOS_2
30-
31-
var destination: String {
32-
switch self {
33-
case .iOS_18:
34-
"platform=iOS Simulator,OS=18.0,name=iPad (10th generation)"
35-
36-
case .tvOS_18:
37-
"platform=tvOS Simulator,OS=18.0,name=Apple TV"
38-
39-
case .macOS_15,
40-
.macCatalyst_15:
41-
"platform=OS X"
42-
43-
case .watchOS_11:
44-
"OS=11.0,name=Apple Watch Series 10 (46mm)"
45-
46-
case .visionOS_2:
47-
"OS=2.0,name=Apple Vision Pro"
48-
}
49-
}
50-
51-
var sdk: String {
52-
switch self {
53-
case .iOS_18:
54-
"iphonesimulator"
55-
56-
case .tvOS_18:
57-
"appletvsimulator"
58-
59-
case .macOS_15,
60-
.macCatalyst_15:
61-
"macosx15.0"
62-
63-
case .watchOS_11:
64-
"watchsimulator"
65-
66-
case .visionOS_2:
67-
"xrsimulator"
68-
}
69-
}
70-
71-
var derivedDataPath: String {
72-
".build/derivedData/" + description
73-
}
74-
75-
var description: String {
76-
rawValue
77-
}
24+
case iOS_18
25+
case tvOS_18
26+
case macOS_15
27+
case macCatalyst_15
28+
case watchOS_11
29+
case visionOS_2
30+
31+
var destination: String {
32+
switch self {
33+
case .iOS_18:
34+
"platform=iOS Simulator,OS=18.0,name=iPad (10th generation)"
35+
36+
case .tvOS_18:
37+
"platform=tvOS Simulator,OS=18.0,name=Apple TV"
38+
39+
case .macOS_15,
40+
.macCatalyst_15:
41+
"platform=OS X"
42+
43+
case .watchOS_11:
44+
"OS=11.0,name=Apple Watch Series 10 (46mm)"
45+
46+
case .visionOS_2:
47+
"OS=2.0,name=Apple Vision Pro"
48+
}
49+
}
50+
51+
var sdk: String {
52+
switch self {
53+
case .iOS_18:
54+
"iphonesimulator"
55+
56+
case .tvOS_18:
57+
"appletvsimulator"
58+
59+
case .macOS_15,
60+
.macCatalyst_15:
61+
"macosx15.0"
62+
63+
case .watchOS_11:
64+
"watchsimulator"
65+
66+
case .visionOS_2:
67+
"xrsimulator"
68+
}
69+
}
70+
71+
var derivedDataPath: String {
72+
".build/derivedData/" + description
73+
}
74+
75+
var description: String {
76+
rawValue
77+
}
7878
}
7979

8080
guard CommandLine.arguments.count > 1 else {
81-
print("Usage: build.swift platforms")
82-
throw TaskError.code(1)
81+
print("Usage: build.swift platforms")
82+
throw TaskError.code(1)
8383
}
8484

8585
let rawPlatforms = CommandLine.arguments[1].components(separatedBy: ",")
8686

8787
for rawPlatform in rawPlatforms {
88-
guard let platform = Platform(rawValue: rawPlatform) else {
89-
print("Received unknown platform type \(rawPlatform)")
90-
print("Possible platform types are: \(Platform.allCases)")
91-
throw TaskError.code(1)
92-
}
93-
94-
var xcodeBuildArguments = [
95-
"-scheme", "swift-async-queue",
96-
"-sdk", platform.sdk,
97-
"-derivedDataPath", platform.derivedDataPath,
98-
"-PBXBuildsContinueAfterErrors=0",
99-
"OTHER_SWIFT_FLAGS=-warnings-as-errors",
100-
]
101-
102-
if !platform.destination.isEmpty {
103-
xcodeBuildArguments.append("-destination")
104-
xcodeBuildArguments.append(platform.destination)
105-
}
106-
xcodeBuildArguments.append("-enableCodeCoverage")
107-
xcodeBuildArguments.append("YES")
108-
xcodeBuildArguments.append("build")
109-
xcodeBuildArguments.append("test")
110-
xcodeBuildArguments.append("-test-iterations")
111-
xcodeBuildArguments.append("100")
112-
xcodeBuildArguments.append("-run-tests-until-failure")
113-
114-
try execute(commandPath: "/usr/bin/xcodebuild", arguments: xcodeBuildArguments)
88+
guard let platform = Platform(rawValue: rawPlatform) else {
89+
print("Received unknown platform type \(rawPlatform)")
90+
print("Possible platform types are: \(Platform.allCases)")
91+
throw TaskError.code(1)
92+
}
93+
94+
var xcodeBuildArguments = [
95+
"-scheme", "swift-async-queue",
96+
"-sdk", platform.sdk,
97+
"-derivedDataPath", platform.derivedDataPath,
98+
"-PBXBuildsContinueAfterErrors=0",
99+
"OTHER_SWIFT_FLAGS=-warnings-as-errors",
100+
]
101+
102+
if !platform.destination.isEmpty {
103+
xcodeBuildArguments.append("-destination")
104+
xcodeBuildArguments.append(platform.destination)
105+
}
106+
xcodeBuildArguments.append("-enableCodeCoverage")
107+
xcodeBuildArguments.append("YES")
108+
xcodeBuildArguments.append("build")
109+
xcodeBuildArguments.append("test")
110+
xcodeBuildArguments.append("-test-iterations")
111+
xcodeBuildArguments.append("100")
112+
xcodeBuildArguments.append("-run-tests-until-failure")
113+
114+
try execute(commandPath: "/usr/bin/xcodebuild", arguments: xcodeBuildArguments)
115115
}

0 commit comments

Comments
 (0)