Skip to content

Commit 7df5fee

Browse files
authored
Merge pull request #384 from argentlabs/fix/swift-format
[TIDY] Swiftformat
2 parents 4f666ea + 6a32627 commit 7df5fee

File tree

92 files changed

+406
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+406
-379
lines changed

scripts/config.swiftformat

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
--acronyms ID,URL,UUID
2+
--allman false
3+
--anonymous-for-each convert
4+
--asset-literals visual-width
5+
--async-capturing
6+
--before-marks
7+
--binary-grouping 4,8
8+
--call-site-paren default
9+
--category-mark "MARK: %c"
10+
--class-threshold 0
11+
--closing-paren balanced
12+
--closure-void remove
13+
--complex-attributes preserve
14+
--computed-var-attributes preserve
15+
--conditional-assignment after-property
16+
--conflict-markers reject
17+
--date-format system
18+
--decimal-grouping 3,6
19+
--doc-comments before-declarations
20+
--else-position same-line
21+
--empty-braces no-space
22+
--enum-namespaces always
23+
--enum-threshold 0
24+
--equatable-macro none
25+
--exponent-case lowercase
26+
--exponent-grouping disabled
27+
--extension-acl on-extension
28+
--extension-mark "MARK: - %t + %c"
29+
--extension-threshold 0
30+
--file-macro "#file"
31+
--fraction-grouping disabled
32+
--fragment false
33+
--func-attributes prev-line
34+
--generic-types
35+
--group-blank-lines true
36+
--grouped-extension "MARK: %c"
37+
--guard-else same-line
38+
--header "//\n// web3.swift\n// Copyright © Argent Labs Limited. All rights reserved.\n//"
39+
--hex-grouping 4,8
40+
--hex-literal-case uppercase
41+
--ifdef indent
42+
--import-grouping length
43+
--indent 4
44+
--indent-case false
45+
--indent-strings false
46+
--inferred-types always
47+
--init-coder-nil false
48+
--language-mode 0
49+
--lifecycle
50+
--line-after-marks false
51+
--line-between-guards false
52+
--linebreaks lf
53+
--mark-categories true
54+
--mark-extensions always
55+
--mark-types always
56+
--max-width none
57+
--modifier-order
58+
--never-trailing
59+
--nil-init remove
60+
--no-space-operators
61+
--no-wrap-operators
62+
--non-complex-attributes
63+
--octal-grouping 4,8
64+
--operator-func spaced
65+
--organization-mode visibility
66+
--organize-types actor,class,enum,struct
67+
--pattern-let hoist
68+
--preserve-acronyms
69+
--preserve-decls
70+
--preserved-property-types Package
71+
--property-types infer-locals-only
72+
--ranges spaced
73+
--self remove
74+
--self-required
75+
--semicolons inline
76+
--short-optionals always
77+
--single-line-for-each ignore
78+
--smart-tabs enabled
79+
--some-any true
80+
--sort-swiftui-properties none
81+
--sorted-patterns
82+
--stored-var-attributes preserve
83+
--strip-unused-args always
84+
--struct-threshold 0
85+
--swift-version 5.9
86+
--tab-width unspecified
87+
--throw-capturing
88+
--timezone system
89+
--trailing-closures
90+
--trailing-commas always
91+
--trim-whitespace always
92+
--type-attributes prev-line
93+
--type-blank-lines remove
94+
--type-delimiter space-after
95+
--type-mark "MARK: - %t"
96+
--type-marks
97+
--type-order
98+
--url-macro none
99+
--visibility-marks
100+
--visibility-order
101+
--void-type void
102+
--wrap-arguments before-first
103+
--wrap-collections before-first
104+
--wrap-conditions preserve
105+
--wrap-effects preserve
106+
--wrap-enum-cases always
107+
--wrap-parameters before-first
108+
--wrap-return-type preserve
109+
--wrap-string-interpolation default
110+
--wrap-ternary default
111+
--wrap-type-aliases preserve
112+
--xcode-indentation disabled
113+
--xctest-symbols
114+
--yoda-swap always
115+
--disable consecutiveSpaces,enumNamespaces,extensionAccessControl,genericExtensions,headerFileName,modifierOrder,numberFormatting,opaqueGenericParameters,preferKeyPath,redundantBackticks,redundantExtensionACL,redundantFileprivate,redundantPattern,redundantRawValues,redundantSelf,sortDeclarations,spaceAroundGenerics,strongOutlets,trailingClosures,trailingCommas,unusedArguments,wrap,wrapMultilineStatementBraces,wrapSingleLineComments,yodaConditions
116+
--enable blankLinesBetweenImports,isEmpty,wrapConditionalBodies

scripts/runSwiftFormat.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
SWIFT_VERSION=5.3
3+
SWIFT_VERSION=5.9
44

55
cd "$(dirname "$0")"
66

