Skip to content

Commit f0ba4f4

Browse files
authored
Introduce .swift-format and enable linting requirement on PR requests (#162)
* Introduce .swift-format and enable linting requirement on PR requests * Update spacesAroundRangeFormationOperators to false
1 parent 15e0df9 commit f0ba4f4

32 files changed

+415
-330
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ jobs:
2828
# Test dependencies
2929
yum install -y procps
3030
fi
31-
linux_build_command: 'swift test && swift test --disable-default-traits'
31+
linux_build_command: 'swift-format lint -s -r --configuration ./.swift-format . && swift test && swift test --disable-default-traits'
3232
windows_swift_versions: '["6.1", "nightly-main"]'
3333
windows_build_command: |
3434
Invoke-Program swift test
3535
Invoke-Program swift test --disable-default-traits
3636
enable_macos_checks: true
3737
macos_xcode_versions: '["16.3"]'
38-
macos_build_command: 'xcrun swift test && xcrun swift test --disable-default-traits'
38+
macos_build_command: 'xcrun swift-format lint -s -r --configuration ./.swift-format . && xcrun swift test && xcrun swift test --disable-default-traits'
3939
enable_linux_static_sdk_build: true
4040
linux_static_sdk_versions: '["6.1", "nightly-6.2"]'
4141
linux_static_sdk_build_command: |

.swift-format

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"fileScopedDeclarationPrivacy": {
3+
"accessLevel": "private"
4+
},
5+
"indentConditionalCompilationBlocks": false,
6+
"indentSwitchCaseLabels": false,
7+
"indentation": {
8+
"spaces": 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents": false,
11+
"lineBreakBeforeControlFlowKeywords": false,
12+
"lineBreakBeforeEachArgument": false,
13+
"lineBreakBeforeEachGenericRequirement": false,
14+
"lineBreakBetweenDeclarationAttributes": false,
15+
"lineLength": 9999,
16+
"maximumBlankLines": 1,
17+
"multiElementCollectionTrailingCommas": true,
18+
"noAssignmentInExpressions": {
19+
"allowedFunctions": [
20+
"XCTAssertNoThrow"
21+
]
22+
},
23+
"prioritizeKeepingFunctionOutputTogether": false,
24+
"respectsExistingLineBreaks": true,
25+
"rules": {
26+
"AllPublicDeclarationsHaveDocumentation": false,
27+
"AlwaysUseLiteralForEmptyCollectionInit": false,
28+
"AlwaysUseLowerCamelCase": false,
29+
"AmbiguousTrailingClosureOverload": false,
30+
"AvoidRetroactiveConformances": false,
31+
"BeginDocumentationCommentWithOneLineSummary": false,
32+
"DoNotUseSemicolons": false,
33+
"DontRepeatTypeInStaticProperties": false,
34+
"FileScopedDeclarationPrivacy": false,
35+
"FullyIndirectEnum": false,
36+
"GroupNumericLiterals": false,
37+
"IdentifiersMustBeASCII": false,
38+
"NeverForceUnwrap": false,
39+
"NeverUseForceTry": false,
40+
"NeverUseImplicitlyUnwrappedOptionals": false,
41+
"NoAccessLevelOnExtensionDeclaration": false,
42+
"NoAssignmentInExpressions": false,
43+
"NoBlockComments": false,
44+
"NoCasesWithOnlyFallthrough": false,
45+
"NoEmptyLinesOpeningClosingBraces": false,
46+
"NoEmptyTrailingClosureParentheses": false,
47+
"NoLabelsInCasePatterns": false,
48+
"NoLeadingUnderscores": false,
49+
"NoParensAroundConditions": false,
50+
"NoPlaygroundLiterals": false,
51+
"NoVoidReturnOnFunctionSignature": false,
52+
"OmitExplicitReturns": false,
53+
"OneCasePerLine": false,
54+
"OneVariableDeclarationPerLine": false,
55+
"OnlyOneTrailingClosureArgument": false,
56+
"OrderedImports": false,
57+
"ReplaceForEachWithForLoop": false,
58+
"ReturnVoidInsteadOfEmptyTuple": false,
59+
"TypeNamesShouldBeCapitalized": false,
60+
"UseEarlyExits": false,
61+
"UseExplicitNilCheckInConditions": false,
62+
"UseLetInEveryBoundCaseVariable": false,
63+
"UseShorthandTypeNames": false,
64+
"UseSingleLinePropertyGetter": false,
65+
"UseSynthesizedInitializer": false,
66+
"UseTripleSlashForDocumentationComments": false,
67+
"UseWhereClausesInForLoops": false,
68+
"ValidateDocumentationComments": false
69+
},
70+
"spacesAroundRangeFormationOperators": false,
71+
"spacesBeforeEndOfLineComments": 1,
72+
"tabWidth": 4,
73+
"version": 1
74+
}

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let package = Package(
5656
.product(name: "SystemPackage", package: "swift-system"),
5757
],
5858
path: "Sources/Subprocess",
59-
exclude: [ "CMakeLists.txt" ],
59+
exclude: ["CMakeLists.txt"],
6060
swiftSettings: [
6161
.enableExperimentalFeature("StrictConcurrency"),
6262
.enableExperimentalFeature("NonescapableTypes"),
@@ -73,7 +73,7 @@ let package = Package(
7373
.product(name: "SystemPackage", package: "swift-system"),
7474
],
7575
swiftSettings: [
76-
.enableExperimentalFeature("Span"),
76+
.enableExperimentalFeature("Span")
7777
] + packageSwiftSettings
7878
),
7979

@@ -91,7 +91,7 @@ let package = Package(
9191
.target(
9292
name: "_SubprocessCShims",
9393
path: "Sources/_SubprocessCShims",
94-
exclude: [ "CMakeLists.txt" ]
94+
exclude: ["CMakeLists.txt"]
9595
),
9696
]
9797
)

