Skip to content

Commit

Permalink
chore(swift): use another formatter (#2603)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
  • Loading branch information
millotp and Fluf22 committed Jan 26, 2024
1 parent 565edb7 commit f9c5271
Show file tree
Hide file tree
Showing 43 changed files with 1,541 additions and 1,658 deletions.
32 changes: 18 additions & 14 deletions .github/actions/setup/action.yml
Expand Up @@ -190,9 +190,6 @@ runs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ steps.versions.outputs.CSHARP_VERSION }}
- run: dotnet tool install csharpier --global
if: ${{ inputs.language == 'csharp' }}
shell: bash

# Swift deps
- name: Install swift
Expand All @@ -201,21 +198,28 @@ runs:
with:
swift-version: ${{ steps.versions.outputs.SWIFT_VERSION }}

- name: Set up Homebrew
- name: Checkout swiftformat
if: ${{ inputs.language == 'swift' }}
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
uses: actions/checkout@v4
with:
repository: nicklockwood/SwiftFormat
ref: 0.53.0
path: swiftformat

- name: Cache Homebrew Bundler RubyGems
- name: Cache the build folder
id: cache-swiftformat
if: ${{ inputs.language == 'swift' }}
id: cache
uses: actions/cache@v4
with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
restore-keys: ${{ runner.os }}-rubygems-
path: swiftformat/.build
key: swiftformat-build-0.53.0-${{ env.CACHE_VERSION }}

- name: Install swift-format
if: ${{ inputs.language == 'swift' && steps.cache.outputs.cache-hit != 'true' }}
- name: Build swiftformat
if: ${{ inputs.language == 'swift' && steps.cache-swiftformat.outputs.cache-hit != 'true' }}
shell: bash
run: cd swiftformat && swift build -c release

- name: Setup the path
if: ${{ inputs.language == 'swift' }}
shell: bash
run: brew install swift-format
run: echo "$(pwd)/swiftformat/.build/release" >> $GITHUB_PATH
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -46,3 +46,5 @@ pubspec.lock
**/csharp/src/bin
**/csharp/src/obj
*.DotSettings.user

swiftformat
Expand Up @@ -10,27 +10,27 @@ import Foundation
/// Indicate whether the HTTP call performed is of type [read] (GET) or [write] (POST, PUT ..).
/// Used to determine which timeout duration to use.
public enum CallType {
case read, write
case read, write
}

extension CallType: CustomStringConvertible {
public var description: String {
switch self {
case .read:
return "read"
case .write:
return "write"
public var description: String {
switch self {
case .read:
return "read"
case .write:
return "write"
}
}
}
}

extension HTTPMethod {
public func toCallType() -> CallType {
switch self {
case .get:
.read
default:
.write
public extension HTTPMethod {
func toCallType() -> CallType {
switch self {
case .get:
.read
default:
.write
}
}
}
}
Expand Up @@ -8,15 +8,13 @@
import Foundation

public protocol Credentials {
/// ApplicationID to target. Is passed as a HTTP header.
var applicationID: String { get }

/// ApplicationID to target. Is passed as a HTTP header.
var applicationID: String { get }

/**
* APIKey for a given ApplicationID. Is passed as a HTTP header.
* To maintain security, never use your Admin APIKey on your front end or share it with anyone.
* In your front end, use the Search-only APIKey or any other key that has search-only rights.
*/
var apiKey: String { get }

/**
* APIKey for a given ApplicationID. Is passed as a HTTP header.
* To maintain security, never use your Admin APIKey on your front end or share it with anyone.
* In your front end, use the Search-only APIKey or any other key that has search-only rights.
*/
var apiKey: String { get }
}
Expand Up @@ -8,63 +8,58 @@
import Foundation

struct DecodingErrorPrettyPrinter: CustomStringConvertible, CustomDebugStringConvertible {
let decodingError: DecodingError

let decodingError: DecodingError

init(decodingError: DecodingError) {
self.decodingError = decodingError
}
init(decodingError: DecodingError) {
self.decodingError = decodingError
}

private let prefix = "Decoding error"
private let prefix = "Decoding error"

private func codingKeyDescription(_ key: CodingKey) -> String {
if let index = key.intValue {
return "[\(index)]"
} else {
return "'\(key.stringValue)'"
private func codingKeyDescription(_ key: CodingKey) -> String {
if let index = key.intValue {
return "[\(index)]"
} else {
return "'\(key.stringValue)'"
}
}
}

private func codingPathDescription(_ path: [CodingKey]) -> String {
return path.map(codingKeyDescription).joined(separator: " -> ")
}
private func codingPathDescription(_ path: [CodingKey]) -> String {
path.map(codingKeyDescription).joined(separator: " -> ")
}

private func additionalComponents(for error: DecodingError) -> [String] {
switch decodingError {
case .valueNotFound(_, let context):
return [codingPathDescription(context.codingPath), context.debugDescription]
private func additionalComponents(for _: DecodingError) -> [String] {
switch decodingError {
case let .valueNotFound(_, context):
return [codingPathDescription(context.codingPath), context.debugDescription]

case .keyNotFound(let key, let context):
return [
codingPathDescription(context.codingPath), "Key not found: \(codingKeyDescription(key))",
]
case let .keyNotFound(key, context):
return [
codingPathDescription(context.codingPath), "Key not found: \(codingKeyDescription(key))",
]

case .typeMismatch(let type, let context):
return [codingPathDescription(context.codingPath), "Type mismatch. Expected: \(type)"]
case let .typeMismatch(type, context):
return [codingPathDescription(context.codingPath), "Type mismatch. Expected: \(type)"]

case .dataCorrupted(let context):
return [codingPathDescription(context.codingPath), context.debugDescription]
case let .dataCorrupted(context):
return [codingPathDescription(context.codingPath), context.debugDescription]

@unknown default:
return [decodingError.localizedDescription]
@unknown default:
return [decodingError.localizedDescription]
}
}

}

var description: String {
return ([prefix] + additionalComponents(for: decodingError)).joined(separator: ": ")
}

var debugDescription: String {
return description
}
var description: String {
([prefix] + additionalComponents(for: decodingError)).joined(separator: ": ")
}

var debugDescription: String {
description
}
}

extension DecodingError {

public var prettyDescription: String {
return DecodingErrorPrettyPrinter(decodingError: self).description
}

public extension DecodingError {
var prettyDescription: String {
DecodingErrorPrettyPrinter(decodingError: self).description
}
}
@@ -1,5 +1,5 @@
//
// AlgoliaError.swift
// ErrorMessage.swift
//
//
// Created by Algolia on 22/12/2023.
Expand All @@ -8,19 +8,17 @@
import Foundation

public struct GenericError: Error, CustomStringConvertible {
public var description: String
public var description: String

public init(description: String) {
self.description = description
}
public init(description: String) {
self.description = description
}
}

public struct ErrorMessage: Codable, CustomStringConvertible {
enum CodingKeys: String, CodingKey {
case description = "message"
}

enum CodingKeys: String, CodingKey {
case description = "message"
}

public let description: String

public let description: String
}

0 comments on commit f9c5271

Please sign in to comment.