Skip to content

Commit ae7da82

Browse files
committed
Add swift-format config file + apply auto-corrections
1 parent e9defa2 commit ae7da82

Some content is hidden

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

42 files changed

+619
-476
lines changed

.swift-format

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentConditionalCompilationBlocks" : true,
6+
"indentSwitchCaseLabels" : false,
7+
"indentation" : {
8+
"spaces" : 3
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : true,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineLength" : 150,
15+
"maximumBlankLines" : 1,
16+
"multiElementCollectionTrailingCommas" : true,
17+
"noAssignmentInExpressions" : {
18+
"allowedFunctions" : [
19+
"XCTAssertNoThrow"
20+
]
21+
},
22+
"prioritizeKeepingFunctionOutputTogether" : false,
23+
"respectsExistingLineBreaks" : true,
24+
"rules" : {
25+
"AllPublicDeclarationsHaveDocumentation" : true,
26+
"AlwaysUseLiteralForEmptyCollectionInit" : true,
27+
"AlwaysUseLowerCamelCase" : true,
28+
"AmbiguousTrailingClosureOverload" : true,
29+
"BeginDocumentationCommentWithOneLineSummary" : true,
30+
"DoNotUseSemicolons" : true,
31+
"DontRepeatTypeInStaticProperties" : true,
32+
"FileScopedDeclarationPrivacy" : true,
33+
"FullyIndirectEnum" : true,
34+
"GroupNumericLiterals" : true,
35+
"IdentifiersMustBeASCII" : true,
36+
"NeverForceUnwrap" : false,
37+
"NeverUseForceTry" : false,
38+
"NeverUseImplicitlyUnwrappedOptionals" : false,
39+
"NoAccessLevelOnExtensionDeclaration" : true,
40+
"NoAssignmentInExpressions" : true,
41+
"NoBlockComments" : true,
42+
"NoCasesWithOnlyFallthrough" : true,
43+
"NoEmptyTrailingClosureParentheses" : true,
44+
"NoLabelsInCasePatterns" : true,
45+
"NoLeadingUnderscores" : false,
46+
"NoParensAroundConditions" : true,
47+
"NoPlaygroundLiterals" : true,
48+
"NoVoidReturnOnFunctionSignature" : true,
49+
"OmitExplicitReturns" : true,
50+
"OneCasePerLine" : true,
51+
"OneVariableDeclarationPerLine" : true,
52+
"OnlyOneTrailingClosureArgument" : true,
53+
"OrderedImports" : true,
54+
"ReplaceForEachWithForLoop" : true,
55+
"ReturnVoidInsteadOfEmptyTuple" : true,
56+
"TypeNamesShouldBeCapitalized" : true,
57+
"UseEarlyExits" : false,
58+
"UseExplicitNilCheckInConditions" : true,
59+
"UseLetInEveryBoundCaseVariable" : true,
60+
"UseShorthandTypeNames" : true,
61+
"UseSingleLinePropertyGetter" : true,
62+
"UseSynthesizedInitializer" : true,
63+
"UseTripleSlashForDocumentationComments" : true,
64+
"UseWhereClausesInForLoops" : true,
65+
"ValidateDocumentationComments" : true
66+
},
67+
"spacesAroundRangeFormationOperators" : false,
68+
"tabWidth" : 8,
69+
"version" : 1
70+
}

Package.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import PackageDescription
33

44
let package = Package(
5-
name: "HandySwift",
6-
platforms: [.iOS(.v12), .macOS(.v10_14), .tvOS(.v13), .visionOS(.v1), .watchOS(.v6)],
7-
products: [.library(name: "HandySwift", targets: ["HandySwift"])],
8-
targets: [
9-
.target(name: "HandySwift"),
10-
.testTarget(name: "HandySwiftTests", dependencies: ["HandySwift"]),
11-
]
5+
name: "HandySwift",
6+
platforms: [.iOS(.v12), .macOS(.v10_14), .tvOS(.v13), .visionOS(.v1), .watchOS(.v6)],
7+
products: [.library(name: "HandySwift", targets: ["HandySwift"])],
8+
targets: [
9+
.target(name: "HandySwift"),
10+
.testTarget(name: "HandySwiftTests", dependencies: ["HandySwift"]),
11+
]
1212
)

Sources/HandySwift/Extensions/ArrayExt.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@ import Foundation
22

