Skip to content

Commit

Permalink
Update swift format to 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Apr 11, 2024
1 parent f2e2b98 commit ccbdbc8
Show file tree
Hide file tree
Showing 27 changed files with 101 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
--minversion 0.51.0

# Swift version
--swiftversion 5.5
--swiftversion 5.8

# file options
--exclude .build

# rules
--disable redundantReturn, extensionAccessControl
--disable redundantReturn, extensionAccessControl, typeSugar

# format options
--ifdef no-indent
Expand Down
6 changes: 3 additions & 3 deletions Benchmark/Sources/soto-benchmark/EncoderSuites.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ protocol EncoderProtocol {

extension XMLEncoder: EncoderProtocol {
typealias Output = XML.Element
func encode<Input: Encodable>(_ value: Input) throws -> Output {
func encode(_ value: some Encodable) throws -> Output {
try self.encode(value, name: "BenchmarkTest")
}
}

extension QueryEncoder: EncoderProtocol {
typealias Output = String?
func encode<Input: Encodable>(_ value: Input) throws -> Output {
func encode(_ value: some Encodable) throws -> Output {
try self.encode(value, name: "BenchmarkTest")
}
}
Expand All @@ -62,7 +62,7 @@ struct Dictionaries: Codable {
}

/// Generic suite of benchmark tests for an Encoder.
func encoderSuite<E: EncoderProtocol>(for encoder: E, suite: BenchmarkSuite) {
func encoderSuite(for encoder: some EncoderProtocol, suite: BenchmarkSuite) {
let numbers = Numbers(b: true, i: 3478, f: 34.4633, d: 9585)
suite.benchmark("numbers") {
_ = try encoder.encode(numbers)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/AWSClient+Paginate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension AWSClient {
}

public mutating func next() async throws -> Output? {
if let input = input {
if let input {
let output = try await self.sequence.command(input, self.sequence.logger)
if let token = output[keyPath: sequence.outputKey],
sequence.inputKey == nil || token != input[keyPath: sequence.inputKey!],
Expand Down
12 changes: 6 additions & 6 deletions Sources/SotoCore/AWSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public final class AWSClient: Sendable {
/// - options: Configuration flags
/// - httpClient: HTTPClient to use.
/// - logger: Logger used to log background AWSClient events
public init<Middleware: AWSMiddlewareProtocol>(
public init(
credentialProvider credentialProviderFactory: CredentialProviderFactory = .default,
retryPolicy retryPolicyFactory: RetryPolicyFactory = .default,
middleware: Middleware,
middleware: some AWSMiddlewareProtocol,
options: Options = Options(),
httpClient: AWSHTTPClient = HTTPClient.shared,
logger clientLogger: Logger = AWSClient.loggingDisabled
Expand Down Expand Up @@ -227,12 +227,12 @@ extension AWSClient {
/// - input: Input object
/// - hostPrefix: String to prefix host name with
/// - logger: Logger to log request details to
public func execute<Input: AWSEncodableShape>(
public func execute(
operation operationName: String,
path: String,
httpMethod: HTTPMethod,
serviceConfig: AWSServiceConfig,
input: Input,
input: some AWSEncodableShape,
hostPrefix: String? = nil,
logger: Logger = AWSClient.loggingDisabled
) async throws {
Expand Down Expand Up @@ -337,12 +337,12 @@ extension AWSClient {
/// - logger: Logger to log request details to
/// - returns:
/// Output object that completes when response is received
public func execute<Output: AWSDecodableShape, Input: AWSEncodableShape>(
public func execute<Output: AWSDecodableShape>(
operation operationName: String,
path: String,
httpMethod: HTTPMethod,
serviceConfig: AWSServiceConfig,
input: Input,
input: some AWSEncodableShape,
hostPrefix: String? = nil,
logger: Logger = AWSClient.loggingDisabled
) async throws -> Output {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SotoCore/AWSServiceConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public final class AWSServiceConfig {
options: Options = []
) {
var partition = partition
if let region = region {
if let region {
self.region = region
partition = region.partition
} else if let partitionEndpoint = partitionEndpoints[partition] {
Expand Down Expand Up @@ -142,7 +142,7 @@ public final class AWSServiceConfig {
variantEndpoints: [EndpointVariantType: EndpointVariant]
) -> String {
// work out endpoint, if provided use that otherwise
if let endpoint = endpoint {
if let endpoint {
return endpoint
} else {
let serviceHost: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/AWSShapes/Base64Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct AWSBase64Data: Sendable, Codable, Equatable {
}

/// construct `AWSBase64Data` from raw data
public static func data<C: Collection>(_ data: C) -> Self where C.Element == UInt8 {
public static func data(_ data: some Collection<UInt8>) -> Self {
return .init(base64String: String(base64Encoding: data))
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/Credential/STSAssumeRole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ struct STSAssumeRoleCredentialProvider: CredentialProviderWithClient {
let request = STSAssumeRoleWithWebIdentityRequest(roleArn: arn, roleSessionName: sessioName, webIdentityToken: token)
credentials = try await self.assumeRoleWithWebIdentity(request, logger: logger).credentials
}
guard let credentials = credentials else {
guard let credentials else {
throw CredentialProviderError.noProvider
}
return credentials
Expand Down
30 changes: 15 additions & 15 deletions Sources/SotoCore/Doc/AWSShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public extension AWSEncodableShape {
guard value <= max else { throw Self.validationError("\(parent).\(name) (\(value)) is greater than the maximum allowed value \(max).") }
}

func validate<T: Collection>(_ value: T, name: String, parent: String, min: Int) throws {
func validate(_ value: some Collection, name: String, parent: String, min: Int) throws {
guard value.count >= min else { throw Self.validationError("Length of \(parent).\(name) (\(value.count)) is less than minimum allowed value \(min).") }
}

func validate<T: Collection>(_ value: T, name: String, parent: String, max: Int) throws {
func validate(_ value: some Collection, name: String, parent: String, max: Int) throws {
guard value.count <= max else { throw Self.validationError("Length of \(parent).\(name) (\(value.count)) is greater than the maximum allowed value \(max).") }
}

Expand Down Expand Up @@ -125,57 +125,57 @@ public extension AWSEncodableShape {

// validate optional values
func validate<T: BinaryInteger>(_ value: T?, name: String, parent: String, min: T) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, min: min)
}

func validate<T: BinaryInteger>(_ value: T?, name: String, parent: String, max: T) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, max: max)
}

func validate<T: FloatingPoint>(_ value: T?, name: String, parent: String, min: T) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, min: min)
}

func validate<T: FloatingPoint>(_ value: T?, name: String, parent: String, max: T) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, max: max)
}

func validate<T: Collection>(_ value: T?, name: String, parent: String, min: Int) throws {
guard let value = value else { return }
func validate(_ value: (some Collection)?, name: String, parent: String, min: Int) throws {
guard let value else { return }
try self.validate(value, name: name, parent: parent, min: min)
}

func validate<T: Collection>(_ value: T?, name: String, parent: String, max: Int) throws {
guard let value = value else { return }
func validate(_ value: (some Collection)?, name: String, parent: String, max: Int) throws {
guard let value else { return }
try self.validate(value, name: name, parent: parent, max: max)
}

func validate(_ value: AWSBase64Data?, name: String, parent: String, min: Int) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, min: min)
}

func validate(_ value: AWSBase64Data?, name: String, parent: String, max: Int) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, max: max)
}

func validate(_ value: AWSHTTPBody?, name: String, parent: String, min: Int) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, min: min)
}

func validate(_ value: AWSHTTPBody?, name: String, parent: String, max: Int) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, max: max)
}

func validate(_ value: String?, name: String, parent: String, pattern: String) throws {
guard let value = value else { return }
guard let value else { return }
try self.validate(value, name: name, parent: parent, pattern: pattern)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension KeyedDecodingContainer {
/// extending `KeyedEncodingContainer` so it will only encode a wrapped value it is non nil
extension KeyedEncodingContainer {
// Used to make make sure OptionalCodingWrappers encode no value when it's wrappedValue is nil.
public mutating func encode<T>(_ value: T, forKey key: KeyedEncodingContainer<K>.Key) throws where T: Encodable, T: OptionalCustomCodingWrapper {
public mutating func encode(_ value: some Encodable & OptionalCustomCodingWrapper, forKey key: KeyedEncodingContainer<K>.Key) throws {
guard value.wrappedValue != nil else { return }
try encodeIfPresent(value, forKey: key)
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/SotoCore/Encoder/QueryEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct QueryEncoder {

public init() {}

public func encode<T: Encodable>(_ value: T) throws -> String? {
public func encode(_ value: some Encodable) throws -> String? {
let encoder = _QueryEncoder(options: options)
try value.encode(to: encoder)

Expand Down Expand Up @@ -94,7 +94,7 @@ public struct QueryEncoder {
}
}
}
if let container = container {
if let container {
flatten(dictionary: container.values, path: "")
}
return result
Expand Down Expand Up @@ -222,7 +222,7 @@ private class _QueryEncoder: Encoder {
mutating func encode(_ value: UInt32, forKey key: Key) throws { self.encode(value, key: key.stringValue) }
mutating func encode(_ value: UInt64, forKey key: Key) throws { self.encode(value, key: key.stringValue) }

mutating func encode<T: Encodable>(_ value: T, forKey key: Key) throws {
mutating func encode(_ value: some Encodable, forKey key: Key) throws {
self.encoder.codingPath.append(key)
defer { self.encoder.codingPath.removeLast() }

Expand Down Expand Up @@ -305,7 +305,7 @@ private class _QueryEncoder: Encoder {
mutating func encode(_ value: UInt32) throws { self.encodeResult(value) }
mutating func encode(_ value: UInt64) throws { self.encodeResult(value) }

mutating func encode<T: Encodable>(_ value: T) throws {
mutating func encode(_ value: some Encodable) throws {
self.count += 1

self.encoder.codingPath.append(_QueryKey(index: self.count))
Expand Down Expand Up @@ -367,7 +367,7 @@ extension _QueryEncoder: SingleValueEncodingContainer {
func encode(_ value: UInt32) throws { self.encodeResult(value) }
func encode(_ value: UInt64) throws { self.encodeResult(value) }

func encode<T: Encodable>(_ value: T) throws {
func encode(_ value: some Encodable) throws {
try value.encode(to: self)
}

Expand Down
34 changes: 17 additions & 17 deletions Sources/SotoCore/Encoder/RequestContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public class RequestEncodingContainer {

/// Write value to header
@inlinable
public func encodeHeader<Value>(_ value: Value, key: String) {
public func encodeHeader(_ value: some Any, key: String) {
self.headers.replaceOrAdd(name: key, value: "\(value)")
}

/// Write optional value to header
@inlinable
public func encodeHeader<Value>(_ value: Value?, key: String) {
if let value = value {
public func encodeHeader(_ value: (some Any)?, key: String) {
if let value {
self.encodeHeader(value, key: key)
}
}
Expand Down Expand Up @@ -120,16 +120,16 @@ public class RequestEncodingContainer {

/// Write dictionary key value pairs to headers with prefix added to the keys
@inlinable
public func encodeHeader<Value>(_ value: [String: Value], key prefix: String) {
public func encodeHeader(_ value: [String: some Any], key prefix: String) {
for element in value {
self.headers.replaceOrAdd(name: "\(prefix)\(element.key)", value: "\(element.value)")
}
}

/// Write optional dictionary key value pairs to headers with prefix added to the keys
@inlinable
public func encodeHeader<Value>(_ value: [String: Value]?, key prefix: String) {
if let value = value {
public func encodeHeader(_ value: [String: some Any]?, key prefix: String) {
if let value {
self.encodeHeader(value, key: prefix)
}
}
Expand All @@ -138,14 +138,14 @@ public class RequestEncodingContainer {

/// Write value to query
@inlinable
public func encodeQuery<Value>(_ value: Value, key: String) {
public func encodeQuery(_ value: some Any, key: String) {
self.queryParams.append((key: key, value: "\(value)"))
}

/// Write optional value to query
@inlinable
public func encodeQuery<Value>(_ value: Value?, key: String) {
if let value = value {
public func encodeQuery(_ value: (some Any)?, key: String) {
if let value {
self.queryParams.append((key: key, value: "\(value)"))
}
}
Expand All @@ -168,47 +168,47 @@ public class RequestEncodingContainer {

/// Write array as a series of query values
@inlinable
public func encodeQuery<Value>(_ value: [Value], key: String) {
public func encodeQuery(_ value: [some Any], key: String) {
for element in value {
self.queryParams.append((key: key, value: "\(element)"))
}
}

/// Write dictionary key value pairs as query key value pairs
@inlinable
public func encodeQuery<Value>(_ value: [String: Value]) {
public func encodeQuery(_ value: [String: some Any]) {
for element in value {
self.queryParams.append((key: element.key, value: "\(element.value)"))
}
}

/// Write optional array as a series of query values
@inlinable
public func encodeQuery<Value>(_ value: [Value]?, key: String) {
if let value = value {
public func encodeQuery(_ value: [some Any]?, key: String) {
if let value {
self.encodeQuery(value, key: key)
}
}

/// Write optional dictionary key value pairs as query key value pairs
@inlinable
public func encodeQuery<Value>(_ value: [String: Value]?) {
if let value = value {
public func encodeQuery(_ value: [String: some Any]?) {
if let value {
self.encodeQuery(value)
}
}

/// Write value into URI path
@inlinable
public func encodePath<Value>(_ value: Value, key: String) {
public func encodePath(_ value: some Any, key: String) {
self.path = self.path
.replacingOccurrences(of: "{\(key)}", with: Self.urlEncodePathComponent(String(describing: value)))
.replacingOccurrences(of: "{\(key)+}", with: Self.urlEncodePath(String(describing: value)))
}

/// Write value into hostname
@inlinable
public func encodeHostPrefix<Value>(_ value: Value, key: String) {
public func encodeHostPrefix(_ value: some Any, key: String) {
self.hostPrefix = self.hostPrefix?
.replacingOccurrences(of: "{\(key)}", with: Self.urlEncodePathComponent(String(describing: value)))
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/HTTP/AWSHTTPBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct AWSHTTPBody: Sendable {
self.storage = .byteBuffer(buffer)
}

public init<C: Collection>(bytes: C, byteBufferAllocator: ByteBufferAllocator = .init()) where C.Element == UInt8 {
public init(bytes: some Collection<UInt8>, byteBufferAllocator: ByteBufferAllocator = .init()) {
var byteBuffer = byteBufferAllocator.buffer(capacity: bytes.count)
byteBuffer.writeBytes(bytes)
self.storage = .byteBuffer(byteBuffer)
Expand Down
Loading

0 comments on commit ccbdbc8

Please sign in to comment.