Skip to content

Commit 2cb43b3

Browse files
committed
Update swiftformat
- Update swiftformat from 0.44 to 0.47 - Add format option `--extensionacl on-declarations` to ensure ACL is never set on extensions - Add format option `--disable typeSugar` to ensure `&&` is not replaced with `,`
1 parent 9166653 commit 2cb43b3

File tree

19 files changed

+95
-80
lines changed

19 files changed

+95
-80
lines changed

.swiftformat

+3-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,7 @@
99
--patternlet inline
1010
--stripunusedargs unnamed-only
1111
--ifdef no-indent
12+
--extensionacl on-declarations
13+
--disable typeSugar
1214

1315
# rules

Examples/LambdaFunctions/Sources/CurrencyExchange/main.swift

+12-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,18 @@ 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
150+
{
149151
// "01/Sep/2018 to 30/Sep/2018"
150152
let startString = period[period.startIndex ..< period.index(period.startIndex, offsetBy: 11)]
151153
let to = period[startString.endIndex ..< period.index(startString.endIndex, offsetBy: 4)]
152154
let endString = period[to.endIndex ..< period.index(to.endIndex, offsetBy: 11)]
153155
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) {
156+
let startDay = calendar.dateInterval(of: .day, for: startDate),
157+
to == " to ",
158+
let endDate = dateFormatter.date(from: String(endString)),
159+
let endDay = calendar.dateInterval(of: .day, for: endDate)
160+
{
158161
interval = DateInterval(start: startDay.start, end: endDay.end)
159162
} else {
160163
interval = nil
@@ -166,8 +169,9 @@ struct ExchangeRatesCalculator {
166169
let ratesByCurrencyCode: [String: Decimal?] = Dictionary(uniqueKeysWithValues: try currencyCodes.map {
167170
let xpathCurrency = $0.replacingOccurrences(of: "'", with: "&apos;")
168171
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) {
172+
// We must parse the decimal data using the UK locale, not the system one.
173+
let rate = Decimal(string: rateString, locale: self.locale)
174+
{
171175
return ($0, rate)
172176
} else {
173177
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

+10-7
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

@@ -341,7 +341,8 @@ extension DynamoDB {
341341
}
342342

343343
@usableFromInline func container<Key>(keyedBy type: Key.Type) throws ->
344-
KeyedDecodingContainer<Key> where Key: CodingKey {
344+
KeyedDecodingContainer<Key> where Key: CodingKey
345+
{
345346
guard case .map(let dictionary) = self.value else {
346347
throw DecodingError.typeMismatch([String: AttributeValue].self, DecodingError.Context(
347348
codingPath: self.codingPath,
@@ -510,8 +511,9 @@ extension DynamoDB {
510511
}
511512

512513
func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type, forKey key: K) throws
513-
-> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
514-
return try self.decoderForKey(key).container(keyedBy: type)
514+
-> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey
515+
{
516+
try self.decoderForKey(key).container(keyedBy: type)
515517
}
516518

517519
func nestedUnkeyedContainer(forKey key: K) throws -> UnkeyedDecodingContainer {
@@ -677,7 +679,7 @@ extension DynamoDB {
677679
}
678680

679681
func decode<T>(_: T.Type) throws -> T where T: Decodable {
680-
return try T(from: self.impl)
682+
try T(from: self.impl)
681683
}
682684

683685
@inline(__always) private func createTypeMismatchError(type: Any.Type, value: AttributeValue) -> DecodingError {
@@ -849,8 +851,9 @@ extension DynamoDB {
849851
}
850852

851853
mutating func nestedContainer<NestedKey>(keyedBy type: NestedKey.Type) throws
852-
-> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
853-
return try self.impl.container(keyedBy: type)
854+
-> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey
855+
{
856+
try self.impl.container(keyedBy: type)
854857
}
855858

856859
mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer {

Sources/AWSLambdaEvents/Utils/Base64.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extension Base64 {
3737

3838
@inlinable
3939
static func decode<Buffer: Collection>(encoded: Buffer, options: DecodingOptions = [])
40-
throws -> [UInt8] where Buffer.Element == UInt8 {
40+
throws -> [UInt8] where Buffer.Element == UInt8
41+
{
4142
let alphabet = options.contains(.base64UrlAlphabet)
4243
? Base64.decodeBase64Url
4344
: Base64.decodeBase64

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+
fileprivate var successful: Bool {
149149
switch self {
150150
case .success:
151151
return true

Sources/AWSLambdaRuntimeCore/LambdaRuntimeClient.swift

+8-7
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ extension Lambda {
126126
}
127127
}
128128

129-
internal extension Lambda {
130-
enum RuntimeError: Error {
129+
extension Lambda {
130+
internal enum RuntimeError: Error {
131131
case badStatusCode(HTTPResponseStatus)
132132
case upstreamError(String)
133133
case invocationMissingHeader(String)
@@ -142,13 +142,13 @@ internal struct ErrorResponse: Codable {
142142
var errorMessage: String
143143
}
144144

145-
internal extension ErrorResponse {
146-
func toJSONBytes() -> [UInt8] {
145+
extension ErrorResponse {
146+
internal func toJSONBytes() -> [UInt8] {
147147
var bytes = [UInt8]()
148148
bytes.append(UInt8(ascii: "{"))
149-
bytes.append(contentsOf: #""errorType":"# .utf8)
149+
bytes.append(contentsOf: #""errorType":"#.utf8)
150150
self.errorType.encodeAsJSONString(into: &bytes)
151-
bytes.append(contentsOf: #","errorMessage":"# .utf8)
151+
bytes.append(contentsOf: #","errorMessage":"#.utf8)
152152
self.errorMessage.encodeAsJSONString(into: &bytes)
153153
bytes.append(UInt8(ascii: "}"))
154154
return bytes
@@ -170,7 +170,8 @@ extension Lambda {
170170
}
171171

172172
guard let deadline = headers.first(name: AmazonHeaders.deadline),
173-
let unixTimeInMilliseconds = Int64(deadline) else {
173+
let unixTimeInMilliseconds = Int64(deadline)
174+
else {
174175
throw RuntimeError.invocationMissingHeader(AmazonHeaders.deadline)
175176
}
176177

Sources/AWSLambdaRuntimeCore/Utils.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ internal enum Signal: Int32 {
5858
case TERM = 15
5959
}
6060

61-
internal extension DispatchWallTime {
62-
init(millisSinceEpoch: Int64) {
61+
extension DispatchWallTime {
62+
internal init(millisSinceEpoch: Int64) {
6363
let nanoSinceEpoch = UInt64(millisSinceEpoch) * 1_000_000
6464
let seconds = UInt64(nanoSinceEpoch / 1_000_000_000)
6565
let nanoseconds = nanoSinceEpoch - (seconds * 1_000_000_000)
6666
self.init(timespec: timespec(tv_sec: Int(seconds), tv_nsec: Int(nanoseconds)))
6767
}
6868

69-
var millisSinceEpoch: Int64 {
69+
internal var millisSinceEpoch: Int64 {
7070
Int64(bitPattern: self.rawValue) / -1_000_000
7171
}
7272
}

0 commit comments

Comments
 (0)