33
// - MARK: Migration
44
extension Array {
5-
@available(*, unavailable, renamed: "sort(by:)", message: "Since SE-0372 shipped in Swift 5.8 `sort(by:)` is officially stable. Just remove the `stable` parameter.")
5+
@available(
6+
*,
7+
unavailable,
8+
renamed: "sort(by:)",
9+
message: "Since SE-0372 shipped in Swift 5.8 `sort(by:)` is officially stable. Just remove the `stable` parameter."
10+
)
611
public mutating func sort(by areInIncreasingOrder: @escaping (Element, Element) -> Bool, stable: Bool) { fatalError() }
712

8-
@available(*, unavailable, renamed: "sorted(by:)", message: "Since SE-0372 shipped in Swift 5.8 `sorted(by:)` is officially stable. Just remove the `stable` parameter.")
13+
@available(
14+
*,
15+
unavailable,
16+
renamed: "sorted(by:)",
17+
message: "Since SE-0372 shipped in Swift 5.8 `sorted(by:)` is officially stable. Just remove the `stable` parameter."
18+
)
919
public func sorted(by areInIncreasingOrder: @escaping (Element, Element) -> Bool, stable: Bool) -> [Element] { fatalError() }
1020
}
1121

1222
extension Array where Element: Comparable {
13-
@available(*, unavailable, renamed: "sort()", message: "Since SE-0372 shipped in Swift 5.8 `sort()` is officially stable. Just remove the `stable` parameter.")
23+
@available(
24+
*,
25+
unavailable,
26+
renamed: "sort()",
27+
message: "Since SE-0372 shipped in Swift 5.8 `sort()` is officially stable. Just remove the `stable` parameter."
28+
)
1429
public mutating func sort(stable: Bool) { fatalError() }
1530

16-
@available(*, unavailable, renamed: "sorted()", message: "Since SE-0372 shipped in Swift 5.8 `sorted()` is officially stable. Just remove the `stable` parameter.")
31+
@available(
32+
*,
33+
unavailable,
34+
renamed: "sorted()",
35+
message: "Since SE-0372 shipped in Swift 5.8 `sorted()` is officially stable. Just remove the `stable` parameter."
36+
)
1737
public func sorted(stable: Bool) -> [Element] { fatalError() }
1838
}

