Skip to content

Commit a49a873

Browse files
authored
Update swiftformat (#196)
changes: * Update swiftformat from 0.44 to 0.47 * Adjust rules
1 parent 9166653 commit a49a873

File tree

18 files changed

+91
-90
lines changed

18 files changed

+91
-90
lines changed

.swiftformat

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# file options
22

3-
--swiftversion 5.1
3+
--swiftversion 5.2
44
--exclude .build
55

66
# format options
@@ -9,5 +9,10 @@
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
1217

1318
# rules

Examples/LambdaFunctions/Sources/CurrencyExchange/main.swift

+9-8
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ struct ExchangeRatesCalculator {
104104
monthIndex: Array<Date>.Index,
105105
currencies: [String],
106106
state: [Date: ExchangeRates],
107-
callback: @escaping ((Result<[Date: ExchangeRates], Swift.Error>) -> Void)) {
107+
callback: @escaping ((Result<[Date: ExchangeRates], Swift.Error>) -> Void))
108+
{
108109
if monthIndex == months.count {
109110
return callback(.success(state))
110111
}
@@ -145,16 +146,16 @@ struct ExchangeRatesCalculator {
145146
dateFormatter.dateFormat = "dd/MMM/yy"
146147
let interval: DateInterval?
147148
if let period = try document.nodes(forXPath: "/exchangeRateMonthList/@Period").first?.stringValue,
148-
period.count == 26 {
149+
period.count == 26 {
149150
// "01/Sep/2018 to 30/Sep/2018"
150151
let startString = period[period.startIndex ..< period.index(period.startIndex, offsetBy: 11)]
151152
let to = period[startString.endIndex ..< period.index(startString.endIndex, offsetBy: 4)]
152153
let endString = period[to.endIndex ..< period.index(to.endIndex, offsetBy: 11)]
153154
if let startDate = dateFormatter.date(from: String(startString)),
154-
let startDay = calendar.dateInterval(of: .day, for: startDate),
155-
to == " to ",
156-
let endDate = dateFormatter.date(from: String(endString)),
157-
let endDay = calendar.dateInterval(of: .day, for: endDate) {
155+
let startDay = calendar.dateInterval(of: .day, for: startDate),
156+
to == " to ",
157+
let endDate = dateFormatter.date(from: String(endString)),
158+
let endDay = calendar.dateInterval(of: .day, for: endDate) {
158159
interval = DateInterval(start: startDay.start, end: endDay.end)
159160
} else {
160161
interval = nil
@@ -166,8 +167,8 @@ struct ExchangeRatesCalculator {
166167
let ratesByCurrencyCode: [String: Decimal?] = Dictionary(uniqueKeysWithValues: try currencyCodes.map {
167168
let xpathCurrency = $0.replacingOccurrences(of: "'", with: "&apos;")
168169
if let rateString = try document.nodes(forXPath: "/exchangeRateMonthList/exchangeRate/currencyCode[text()='\(xpathCurrency)']/../rateNew/text()").first?.stringValue,
169-
// We must parse the decimal data using the UK locale, not the system one.
170-
let rate = Decimal(string: rateString, locale: self.locale) {
170+
// We must parse the decimal data using the UK locale, not the system one.
171+
let rate = Decimal(string: rateString, locale: self.locale) {
171172
return ($0, rate)
172173
} else {
173174
return ($0, nil)

Sources/AWSLambdaEvents/AppSync.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public enum AppSync {
146146
}
147147
}
148148

149-
public extension AppSync {
150-
enum Response<ResultType: Encodable>: Encodable {
149+
extension AppSync {
150+
public enum Response<ResultType: Encodable>: Encodable {
151151
public func encode(to encoder: Encoder) throws {
152152
var container = encoder.singleValueContainer()
153153
switch self {
@@ -165,5 +165,5 @@ public extension AppSync {
165165
case dictionary([String: ResultType])
166166
}
167167

168-
typealias JSONStringResponse = Response<String>
168+
public typealias JSONStringResponse = Response<String>
169169
}

Sources/AWSLambdaEvents/Cloudwatch.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public protocol CloudwatchDetail: Decodable {
2121
static var name: String { get }
2222
}
2323

24-
public extension CloudwatchDetail {
25-
var detailType: String {
24+
extension CloudwatchDetail {
25+
public var detailType: String {
2626
Self.name
2727
}
2828
}

Sources/AWSLambdaEvents/DynamoDB.swift

+12-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import struct Foundation.Date
1616

1717
// https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
18-
public struct DynamoDB {
18+
public enum DynamoDB {
1919
public struct Event: Decodable {
2020
public let records: [EventRecord]
2121

@@ -311,14 +311,12 @@ extension DynamoDB {
311311
public init() {}
312312

313313
@inlinable public func decode<T: Decodable>(_ type: T.Type, from image: [String: AttributeValue])
314-
throws -> T
315-
{
314+
throws -> T {
316315
try self.decode(type, from: .map(image))
317316
}
318317

319318
@inlinable public func decode<T: Decodable>(_ type: T.Type, from value: AttributeValue)
320-
throws -> T
321-
{
319+
throws -> T {
322320
let decoder = _DecoderImpl(userInfo: userInfo, from: value, codingPath: [])
323321
return try decoder.decode(T.self)
324322
}
@@ -511,7 +509,7 @@ extension DynamoDB {
511509

512510
func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type, forKey key: K) throws
513511
-> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
514-
return try self.decoderForKey(key).container(keyedBy: type)
512+
try self.decoderForKey(key).container(keyedBy: type)
515513
}
516514

517515
func nestedUnkeyedContainer(forKey key: K) throws -> UnkeyedDecodingContainer {
@@ -557,8 +555,7 @@ extension DynamoDB {
557555
}
558556

559557
@inline(__always) private func decodeFixedWidthInteger<T: FixedWidthInteger>(key: Self.Key)
560-
throws -> T
561-
{
558+
throws -> T {
562559
let value = try getValue(forKey: key)
563560

564561
guard case .number(let number) = value else {
@@ -577,8 +574,7 @@ extension DynamoDB {
577574
}
578575

579576
@inline(__always) private func decodeLosslessStringConvertible<T: LosslessStringConvertible>(
580-
key: Self.Key) throws -> T
581-
{
577+
key: Self.Key) throws -> T {
582578
let value = try getValue(forKey: key)
583579

584580
guard case .number(let number) = value else {
@@ -677,7 +673,7 @@ extension DynamoDB {
677673
}
678674

679675
func decode<T>(_: T.Type) throws -> T where T: Decodable {
680-
return try T(from: self.impl)
676+
try T(from: self.impl)
681677
}
682678

683679
@inline(__always) private func createTypeMismatchError(type: Any.Type, value: AttributeValue) -> DecodingError {
@@ -688,8 +684,7 @@ extension DynamoDB {
688684
}
689685

690686
@inline(__always) private func decodeFixedWidthInteger<T: FixedWidthInteger>() throws
691-
-> T
692-
{
687+
-> T {
693688
guard case .number(let number) = self.value else {
694689
throw self.createTypeMismatchError(type: T.self, value: self.value)
695690
}
@@ -705,8 +700,7 @@ extension DynamoDB {
705700
}
706701

707702
@inline(__always) private func decodeLosslessStringConvertible<T: LosslessStringConvertible>()
708-
throws -> T
709-
{
703+
throws -> T {
710704
guard case .number(let number) = self.value else {
711705
throw self.createTypeMismatchError(type: T.self, value: self.value)
712706
}
@@ -850,7 +844,7 @@ extension DynamoDB {
850844

851845
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws
852846
-> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
853-
return try self.impl.container(keyedBy: type)
847+
try self.impl.container(keyedBy: type)
854848
}
855849

856850
mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer {
@@ -869,8 +863,7 @@ extension DynamoDB {
869863
}
870864

871865
@inline(__always) private mutating func decodeFixedWidthInteger<T: FixedWidthInteger>() throws
872-
-> T
873-
{
866+
-> T {
874867
defer {
875868
currentIndex += 1
876869
if currentIndex == count {
@@ -891,8 +884,7 @@ extension DynamoDB {
891884
}
892885

893886
@inline(__always) private mutating func decodeLosslessStringConvertible<T: LosslessStringConvertible>()
894-
throws -> T
895-
{
887+
throws -> T {
896888
defer {
897889
currentIndex += 1
898890
if currentIndex == count {

Sources/AWSLambdaRuntime/Lambda+Codable.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,31 @@ internal struct CodableVoidClosureWrapper<In: Decodable>: LambdaHandler {
7979
}
8080

8181
/// Implementation of a`ByteBuffer` to `In` decoding
82-
public extension EventLoopLambdaHandler where In: Decodable {
83-
func decode(buffer: ByteBuffer) throws -> In {
82+
extension EventLoopLambdaHandler where In: Decodable {
83+
public func decode(buffer: ByteBuffer) throws -> In {
8484
try self.decoder.decode(In.self, from: buffer)
8585
}
8686
}
8787

8888
/// Implementation of `Out` to `ByteBuffer` encoding
89-
public extension EventLoopLambdaHandler where Out: Encodable {
90-
func encode(allocator: ByteBufferAllocator, value: Out) throws -> ByteBuffer? {
89+
extension EventLoopLambdaHandler where Out: Encodable {
90+
public func encode(allocator: ByteBufferAllocator, value: Out) throws -> ByteBuffer? {
9191
try self.encoder.encode(value, using: allocator)
9292
}
9393
}
9494

9595
/// Default `ByteBuffer` to `In` decoder using Foundation's JSONDecoder
9696
/// Advanced users that want to inject their own codec can do it by overriding these functions.
97-
public extension EventLoopLambdaHandler where In: Decodable {
98-
var decoder: LambdaCodableDecoder {
97+
extension EventLoopLambdaHandler where In: Decodable {
98+
public var decoder: LambdaCodableDecoder {
9999
Lambda.defaultJSONDecoder
100100
}
101101
}
102102

103103
/// Default `Out` to `ByteBuffer` encoder using Foundation's JSONEncoder
104104
/// Advanced users that want to inject their own codec can do it by overriding these functions.
105-
public extension EventLoopLambdaHandler where Out: Encodable {
106-
var encoder: LambdaCodableEncoder {
105+
extension EventLoopLambdaHandler where Out: Encodable {
106+
public var encoder: LambdaCodableEncoder {
107107
Lambda.defaultJSONEncoder
108108
}
109109
}
@@ -116,9 +116,9 @@ public protocol LambdaCodableEncoder {
116116
func encode<T: Encodable>(_ value: T, using allocator: ByteBufferAllocator) throws -> ByteBuffer
117117
}
118118

119-
private extension Lambda {
120-
static let defaultJSONDecoder = JSONDecoder()
121-
static let defaultJSONEncoder = JSONEncoder()
119+
extension Lambda {
120+
fileprivate static let defaultJSONDecoder = JSONDecoder()
121+
fileprivate static let defaultJSONEncoder = JSONEncoder()
122122
}
123123

124124
extension JSONDecoder: LambdaCodableDecoder {}

Sources/AWSLambdaRuntimeCore/Lambda+String.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ internal struct StringVoidClosureWrapper: LambdaHandler {
8686
}
8787
}
8888

89-
public extension EventLoopLambdaHandler where In == String {
89+
extension EventLoopLambdaHandler where In == String {
9090
/// Implementation of a `ByteBuffer` to `String` decoding
91-
func decode(buffer: ByteBuffer) throws -> String {
91+
public func decode(buffer: ByteBuffer) throws -> String {
9292
var buffer = buffer
9393
guard let string = buffer.readString(length: buffer.readableBytes) else {
9494
fatalError("buffer.readString(length: buffer.readableBytes) failed")
@@ -97,9 +97,9 @@ public extension EventLoopLambdaHandler where In == String {
9797
}
9898
}
9999

100-
public extension EventLoopLambdaHandler where Out == String {
100+
extension EventLoopLambdaHandler where Out == String {
101101
/// Implementation of `String` to `ByteBuffer` encoding
102-
func encode(allocator: ByteBufferAllocator, value: String) throws -> ByteBuffer? {
102+
public func encode(allocator: ByteBufferAllocator, value: String) throws -> ByteBuffer? {
103103
// FIXME: reusable buffer
104104
var buffer = allocator.buffer(capacity: value.utf8.count)
105105
buffer.writeString(value)

Sources/AWSLambdaRuntimeCore/LambdaContext.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ extension Lambda {
9292
clientContext: String? = nil,
9393
logger: Logger,
9494
eventLoop: EventLoop,
95-
allocator: ByteBufferAllocator) {
95+
allocator: ByteBufferAllocator)
96+
{
9697
self.requestID = requestID
9798
self.traceID = traceID
9899
self.invokedFunctionARN = invokedFunctionARN

Sources/AWSLambdaRuntimeCore/LambdaHandler.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ public protocol LambdaHandler: EventLoopLambdaHandler {
3939
func handle(context: Lambda.Context, event: In, callback: @escaping (Result<Out, Error>) -> Void)
4040
}
4141

42-
internal extension Lambda {
43-
static let defaultOffloadQueue = DispatchQueue(label: "LambdaHandler.offload")
42+
extension Lambda {
43+
internal static let defaultOffloadQueue = DispatchQueue(label: "LambdaHandler.offload")
4444
}
4545

46-
public extension LambdaHandler {
46+
extension LambdaHandler {
4747
/// The queue on which `handle` is invoked on.
48-
var offloadQueue: DispatchQueue {
48+
public var offloadQueue: DispatchQueue {
4949
Lambda.defaultOffloadQueue
5050
}
5151

5252
/// `LambdaHandler` is offloading the processing to a `DispatchQueue`
5353
/// This is slower but safer, in case the implementation blocks the `EventLoop`
5454
/// Performance sensitive Lambdas should be based on `EventLoopLambdaHandler` which does not offload.
55-
func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out> {
55+
public func handle(context: Lambda.Context, event: In) -> EventLoopFuture<Out> {
5656
let promise = context.eventLoop.makePromise(of: Out.self)
5757
// FIXME: reusable DispatchQueue
5858
self.offloadQueue.async {
@@ -62,8 +62,8 @@ public extension LambdaHandler {
6262
}
6363
}
6464

65-
public extension LambdaHandler {
66-
func shutdown(context: Lambda.ShutdownContext) -> EventLoopFuture<Void> {
65+
extension LambdaHandler {
66+
public func shutdown(context: Lambda.ShutdownContext) -> EventLoopFuture<Void> {
6767
let promise = context.eventLoop.makePromise(of: Void.self)
6868
self.offloadQueue.async {
6969
do {
@@ -78,7 +78,7 @@ public extension LambdaHandler {
7878

7979
/// Clean up the Lambda resources synchronously.
8080
/// Concrete Lambda handlers implement this method to shutdown resources like `HTTPClient`s and database connections.
81-
func syncShutdown(context: Lambda.ShutdownContext) throws {
81+
public func syncShutdown(context: Lambda.ShutdownContext) throws {
8282
// noop
8383
}
8484
}
@@ -126,9 +126,9 @@ public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler {
126126
func decode(buffer: ByteBuffer) throws -> In
127127
}
128128

129-
public extension EventLoopLambdaHandler {
129+
extension EventLoopLambdaHandler {
130130
/// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding
131-
func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
131+
public func handle(context: Lambda.Context, event: ByteBuffer) -> EventLoopFuture<ByteBuffer?> {
132132
switch self.decodeIn(buffer: event) {
133133
case .failure(let error):
134134
return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error))
@@ -162,8 +162,8 @@ public extension EventLoopLambdaHandler {
162162
}
163163

164164
/// Implementation of `ByteBuffer` to `Void` decoding
165-
public extension EventLoopLambdaHandler where Out == Void {
166-
func encode(allocator: ByteBufferAllocator, value: Void) throws -> ByteBuffer? {
165+
extension EventLoopLambdaHandler where Out == Void {
166+
public func encode(allocator: ByteBufferAllocator, value: Void) throws -> ByteBuffer? {
167167
nil
168168
}
169169
}
@@ -194,8 +194,8 @@ public protocol ByteBufferLambdaHandler {
194194
func shutdown(context: Lambda.ShutdownContext) -> EventLoopFuture<Void>
195195
}
196196

197-
public extension ByteBufferLambdaHandler {
198-
func shutdown(context: Lambda.ShutdownContext) -> EventLoopFuture<Void> {
197+
extension ByteBufferLambdaHandler {
198+
public func shutdown(context: Lambda.ShutdownContext) -> EventLoopFuture<Void> {
199199
context.eventLoop.makeSucceededFuture(())
200200
}
201201
}

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ extension Lambda {
100100
}
101101
}
102102

103-
private extension Lambda.Context {
104-
convenience init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator, invocation: Lambda.Invocation) {
103+
extension Lambda.Context {
104+
fileprivate convenience init(logger: Logger, eventLoop: EventLoop, allocator: ByteBufferAllocator, invocation: Lambda.Invocation) {
105105
self.init(requestID: invocation.requestID,
106106
traceID: invocation.traceID,
107107
invokedFunctionARN: invocation.invokedFunctionARN,
@@ -144,8 +144,8 @@ extension EventLoopFuture {
144144
}
145145
}
146146

147-
private extension Result {
148-
var successful: Bool {
147+
extension Result {
148+
private var successful: Bool {
149149
switch self {
150150
case .success:
151151
return true

0 commit comments

Comments
 (0)