Skip to content

Commit f6085a3

Browse files
authored
Apply the same .swift-format as the generator repo (#68)
Apply the same .swift-format as the generator repo ### Motivation Bring the runtime library formatting in line with the generator repo. Also fixes apple/swift-openapi-generator#250. ### Modifications Copied the `.swift-format` file, reran swift-format. Only formatting changes. ### Result Consistent style. ### Test Plan CI. Reviewed by: gjcairo Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (api breakage) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #68
1 parent a51b3bd commit f6085a3

File tree

62 files changed

+1107
-3657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1107
-3657
lines changed

.swift-format

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
"lineLength" : 120,
1515
"maximumBlankLines" : 1,
1616
"prioritizeKeepingFunctionOutputTogether" : false,
17-
"respectsExistingLineBreaks" : true,
17+
"respectsExistingLineBreaks" : false,
1818
"rules" : {
1919
"AllPublicDeclarationsHaveDocumentation" : true,
2020
"AlwaysUseLowerCamelCase" : false,
21+
"AlwaysUseLiteralForEmptyCollectionInit" : true,
2122
"AmbiguousTrailingClosureOverload" : true,
2223
"BeginDocumentationCommentWithOneLineSummary" : false,
2324
"DoNotUseSemicolons" : true,
@@ -38,16 +39,18 @@
3839
"NoLeadingUnderscores" : false,
3940
"NoParensAroundConditions" : true,
4041
"NoVoidReturnOnFunctionSignature" : true,
42+
"OmitExplicitReturns" : true,
4143
"OneCasePerLine" : true,
4244
"OneVariableDeclarationPerLine" : true,
4345
"OnlyOneTrailingClosureArgument" : true,
4446
"OrderedImports" : false,
47+
"ReplaceForEachWithForLoop" : true,
4548
"ReturnVoidInsteadOfEmptyTuple" : true,
46-
"UseEarlyExits" : true,
49+
"UseEarlyExits" : false,
4750
"UseLetInEveryBoundCaseVariable" : false,
4851
"UseShorthandTypeNames" : true,
4952
"UseSingleLinePropertyGetter" : false,
50-
"UseSynthesizedInitializer" : false,
53+
"UseSynthesizedInitializer" : true,
5154
"UseTripleSlashForDocumentationComments" : true,
5255
"UseWhereClausesInForLoops" : false,
5356
"ValidateDocumentationComments" : true

Sources/OpenAPIRuntime/Base/Acceptable.swift

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public struct QualityValue: Sendable, Hashable {
2929

3030
/// Returns a Boolean value indicating whether the quality value is
3131
/// at its default value 1.0.
32-
public var isDefault: Bool {
33-
thousands == 1000
34-
}
32+
public var isDefault: Bool { thousands == 1000 }
3533

3634
/// Creates a new quality value from the provided floating-point number.
3735
///
@@ -46,26 +44,20 @@ public struct QualityValue: Sendable, Hashable {
4644
}
4745

4846
/// The value represented as a floating-point number between 0.0 and 1.0, inclusive.
49-
public var doubleValue: Double {
50-
Double(thousands) / 1000
51-
}
47+
public var doubleValue: Double { Double(thousands) / 1000 }
5248
}
5349

5450
extension QualityValue: RawRepresentable {
5551
/// Creates a new `QualityValue` instance from a raw string value.
5652
///
5753
/// - Parameter rawValue: A string representing the quality value.
5854
public init?(rawValue: String) {
59-
guard let doubleValue = Double(rawValue) else {
60-
return nil
61-
}
55+
guard let doubleValue = Double(rawValue) else { return nil }
6256
self.init(doubleValue: doubleValue)
6357
}
6458

6559
/// The raw string representation of the `QualityValue`.
66-
public var rawValue: String {
67-
String(format: "%0.3f", doubleValue)
68-
}
60+
public var rawValue: String { String(format: "%0.3f", doubleValue) }
6961
}
7062

7163
extension QualityValue: ExpressibleByIntegerLiteral {
@@ -86,18 +78,14 @@ extension QualityValue: ExpressibleByFloatLiteral {
8678
/// Creates a new `QualityValue` instance from a floating-point literal value.
8779
///
8880
/// - Parameter value: A floating-point literal value representing the quality value.
89-
public init(floatLiteral value: Double) {
90-
self.init(doubleValue: value)
91-
}
81+
public init(floatLiteral value: Double) { self.init(doubleValue: value) }
9282
}
9383

9484
extension Array {
9585

9686
/// Returns the default values for the acceptable type.
9787
public static func defaultValues<T: AcceptableProtocol>() -> [AcceptHeaderContentType<T>]
98-
where Element == AcceptHeaderContentType<T> {
99-
T.allCases.map { .init(contentType: $0) }
100-
}
88+
where Element == AcceptHeaderContentType<T> { T.allCases.map { .init(contentType: $0) } }
10189
}
10290

10391
/// A wrapper of an individual content type in the accept header.
@@ -129,9 +117,7 @@ public struct AcceptHeaderContentType<ContentType: AcceptableProtocol>: Sendable
129117

130118
/// Returns the default set of acceptable content types for this type, in
131119
/// the order specified in the OpenAPI document.
132-
public static var defaultValues: [Self] {
133-
ContentType.allCases.map { .init(contentType: $0) }
134-
}
120+
public static var defaultValues: [Self] { ContentType.allCases.map { .init(contentType: $0) } }
135121
}
136122

137123
extension AcceptHeaderContentType: RawRepresentable {
@@ -161,18 +147,12 @@ extension AcceptHeaderContentType: RawRepresentable {
161147
}
162148

163149
/// The raw representation of the content negotiation as a MIME type string.
164-
public var rawValue: String {
165-
contentType.rawValue + (quality.isDefault ? "" : "; q=\(quality.rawValue)")
166-
}
150+
public var rawValue: String { contentType.rawValue + (quality.isDefault ? "" : "; q=\(quality.rawValue)") }
167151
}
168152

169153
extension Array {
170154

171155
/// Returns the array sorted by the quality value, highest quality first.
172156
public func sortedByQuality<T: AcceptableProtocol>() -> [AcceptHeaderContentType<T>]
173-
where Element == AcceptHeaderContentType<T> {
174-
sorted { a, b in
175-
a.quality.doubleValue > b.quality.doubleValue
176-
}
177-
}
157+
where Element == AcceptHeaderContentType<T> { sorted { a, b in a.quality.doubleValue > b.quality.doubleValue } }
178158
}

Sources/OpenAPIRuntime/Base/Base64EncodedData.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ public struct Base64EncodedData: Sendable, Hashable {
5656

5757
/// Initializes an instance of ``Base64EncodedData`` wrapping the provided slice of bytes.
5858
/// - Parameter data: The underlying bytes to wrap.
59-
public init(data: ArraySlice<UInt8>) {
60-
self.data = data
61-
}
59+
public init(data: ArraySlice<UInt8>) { self.data = data }
6260
}
6361

6462
extension Base64EncodedData: Codable {

Sources/OpenAPIRuntime/Base/CopyOnWriteBox.swift

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,31 @@
1616
///
1717
/// It also enables recursive types by introducing a "box" into the cycle, which
1818
/// allows the owning type to have a finite size.
19-
@_spi(Generated)
20-
public struct CopyOnWriteBox<Wrapped> {
19+
@_spi(Generated) public struct CopyOnWriteBox<Wrapped> {
2120

2221
/// The reference type storage for the box.
23-
@usableFromInline
24-
internal final class Storage {
22+
@usableFromInline internal final class Storage {
2523

2624
/// The stored value.
27-
@usableFromInline
28-
var value: Wrapped
25+
@usableFromInline var value: Wrapped
2926

3027
/// Creates a new storage with the provided initial value.
3128
/// - Parameter value: The initial value to store in the box.
32-
@inlinable
33-
init(value: Wrapped) {
34-
self.value = value
35-
}
29+
@inlinable init(value: Wrapped) { self.value = value }
3630
}
3731

3832
/// The internal storage of the box.
39-
@usableFromInline
40-
internal var storage: Storage
33+
@usableFromInline internal var storage: Storage
4134

4235
/// Creates a new box.
4336
/// - Parameter value: The value to store in the box.
44-
@inlinable
45-
public init(value: Wrapped) {
46-
self.storage = .init(value: value)
47-
}
37+
@inlinable public init(value: Wrapped) { self.storage = .init(value: value) }
4838

4939
/// The stored value whose accessors enforce copy-on-write semantics.
50-
@inlinable
51-
public var value: Wrapped {
52-
get {
53-
storage.value
54-
}
40+
@inlinable public var value: Wrapped {
41+
get { storage.value }
5542
_modify {
56-
if !isKnownUniquelyReferenced(&storage) {
57-
storage = Storage(value: storage.value)
58-
}
43+
if !isKnownUniquelyReferenced(&storage) { storage = Storage(value: storage.value) }
5944
yield &storage.value
6045
}
6146
}
@@ -73,10 +58,7 @@ extension CopyOnWriteBox: Encodable where Wrapped: Encodable {
7358
///
7459
/// - Parameter encoder: The encoder to write data to.
7560
/// - Throws: On an encoding error.
76-
@inlinable
77-
public func encode(to encoder: any Encoder) throws {
78-
try value.encode(to: encoder)
79-
}
61+
@inlinable public func encode(to encoder: any Encoder) throws { try value.encode(to: encoder) }
8062
}
8163

8264
extension CopyOnWriteBox: Decodable where Wrapped: Decodable {
@@ -88,8 +70,7 @@ extension CopyOnWriteBox: Decodable where Wrapped: Decodable {
8870
///
8971
/// - Parameter decoder: The decoder to read data from.
9072
/// - Throws: On a decoding error.
91-
@inlinable
92-
public init(from decoder: any Decoder) throws {
73+
@inlinable public init(from decoder: any Decoder) throws {
9374
let value = try Wrapped(from: decoder)
9475
self.init(value: value)
9576
}
@@ -106,11 +87,7 @@ extension CopyOnWriteBox: Equatable where Wrapped: Equatable {
10687
/// - lhs: A value to compare.
10788
/// - rhs: Another value to compare.
10889
/// - Returns: A Boolean value indicating whether the values are equal.
109-
@inlinable
110-
public static func == (
111-
lhs: CopyOnWriteBox<Wrapped>,
112-
rhs: CopyOnWriteBox<Wrapped>
113-
) -> Bool {
90+
@inlinable public static func == (lhs: CopyOnWriteBox<Wrapped>, rhs: CopyOnWriteBox<Wrapped>) -> Bool {
11491
lhs.value == rhs.value
11592
}
11693
}
@@ -132,10 +109,7 @@ extension CopyOnWriteBox: Hashable where Wrapped: Hashable {
132109
///
133110
/// - Parameter hasher: The hasher to use when combining the components
134111
/// of this instance.
135-
@inlinable
136-
public func hash(into hasher: inout Hasher) {
137-
hasher.combine(value)
138-
}
112+
@inlinable public func hash(into hasher: inout Hasher) { hasher.combine(value) }
139113
}
140114

141115
extension CopyOnWriteBox: CustomStringConvertible where Wrapped: CustomStringConvertible {
@@ -163,10 +137,7 @@ extension CopyOnWriteBox: CustomStringConvertible where Wrapped: CustomStringCon
163137
///
164138
/// The conversion of `p` to a string in the assignment to `s` uses the
165139
/// `Point` type's `description` property.
166-
@inlinable
167-
public var description: String {
168-
value.description
169-
}
140+
@inlinable public var description: String { value.description }
170141
}
171142

172143
extension CopyOnWriteBox: CustomDebugStringConvertible where Wrapped: CustomDebugStringConvertible {
@@ -194,10 +165,7 @@ extension CopyOnWriteBox: CustomDebugStringConvertible where Wrapped: CustomDebu
194165
///
195166
/// The conversion of `p` to a string in the assignment to `s` uses the
196167
/// `Point` type's `debugDescription` property.
197-
@inlinable
198-
public var debugDescription: String {
199-
value.debugDescription
200-
}
168+
@inlinable public var debugDescription: String { value.debugDescription }
201169
}
202170

203171
extension CopyOnWriteBox: @unchecked Sendable where Wrapped: Sendable {}

0 commit comments

Comments
 (0)