Sources/HandySwift/Extensions/CollectionExt.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
extension Collection {
4-
/// Returns the element at the specified index or `nil` if no element at the given index exists.
4+
/// Returns the element at the specified index or `nil` if no element at the given index exists.
55
/// This is particularly useful when dealing with collections of elements where you're unsure if an index is within the collection's bounds.
66
/// It helps prevent crashes due to accessing an index out of bounds.
77
///
@@ -74,7 +74,7 @@ extension Collection {
7474
}
7575

7676
extension Collection where Element: DivisibleArithmetic {
77-
/// Returns the average of all elements. It sums up all the elements and then divides by the count of the collection.
77+
/// Returns the average of all elements. It sums up all the elements and then divides by the count of the collection.
7878
/// This method requires that the element type conforms to `DivisibleArithmetic`, which includes numeric types such as `Int`, `Double`, etc.
7979
///
8080
/// Example:
@@ -91,7 +91,7 @@ extension Collection where Element: DivisibleArithmetic {
9191
}
9292

9393
extension Collection where Element == Int {
94-
/// Returns the average of all elements as a Double value.
94+
/// Returns the average of all elements as a Double value.
9595
/// This is useful for `Int` collections where the precision of the average calculation is important and you prefer the result to be a `Double`.
9696
///
9797
/// Example:

Sources/HandySwift/Extensions/ComparableExt.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension Comparable {
4646
limits.lowerBound > self ? limits.lowerBound : self
4747
}
4848

49-
/// Returns `self` clamped to the given partial range (through) limits.
49+
/// Returns `self` clamped to the given partial range (through) limits.
5050
/// This method ensures that the value does not exceed a specified maximum.
5151
///
5252
/// Example:
@@ -64,7 +64,7 @@ extension Comparable {
6464
limits.upperBound < self ? limits.upperBound : self
6565
}
6666

67-
/// Clamps `self` to the given closed range limits.
67+
/// Clamps `self` to the given closed range limits.
6868
/// Modifies the original value to ensure it falls within a specific range, adjusting it to the nearest boundary if necessary.
6969
///
7070
/// Example:
@@ -80,7 +80,7 @@ extension Comparable {
8080
self = clamped(to: limits)
8181
}
8282

83-
/// Clamps `self` to the given partial range (from) limits.
83+
/// Clamps `self` to the given partial range (from) limits.
8484
/// Modifies the original value to ensure it does not fall below a specified minimum.
8585
///
8686
/// Example:
@@ -96,7 +96,7 @@ extension Comparable {
9696
self = clamped(to: limits)
9797
}
9898

99-
/// Clamps `self` to the given partial range (through) limits.
99+
/// Clamps `self` to the given partial range (through) limits.
100100
/// Modifies the original value to ensure it does not exceed a specified maximum.
101101
///
102102
/// Example:
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
#if canImport(CryptoKit)
2-
import CryptoKit
3-
import Foundation
2+
import CryptoKit
3+
import Foundation
44

5-
extension Data {
6-
/// Encrypts this plain `Data` using AES.GCM with the provided key.
7-
/// This method is useful for encrypting data before securely storing or transmitting it.
8-
/// Ensure that the `SymmetricKey` used for encryption is securely managed and stored.
9-
///
10-
/// Example:
11-
/// ```swift
12-
/// let key = SymmetricKey(size: .bits256)
13-
/// let plainData = "Harry Potter is a 🧙".data(using: .utf8)!
14-
/// do {
15-
/// let encryptedData = try plainData.encrypted(key: key)
16-
/// // Use encryptedData as needed
17-
/// } catch {
18-
/// print("Encryption failed: \(error)")
19-
/// }
20-
/// ```
21-
///
22-
/// - Parameters:
23-
/// - key: The symmetric key to use for encryption.
24-
/// - Returns: The encrypted `Data`.
25-
/// - Throws: An error if encryption fails.
26-
/// - Note: Available on iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, and later.
27-
@available(iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, *)
28-
public func encrypted(key: SymmetricKey) throws -> Data {
29-
try AES.GCM.seal(self, using: key).combined!
30-
}
5+
extension Data {
6+
/// Encrypts this plain `Data` using AES.GCM with the provided key.
7+
/// This method is useful for encrypting data before securely storing or transmitting it.
8+
/// Ensure that the `SymmetricKey` used for encryption is securely managed and stored.
9+
///
10+
/// Example:
11+
/// ```swift
12+
/// let key = SymmetricKey(size: .bits256)
13+
/// let plainData = "Harry Potter is a 🧙".data(using: .utf8)!
14+
/// do {
15+
/// let encryptedData = try plainData.encrypted(key: key)
16+
/// // Use encryptedData as needed
17+
/// } catch {
18+
/// print("Encryption failed: \(error)")
19+
/// }
20+
/// ```
21+
///
22+
/// - Parameters:
23+
/// - key: The symmetric key to use for encryption.
24+
/// - Returns: The encrypted `Data`.
25+
/// - Throws: An error if encryption fails.
26+
/// - Note: Available on iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, and later.
27+
@available(iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, *)
28+
public func encrypted(key: SymmetricKey) throws -> Data {
29+
try AES.GCM.seal(self, using: key).combined!
30+
}
3131

32-
/// Decrypts this encrypted data using AES.GCM with the provided key.
33-
/// This method is crucial for converting encrypted data back to its original form securely.
34-
/// Ensure the `SymmetricKey` used matches the one used for encryption.
35-
///
36-
/// Example:
37-
/// ```swift
38-
/// let key = SymmetricKey(size: .bits256)
39-
/// // Assuming encryptedData is the Data we previously encrypted
40-
/// do {
41-
/// let decryptedData = try encryptedData.decrypted(key: key)
42-
/// let decryptedString = String(data: decryptedData, encoding: .utf8)!
43-
/// // Use decryptedString or decryptedData as needed
44-
/// } catch {
45-
/// print("Decryption failed: \(error)")
46-
/// }
47-
/// ```
48-
///
49-
/// - Parameters:
50-
/// - key: The symmetric key to use for decryption.
51-
/// - Returns: The decrypted `Data`.
52-
/// - Throws: An error if decryption fails.
53-
/// - Note: Available on iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, and later.
54-
@available(iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, *)
55-
public func decrypted(key: SymmetricKey) throws -> Data {
56-
let sealedBox = try AES.GCM.SealedBox(combined: self)
57-
return try AES.GCM.open(sealedBox, using: key)
32+
/// Decrypts this encrypted data using AES.GCM with the provided key.
33+
/// This method is crucial for converting encrypted data back to its original form securely.
34+
/// Ensure the `SymmetricKey` used matches the one used for encryption.
35+
///
36+
/// Example:
37+
/// ```swift
38+
/// let key = SymmetricKey(size: .bits256)
39+
/// // Assuming encryptedData is the Data we previously encrypted
40+
/// do {
41+
/// let decryptedData = try encryptedData.decrypted(key: key)
42+
/// let decryptedString = String(data: decryptedData, encoding: .utf8)!
43+
/// // Use decryptedString or decryptedData as needed
44+
/// } catch {
45+
/// print("Decryption failed: \(error)")
46+
/// }
47+
/// ```
48+
///
49+
/// - Parameters:
50+
/// - key: The symmetric key to use for decryption.
51+
/// - Returns: The decrypted `Data`.
52+
/// - Throws: An error if decryption fails.
53+
/// - Note: Available on iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, and later.
54+
@available(iOS 13, macOS 10.15, tvOS 13, visionOS 1, watchOS 6, *)
55+
public func decrypted(key: SymmetricKey) throws -> Data {
56+
let sealedBox = try AES.GCM.SealedBox(combined: self)
57+
return try AES.GCM.open(sealedBox, using: key)
58+
}
5859
}
59-
}
6060
#endif

Sources/HandySwift/Extensions/DictionaryExt.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
extension Dictionary {
4-
/// Initializes a new `Dictionary` and populates it with keys and values arrays.
4+
/// Initializes a new `Dictionary` and populates it with keys and values arrays.
55
/// This method is particularly useful when you have separate arrays of keys and values and you need to combine them into a single dictionary.
66
/// It ensures that each key is mapped to its corresponding value based on their order in the arrays.
77
///
@@ -56,6 +56,11 @@ extension Dictionary {
5656
@available(*, unavailable, renamed: "merge(_:uniquingKeysWith:)", message: "Append `{ $1 }` as a `uniquingKeysWith` trailing closure to migrate.")
5757
public mutating func merge(_ other: [Key: Value]) { fatalError() }
5858

59-
@available(*, unavailable, renamed: "merging(_:uniquingKeysWith:)", message: "Remove the `with:` label and append `{ $1 }` as a `uniquingKeysWith` trailing closure to migrate.")
59+
@available(
60+
*,
61+
unavailable,
62+
renamed: "merging(_:uniquingKeysWith:)",
63+
message: "Remove the `with:` label and append `{ $1 }` as a `uniquingKeysWith` trailing closure to migrate."
64+
)
6065
public func merged(with other: [Key: Value]) -> [Key: Value] { fatalError() }
6166
}

Sources/HandySwift/Extensions/DispatchTimeIntervalExt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
extension DispatchTimeInterval {
4-
/// Converts the dispatch time interval to seconds using the `TimeInterval` type.
4+
/// Converts the dispatch time interval to seconds using the `TimeInterval` type.
55
/// This is useful for when you need to work with `DispatchTimeInterval` values in contexts that require `TimeInterval` (in seconds),
66
/// such as scheduling timers, animations, or any operations that are based on seconds.
77
///

Sources/HandySwift/Extensions/DoubleExt.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Foundation
22

33
extension Double {
4-
/// Rounds the value to an integral value using the specified number of fraction digits and rounding rule.
4+
/// Rounds the value to an integral value using the specified number of fraction digits and rounding rule.
55
/// This is useful for when you need precise control over the rounding behavior of floating-point calculations,
66
/// such as in financial calculations where rounding to a specific number of decimal places is required.
77
///
88
/// Example:
99
/// ```swift
1010
/// var price: Double = 2.875
1111
/// price.round(fractionDigits: 2) // price becomes 2.88
12-
///
12+
///
1313
/// // Using a different rounding rule:
1414
/// price.round(fractionDigits: 2, rule: .down) // price becomes 2.87
1515
/// ```
@@ -24,15 +24,15 @@ extension Double {
2424
self = (self * divisor).rounded(rule) / divisor
2525
}
2626

27-
/// Returns this value rounded to an integral value using the specified number of fraction digits and rounding rule.
27+
/// Returns this value rounded to an integral value using the specified number of fraction digits and rounding rule.
2828
/// This method does not mutate the original value but instead returns a new `Double` that is the result of the rounding operation,
2929
/// making it suitable for cases where the original value must remain unchanged.
3030
///
3131
/// Example:
3232
/// ```swift
3333
/// let price: Double = 2.875
3434
/// let roundedPrice = price.rounded(fractionDigits: 2) // => 2.88
35-
///
35+
///
3636
/// // Using a different rounding rule:
3737
/// let roundedDownPrice = price.rounded(fractionDigits: 2, rule: .down) // => 2.87
3838
/// ```

0 commit comments

Comments
 (0)