Skip to content

Commit b20d95c

Browse files
committed
Update swiftformat
1 parent 2004900 commit b20d95c

File tree

22 files changed

+87
-92
lines changed

22 files changed

+87
-92
lines changed

.swiftformat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,11 @@
99
--patternlet inline
1010
--stripunusedargs unnamed-only
1111
--ifdef no-indent
12+
--extensionacl on-declarations
13+
--disable typeSugar
14+
--disable andOperator
15+
--disable wrapMultilineStatementBraces
16+
--disable enumNamespaces
17+
--disable redundantExtensionACL
1218

1319
# rules

Examples/CloudFunctions/Sources/CurrencyExchange/main.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,16 @@ struct ExchangeRatesCalculator {
161161
dateFormatter.dateFormat = "dd/MMM/yy"
162162
let interval: DateInterval?
163163
if let period = try document.nodes(forXPath: "/exchangeRateMonthList/@Period").first?.stringValue,
164-
period.count == 26
165-
{
164+
period.count == 26 {
166165
// "01/Sep/2018 to 30/Sep/2018"
167166
let startString = period[period.startIndex ..< period.index(period.startIndex, offsetBy: 11)]
168167
let to = period[startString.endIndex ..< period.index(startString.endIndex, offsetBy: 4)]
169168
let endString = period[to.endIndex ..< period.index(to.endIndex, offsetBy: 11)]
170169
if let startDate = dateFormatter.date(from: String(startString)),
171-
let startDay = calendar.dateInterval(of: .day, for: startDate),
172-
to == " to ",
173-
let endDate = dateFormatter.date(from: String(endString)),
174-
let endDay = calendar.dateInterval(of: .day, for: endDate)
175-
{
170+
let startDay = calendar.dateInterval(of: .day, for: startDate),
171+
to == " to ",
172+
let endDate = dateFormatter.date(from: String(endString)),
173+
let endDay = calendar.dateInterval(of: .day, for: endDate) {
176174
interval = DateInterval(start: startDay.start, end: endDay.end)
177175
} else {
178176
interval = nil
@@ -184,9 +182,8 @@ struct ExchangeRatesCalculator {
184182
let ratesByCurrencyCode: [String: Decimal?] = Dictionary(uniqueKeysWithValues: try currencyCodes.map {
185183
let xpathCurrency = $0.replacingOccurrences(of: "'", with: "&apos;")
186184
if let rateString = try document.nodes(forXPath: "/exchangeRateMonthList/exchangeRate/currencyCode[text()='\(xpathCurrency)']/../rateNew/text()").first?.stringValue,
187-
// We must parse the decimal data using the UK locale, not the system one.
188-
let rate = Decimal(string: rateString, locale: self.locale)
189-
{
185+
// We must parse the decimal data using the UK locale, not the system one.
186+
let rate = Decimal(string: rateString, locale: self.locale) {
190187
return ($0, rate)
191188
} else {
192189
return ($0, nil)

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
2323
.package(url: "https://github.com/swift-server/swift-backtrace.git", from: "1.1.0"),
2424
.package(url: "https://github.com/stevapple/tencent-cloud-core.git", .upToNextMinor(from: "0.2.0")),
25-
.package(name: "Gzip", url: "https://github.com/1024jp/GzipSwift.git", from: "5.1.0")
25+
.package(name: "Gzip", url: "https://github.com/1024jp/GzipSwift.git", from: "5.1.0"),
2626
],
2727
targets: [
2828
.target(name: "TencentSCFRuntime", dependencies: [
@@ -46,7 +46,7 @@ let package = Package(
4646
.product(name: "NIOFoundationCompat", package: "swift-nio"),
4747
]),
4848
.target(name: "TencentSCFEvents", dependencies: [
49-
.byName(name: "Gzip")
49+
.byName(name: "Gzip"),
5050
]),
5151
.testTarget(name: "TencentSCFEventsTests", dependencies: ["TencentSCFEvents"]),
5252
// testing helper

Sources/TencentSCFEvents/APIGateway/APIGateway.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public enum APIGateway {
5353
public typealias Response = APIResponse
5454
}
5555

56-
internal extension APIGateway {
57-
static let defaultJSONDecoder = JSONDecoder()
58-
static let defaultJSONEncoder = JSONEncoder()
56+
extension APIGateway {
57+
internal static let defaultJSONDecoder = JSONDecoder()
58+
internal static let defaultJSONEncoder = JSONEncoder()
5959
}

Sources/TencentSCFEvents/APIResponse.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension APIResponse {
3333
do {
3434
rawBody = try body()
3535
} catch let err {
36-
self.headers = headers.merging(["Content-Type": "application/json"]) { (_, default) in `default` }
36+
self.headers = headers.merging(["Content-Type": "application/json"]) { _, `default` in `default` }
3737
self.statusCode = .internalServerError
3838
self.isBase64Encoded = false
3939
if let err = err as? EncodingError {
@@ -45,7 +45,7 @@ extension APIResponse {
4545
}
4646

4747
self.statusCode = statusCode
48-
self.headers = headers.merging(["Content-Type": rawBody.defaultMIME]) { (custom, _) in custom }
48+
self.headers = headers.merging(["Content-Type": rawBody.defaultMIME]) { custom, _ in custom }
4949

5050
switch rawBody {
5151
case .data(let dataBody):
@@ -67,7 +67,7 @@ extension APIResponse {
6767
case null
6868

6969
public static func codable<T: Encodable>(_ body: T) throws -> Self {
70-
return .json(String(data: try APIGateway.defaultJSONEncoder.encode(body), encoding: .utf8) ?? "")
70+
.json(String(data: try APIGateway.defaultJSONEncoder.encode(body), encoding: .utf8) ?? "")
7171
}
7272

7373
var defaultMIME: String {
@@ -80,3 +80,4 @@ extension APIResponse {
8080
}
8181
}
8282
}
83+

Sources/TencentSCFEvents/CLS/CLSLog.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
//
1313
//===------------------------------------------------------------------------------------===//
1414

15-
import Gzip
1615
import struct Foundation.Data
1716
import struct Foundation.Date
17+
import Gzip
1818

1919
// https://intl.cloud.tencent.com/document/product/583/38845
2020

@@ -29,7 +29,7 @@ public enum CLS {
2929
public init(from decoder: Decoder) throws {
3030
let rawContainer = try decoder.singleValueContainer()
3131
let data = try rawContainer.decode(CLS.Raw.self).data.gunzipped()
32-
32+
3333
let _self = try CLS.jsonDecoder.decode(CLS._Logs.self, from: data)
3434
self.topicId = _self.topicId
3535
self.topicName = _self.topicName
@@ -49,7 +49,7 @@ public enum CLS {
4949
case timestamp
5050
case content
5151
}
52-
52+
5353
public init(from decoder: Decoder) throws {
5454
let container = try decoder.container(keyedBy: CodingKeys.self)
5555
let timestring = try container.decode(String.self, forKey: .timestamp)

Sources/TencentSCFEvents/CLS/CLSRaw.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import struct Foundation.Data
1616

1717
// https://intl.cloud.tencent.com/document/product/583/38845
1818

19-
extension CLS{
19+
extension CLS {
2020
struct _Logs: Decodable {
2121
let topicId: String
2222
let topicName: String
@@ -35,6 +35,7 @@ extension CLS{
3535
enum WrappingCodingKeys: String, CodingKey {
3636
case logs = "clslogs"
3737
}
38+
3839
enum CodingKeys: String, CodingKey {
3940
case data
4041
}

Sources/TencentSCFEvents/Utils/Base64.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ extension Base64 {
4949

5050
@inlinable
5151
static func decode<Buffer: Collection>(encoded: Buffer, options: DecodingOptions = [])
52-
throws -> [UInt8] where Buffer.Element == UInt8
53-
{
52+
throws -> [UInt8] where Buffer.Element == UInt8 {
5453
let alphabet = options.contains(.base64UrlAlphabet)
5554
? Base64.decodeBase64Url
5655
: Base64.decodeBase64

Sources/TencentSCFEvents/Utils/HTTP.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ extension HTTPResponseStatus: Codable {
170170

171171
extension String {
172172
internal var isValidHTTPToken: Bool {
173-
self.utf8.allSatisfy { (char) -> Bool in
173+
self.utf8.allSatisfy { char -> Bool in
174174
switch char {
175175
case UInt8(ascii: "a") ... UInt8(ascii: "z"),
176176
UInt8(ascii: "A") ... UInt8(ascii: "Z"),

Sources/TencentSCFEvents/Utils/String.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
//
2626
//===------------------------------------------------------------------------------------===//
2727

28-
internal extension String {
29-
func jsonEncoded() -> String {
28+
extension String {
29+
internal func jsonEncoded() -> String {
3030
var bytes = [UInt8]()
3131
let stringBytes = self.utf8
3232
var startCopyIndex = stringBytes.startIndex

0 commit comments

Comments
 (0)