Skip to content

Commit 281ad87

Browse files
authored
Update swiftformat (#196)
changes: * Update swiftformat from 0.44 to 0.47 * Adjust rules
1 parent 8cc571f commit 281ad87

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
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

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 {

Tests/AWSLambdaEventsTests/Utils/DateWrapperTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DateWrapperTests: XCTestCase {
4242
XCTFail("Unexpected error: \(error)"); return
4343
}
4444

45-
XCTAssertEqual(context.codingPath.compactMap { $0.stringValue }, ["date"])
45+
XCTAssertEqual(context.codingPath.map(\.stringValue), ["date"])
4646
XCTAssertEqual(context.debugDescription, "Expected date to be in ISO8601 date format, but `\(date)` is not in the correct format")
4747
XCTAssertNil(context.underlyingError)
4848
}
@@ -74,7 +74,7 @@ class DateWrapperTests: XCTestCase {
7474
XCTFail("Unexpected error: \(error)"); return
7575
}
7676

77-
XCTAssertEqual(context.codingPath.compactMap { $0.stringValue }, ["date"])
77+
XCTAssertEqual(context.codingPath.map(\.stringValue), ["date"])
7878
XCTAssertEqual(context.debugDescription, "Expected date to be in ISO8601 date format with fractional seconds, but `\(date)` is not in the correct format")
7979
XCTAssertNil(context.underlyingError)
8080
}
@@ -132,7 +132,7 @@ class DateWrapperTests: XCTestCase {
132132
XCTFail("Unexpected error: \(error)"); return
133133
}
134134

135-
XCTAssertEqual(context.codingPath.compactMap { $0.stringValue }, ["date"])
135+
XCTAssertEqual(context.codingPath.map(\.stringValue), ["date"])
136136
XCTAssertEqual(context.debugDescription, "Expected date to be in RFC5322 date-time format with fractional seconds, but `\(date)` is not in the correct format")
137137
XCTAssertNil(context.underlyingError)
138138
}

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
1515

1616
# swiftformat (until part of the toolchain)
1717

18-
ARG swiftformat_version=0.44.6
18+
ARG swiftformat_version=0.47.3
1919
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format
2020
RUN cd $HOME/.tools/swift-format && swift build -c release
2121
RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat

0 commit comments

Comments
 (0)