@@ -17,8 +17,8 @@ if ! which bin/swiftformat >/dev/null; then
1717
cd bin
1818
rm -r ./*
1919

20-
downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.50.3/swiftformat.artifactbundle.zip"
21-
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.50.3-macos/bin/swiftformat .
20+
downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.57.2/swiftformat.artifactbundle.zip"
21+
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.57.2-macos/bin/swiftformat .
2222
find . -name "*Tmp" -type d -prune -exec rm -rf '{}' +
2323
for entry in ./*
2424
do
@@ -38,12 +38,12 @@ cleanup() {
3838
}
3939

4040
format() {
41-
bin/swiftformat ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION
41+
bin/swiftformat ../web3swift/src/ --config "config.swiftformat" --swiftversion $SWIFT_VERSION
4242
cleanup
4343
}
4444

4545
lint() {
46-
bin/swiftformat --lint ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION
46+
bin/swiftformat --lint ../web3swift/src/ --config "config.swiftformat" --swiftversion $SWIFT_VERSION
4747
cleanup
4848
}
4949

scripts/swiftformat.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

web3swift/src/Account/EthereumAccount+SignTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import Foundation

web3swift/src/Account/EthereumAccount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import Logging

web3swift/src/Account/EthereumKeyStorage+Password.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import Foundation

web3swift/src/Account/EthereumKeyStorage.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import Foundation
@@ -32,7 +32,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
3232
private let localFileName = "ethereumkey"
3333

3434
private var addressPath: String? {
35-
guard let address = address else {
35+
guard let address else {
3636
return nil
3737
}
3838
if let url = folderPath {
@@ -58,7 +58,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
5858
private let fileManager = FileManager.default
5959

6060
public func storePrivateKey(key: Data) throws {
61-
guard let localPath = localPath else {
61+
guard let localPath else {
6262
throw EthereumKeyStorageError.failedToSave
6363
}
6464

@@ -70,7 +70,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
7070
}
7171

7272
public func loadPrivateKey() throws -> Data {
73-
guard let localPath = localPath else {
73+
guard let localPath else {
7474
throw EthereumKeyStorageError.failedToLoad
7575
}
7676

@@ -84,7 +84,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
8484

8585
extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol {
8686
public func fetchAccounts() throws -> [EthereumAddress] {
87-
guard let folderPath = folderPath else {
87+
guard let folderPath else {
8888
throw EthereumKeyStorageError.failedToLoad
8989
}
9090

@@ -139,7 +139,7 @@ extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol {
139139

140140
public func deleteAllKeys() throws {
141141
do {
142-
if let folderPath = folderPath {
142+
if let folderPath {
143143
let directoryContents = try fileManager.contentsOfDirectory(atPath: folderPath.path)
144144
let addresses = directoryContents.filter({ $0.web3.isAddress || $0 == localFileName })
145145
for address in addresses {
@@ -154,7 +154,7 @@ extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol {
154154

155155
public func deletePrivateKey(for address: EthereumAddress) throws {
156156
do {
157-
if let folderPath = folderPath {
157+
if let folderPath {
158158
let filePathName = folderPath.appendingPathComponent(address.asString())
159159
try fileManager.removeItem(at: filePathName)
160160
}

web3swift/src/Account/Signature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import Foundation

web3swift/src/Account/TypedData.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import BigInt
@@ -61,8 +61,8 @@ extension TypedData {
6161
// Whole data blob hash to sign
6262
public func signableHash() throws -> Data {
6363
var data = Data([0x19, 0x01])
64-
data.append(try encodeData(data: domain, type: "EIP712Domain").web3.keccak256)
65-
data.append(try encodeData(data: message, type: primaryType).web3.keccak256)
64+
try data.append(encodeData(data: domain, type: "EIP712Domain").web3.keccak256)
65+
try data.append(encodeData(data: message, type: primaryType).web3.keccak256)
6666
return data.web3.keccak256
6767
}
6868

@@ -88,7 +88,6 @@ extension TypedData {
8888
}
8989

9090
let recursiveEncoded: [UInt8] = try valueTypes.flatMap { variable -> [UInt8] in
91-
9291
// Decomposite the type if it is array type
9392
let components = variable.type.components(separatedBy: CharacterSet(charactersIn: "[]"))
9493
let parsedType = components[0]

web3swift/src/Client/BaseEthereumClient+Call.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// web3.swift
3-
// Copyright © 2022 Argent Labs Limited. All rights reserved.
3+
// Copyright © Argent Labs Limited. All rights reserved.
44
//
55

66
import Foundation
@@ -48,7 +48,7 @@ extension BaseEthereumClient {
4848
func encode(to encoder: Encoder) throws {
4949
var container = encoder.unkeyedContainer()
5050
var nested = container.nestedContainer(keyedBy: TransactionCodingKeys.self)
51-
if let from = from {
51+
if let from {
5252
try nested.encode(from, forKey: .from)
5353
}
5454
try nested.encode(to, forKey: .to)
@@ -212,11 +212,11 @@ fileprivate extension OffchainReadError {
212212
var isNextURLAllowed: Bool {
213213
switch self {
214214
case let .server(code, _):
215-
return code >= 500 // 4xx responses -> Don't continue with next url
215+
code >= 500 // 4xx responses -> Don't continue with next url
216216
case .network, .invalidParams, .invalidResponse:
217-
return true
217+
true
218218
case .tooManyRedirections:
219-
return false
219+
false
220220
}
221221
}
222222
}

0 commit comments

Comments
 (0)