Sources/Subprocess/API.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ public func run<
133133
standardError: result.value.standardError
134134
)
135135
}
136-
#endif // SubprocessSpan
137-
136+
#endif // SubprocessSpan
138137

139138
// MARK: - Custom Execution Body
140139

Sources/Subprocess/AsyncBufferSequence.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ extension AsyncBufferSequence {
192192
}
193193

194194
// https://en.wikipedia.org/wiki/Newline#Unicode
195-
let lineFeed = Encoding.CodeUnit(0x0A)
195+
let lineFeed = Encoding.CodeUnit(0x0A)
196196
/// let verticalTab = Encoding.CodeUnit(0x0B)
197197
/// let formFeed = Encoding.CodeUnit(0x0C)
198-
let carriageReturn = Encoding.CodeUnit(0x0D)
198+
let carriageReturn = Encoding.CodeUnit(0x0D)
199199
// carriageReturn + lineFeed
200200
let newLine1: Encoding.CodeUnit
201201
let newLine2: Encoding.CodeUnit
@@ -207,24 +207,24 @@ extension AsyncBufferSequence {
207207
let paragraphSeparator3: Encoding.CodeUnit
208208
switch Encoding.CodeUnit.self {
209209
case is UInt8.Type:
210-
newLine1 = Encoding.CodeUnit(0xC2)
211-
newLine2 = Encoding.CodeUnit(0x85)
210+
newLine1 = Encoding.CodeUnit(0xC2)
211+
newLine2 = Encoding.CodeUnit(0x85)
212212

213-
lineSeparator1 = Encoding.CodeUnit(0xE2)
214-
lineSeparator2 = Encoding.CodeUnit(0x80)
215-
lineSeparator3 = Encoding.CodeUnit(0xA8)
213+
lineSeparator1 = Encoding.CodeUnit(0xE2)
214+
lineSeparator2 = Encoding.CodeUnit(0x80)
215+
lineSeparator3 = Encoding.CodeUnit(0xA8)
216216

217217
paragraphSeparator1 = Encoding.CodeUnit(0xE2)
218218
paragraphSeparator2 = Encoding.CodeUnit(0x80)
219219
paragraphSeparator3 = Encoding.CodeUnit(0xA9)
220220
case is UInt16.Type, is UInt32.Type:
221221
// UTF16 and UTF32 use one byte for all
222-
newLine1 = Encoding.CodeUnit(0x0085)
223-
newLine2 = Encoding.CodeUnit(0x0085)
222+
newLine1 = Encoding.CodeUnit(0x0085)
223+
newLine2 = Encoding.CodeUnit(0x0085)
224224

225-
lineSeparator1 = Encoding.CodeUnit(0x2028)
226-
lineSeparator2 = Encoding.CodeUnit(0x2028)
227-
lineSeparator3 = Encoding.CodeUnit(0x2028)
225+
lineSeparator1 = Encoding.CodeUnit(0x2028)
226+
lineSeparator2 = Encoding.CodeUnit(0x2028)
227+
lineSeparator3 = Encoding.CodeUnit(0x2028)
228228

229229
paragraphSeparator1 = Encoding.CodeUnit(0x2029)
230230
paragraphSeparator2 = Encoding.CodeUnit(0x2029)
@@ -285,7 +285,7 @@ extension AsyncBufferSequence {
285285
continue
286286
}
287287
return yield()
288-
case lineFeed ..< carriageReturn, newLine1, lineSeparator1, paragraphSeparator1:
288+
case lineFeed..<carriageReturn, newLine1, lineSeparator1, paragraphSeparator1:
289289
return yield()
290290
default:
291291
continue
@@ -361,7 +361,7 @@ private let _pageSize: Int = Int(getpagesize())
361361
private let _pageSize: Int = Int(getpagesize())
362362
#elseif canImport(C)
363363
private let _pageSize: Int = Int(getpagesize())
364-
#endif // canImport(Darwin)
364+
#endif // canImport(Darwin)
365365

366366
@inline(__always)
367367
internal var readBufferSize: Int {

Sources/Subprocess/Buffer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
@preconcurrency internal import Dispatch
1414
#endif
1515

16-
1716
extension AsyncBufferSequence {
1817
/// A immutable collection of bytes
1918
public struct Buffer: Sendable {
@@ -33,7 +32,7 @@ extension AsyncBufferSequence {
3332
if _fastPath(slices.count == 1) {
3433
return [.init(data: slices[0], backingData: data)]
3534
}
36-
return slices.map{ .init(data: $0, backingData: data) }
35+
return slices.map { .init(data: $0, backingData: data) }
3736
}
3837
#else
3938
internal let data: [UInt8]
@@ -78,6 +77,7 @@ extension AsyncBufferSequence.Buffer {
7877
}
7978

8079
#if SubprocessSpan
80+
// swift-format-ignore
8181
// Access the storage backing this Buffer
8282
public var bytes: RawSpan {
8383
@lifetime(borrow self)
@@ -87,7 +87,7 @@ extension AsyncBufferSequence.Buffer {
8787
return _overrideLifetime(of: bytes, to: self)
8888
}
8989
}
90-
#endif // SubprocessSpan
90+
#endif // SubprocessSpan
9191
}
9292

9393
// MARK: - Hashable, Equatable

Sources/Subprocess/Configuration.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ extension Environment: CustomStringConvertible, CustomDebugStringConvertible {
404404
if environmentString.utf8.first == Character("=").utf8.first {
405405
continue
406406
}
407-
#endif // os(Windows)
407+
#endif // os(Windows)
408408

409409
guard let delimiter = environmentString.firstIndex(of: "=") else {
410410
continue
@@ -509,17 +509,17 @@ internal enum StringOrRawBytes: Sendable, Hashable {
509509
func createRawBytes() -> UnsafeMutablePointer<CChar> {
510510
switch self {
511511
case .string(let string):
512-
#if os(Windows)
512+
#if os(Windows)
513513
return _strdup(string)
514-
#else
514+
#else
515515
return strdup(string)
516-
#endif
516+
#endif
517517
case .rawBytes(let rawBytes):
518-
#if os(Windows)
518+
#if os(Windows)
519519
return _strdup(rawBytes)
520-
#else
520+
#else
521521
return strdup(rawBytes)
522-
#endif
522+
#endif
523523
}
524524
}
525525

@@ -1026,11 +1026,10 @@ internal struct _OrderedSet<Element: Hashable & Sendable>: Hashable, Sendable {
10261026
}
10271027
}
10281028

1029-
extension _OrderedSet : Sequence {
1029+
extension _OrderedSet: Sequence {
10301030
typealias Iterator = Array<Element>.Iterator
10311031

10321032
internal func makeIterator() -> Iterator {
10331033
return self.elements.makeIterator()
10341034
}
10351035
}
1036-

Sources/Subprocess/IO/AsyncIO+Dispatch.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class AsyncIO: Sendable {
2727

2828
internal init() {}
2929

30-
internal func shutdown() { /* noop on Darwin */ }
30+
internal func shutdown() { /* noop on Darwin */ }
3131

3232
internal func read(
3333
from diskIO: borrowing IOChannel,
@@ -104,7 +104,7 @@ final class AsyncIO: Sendable {
104104
}
105105
}
106106
}
107-
#endif // SubprocessSpan
107+
#endif // SubprocessSpan
108108

109109
internal func write(
110110
_ array: [UInt8],
@@ -167,7 +167,7 @@ final class AsyncIO: Sendable {
167167
}
168168

169169
#if !canImport(Darwin)
170-
extension DispatchData: @retroactive @unchecked Sendable { }
170+
extension DispatchData: @retroactive @unchecked Sendable {}
171171
#endif
172172

173173
#endif

0 commit comments

Comments
 (0)