Skip to content

Commit e9af0e9

Browse files
committed
Add SwiftFormat config + format code with both formatters
1 parent ae7da82 commit e9af0e9

File tree

7 files changed

+56
-42
lines changed

7 files changed

+56
-42
lines changed

.swiftformat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Minimal SwiftFormat config for explicit self insertion only
2+
# Used in conjunction with Apple swift-format for comprehensive formatting
3+
#
4+
# IMPORTANT: Only handles explicit self insertion - all other formatting
5+
# is managed by Apple swift-format to avoid conflicts
6+
7+
# Swift version
8+
--swift-version 6.1
9+
10+
# Explicit self rule only
11+
--self insert
12+
13+
# Use only the redundantSelf rule (exclusive list)
14+
--rules redundantSelf

Sources/HandySwift/Extensions/ComparableExt.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension Comparable {
7777
/// - Parameter limits: The closed range determining minimum and maximum value.
7878
@inlinable
7979
public mutating func clamp(to limits: ClosedRange<Self>) {
80-
self = clamped(to: limits)
80+
self = self.clamped(to: limits)
8181
}
8282

8383
/// Clamps `self` to the given partial range (from) limits.
@@ -93,7 +93,7 @@ extension Comparable {
9393
/// - Parameter limits: The partial range (from) determining the minimum value.
9494
@inlinable
9595
public mutating func clamp(to limits: PartialRangeFrom<Self>) {
96-
self = clamped(to: limits)
96+
self = self.clamped(to: limits)
9797
}
9898

9999
/// Clamps `self` to the given partial range (through) limits.
@@ -112,6 +112,6 @@ extension Comparable {
112112
/// - Parameter limits: The partial range (through) determining the maximum value.
113113
@inlinable
114114
public mutating func clamp(to limits: PartialRangeThrough<Self>) {
115-
self = clamped(to: limits)
115+
self = self.clamped(to: limits)
116116
}
117117
}

Sources/HandySwift/Extensions/StringExt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension String {
4242
///
4343
/// - Returns: The NSRange representation of the full string range.
4444
public var fullNSRange: NSRange {
45-
NSRange(fullRange, in: self)
45+
NSRange(self.fullRange, in: self)
4646
}
4747

4848
/// Creates a new instance with a random numeric/alphabetic/alphanumeric string of given length.

Sources/HandySwift/Extensions/TimeIntervalExt.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension TimeInterval {
8787
/// - Returns: The time interval in days.
8888
@inlinable
8989
public static func days(_ value: Double) -> TimeInterval {
90-
value * secondsPerDay
90+
value * self.secondsPerDay
9191
}
9292

9393
/// Converts the provided value to `TimeInterval` representing hours.
@@ -96,7 +96,7 @@ extension TimeInterval {
9696
/// - Returns: The time interval in hours.
9797
@inlinable
9898
public static func hours(_ value: Double) -> TimeInterval {
99-
value * secondsPerHour
99+
value * self.secondsPerHour
100100
}
101101

102102
/// Converts the provided value to `TimeInterval` representing minutes.
@@ -105,7 +105,7 @@ extension TimeInterval {
105105
/// - Returns: The time interval in minutes.
106106
@inlinable
107107
public static func minutes(_ value: Double) -> TimeInterval {
108-
value * secondsPerMinute
108+
value * self.secondsPerMinute
109109
}
110110

111111
/// Converts the provided value to `TimeInterval` representing seconds.
@@ -123,7 +123,7 @@ extension TimeInterval {
123123
/// - Returns: The time interval in milliseconds.
124124
@inlinable
125125
public static func milliseconds(_ value: Double) -> TimeInterval {
126-
value / millisecondsPerSecond
126+
value / self.millisecondsPerSecond
127127
}
128128

129129
/// Converts the provided value to `TimeInterval` representing microseconds.
@@ -132,7 +132,7 @@ extension TimeInterval {
132132
/// - Returns: The time interval in microseconds.
133133
@inlinable
134134
public static func microseconds(_ value: Double) -> TimeInterval {
135-
value / microsecondsPerSecond
135+
value / self.microsecondsPerSecond
136136
}
137137

138138
/// Converts the provided value to `TimeInterval` representing nanoseconds.
@@ -141,7 +141,7 @@ extension TimeInterval {
141141
/// - Returns: The time interval in nanoseconds.
142142
@inlinable
143143
public static func nanoseconds(_ value: Double) -> TimeInterval {
144-
value / nanosecondsPerSecond
144+
value / self.nanosecondsPerSecond
145145
}
146146

147147
/// Returns the `Duration` representation of the current time interval.

Sources/HandySwift/Types/FrequencyTable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public struct FrequencyTable<T> {
4949
/// ```
5050
@inlinable
5151
public init(values: [T], frequencyClosure: (T) throws -> Int) rethrows {
52-
valuesWithFrequencies = try values.map { ($0, try frequencyClosure($0)) }
53-
frequentValues = valuesWithFrequencies.reduce(into: []) { memo, entry in
52+
self.valuesWithFrequencies = try values.map { ($0, try frequencyClosure($0)) }
53+
self.frequentValues = self.valuesWithFrequencies.reduce(into: []) { memo, entry in
5454
memo += Array(repeating: entry.value, count: entry.frequency)
5555
}
5656
}

Sources/HandySwift/Types/HandyRegex.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public struct HandyRegex {
102102
/// - throws: A value of `ErrorType` describing the invalid regular expression.
103103
@available(*, deprecated, message: "The HandyRegex type will be removed in a future version. Migrate to Swift.Regex<Output> if possible.")
104104
public init(_ pattern: String, options: Options = []) throws {
105-
regularExpression = try NSRegularExpression(
105+
self.regularExpression = try NSRegularExpression(
106106
pattern: pattern,
107107
options: options.toNSRegularExpressionOptions
108108
)
@@ -116,7 +116,7 @@ public struct HandyRegex {
116116
@available(*, deprecated, message: "The HandyRegex type will be removed in a future version. Migrate to Swift.Regex<Output> if possible.")
117117
@inlinable
118118
public func matches(_ string: String) -> Bool {
119-
firstMatch(in: string) != nil
119+
self.firstMatch(in: string) != nil
120120
}
121121

122122
/// If the regex matches `string`, returns a `Match` describing the
@@ -129,7 +129,7 @@ public struct HandyRegex {
129129
@available(*, deprecated, message: "The HandyRegex type will be removed in a future version. Migrate to Swift.Regex<Output> if possible.")
130130
@inlinable
131131
public func firstMatch(in string: String) -> Match? {
132-
regularExpression
132+
self.regularExpression
133133
.firstMatch(in: string, options: [], range: NSRange(location: 0, length: string.utf16.count))
134134
.map { Match(result: $0, in: string) }
135135
}
@@ -144,7 +144,7 @@ public struct HandyRegex {
144144
@available(*, deprecated, message: "The HandyRegex type will be removed in a future version. Migrate to Swift.Regex<Output> if possible.")
145145
@inlinable
146146
public func matches(in string: String) -> [Match] {
147-
regularExpression
147+
self.regularExpression
148148
.matches(in: string, options: [], range: NSRange(location: 0, length: string.utf16.count))
149149
.map { Match(result: $0, in: string) }
150150
}
@@ -183,7 +183,7 @@ public struct HandyRegex {
183183
extension HandyRegex: CustomStringConvertible {
184184
/// Returns a string describing the regex using its pattern string.
185185
public var description: String {
186-
"Regex<\"\(regularExpression.pattern)\">"
186+
"Regex<\"\(self.regularExpression.pattern)\">"
187187
}
188188
}
189189

@@ -199,7 +199,7 @@ extension HandyRegex: Equatable {
199199
extension HandyRegex: Hashable {
200200
/// Manages hashing of the `Regex` instance.
201201
public func hash(into hasher: inout Hasher) {
202-
hasher.combine(regularExpression)
202+
hasher.combine(self.regularExpression)
203203
}
204204
}
205205

@@ -275,7 +275,7 @@ extension HandyRegex {
275275
/// regex.matches(in: "b").first?.captures // [nil, Optional("b")]
276276
public lazy var captures: [String?] = {
277277
let captureRanges = stride(from: 0, to: result.numberOfRanges, by: 1)
278-
.map(result.range)
278+
.map(self.result.range)
279279
.dropFirst()
280280
.map { [unowned self] in
281281
Range($0, in: self.baseString)
@@ -316,17 +316,17 @@ extension HandyRegex {
316316
///
317317
/// - returns: A string with `template` applied to the matched string.
318318
public func string(applyingTemplate template: String) -> String {
319-
result.regularExpression!.replacementString(
320-
for: result,
321-
in: baseString,
319+
self.result.regularExpression!.replacementString(
320+
for: self.result,
321+
in: self.baseString,
322322
offset: 0,
323323
template: template
324324
)
325325
}
326326

327327
/// Returns a string describing the match.
328328
public var description: String {
329-
"Match<\"\(string)\">"
329+
"Match<\"\(self.string)\">"
330330
}
331331
}
332332
}

Sources/HandySwift/Types/SortedArray.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public struct SortedArray<Element: Comparable> {
3939
///
4040
/// var emptyArray = SortedArray<Int>()
4141
public init() {
42-
internalArray = []
42+
self.internalArray = []
4343
}
4444

4545
/// Creates a new SortedArray with a given sequence of elements and sorts its elements.
@@ -54,7 +54,7 @@ public struct SortedArray<Element: Comparable> {
5454

5555
@usableFromInline
5656
internal init<S: Sequence>(sequence: S, preSorted: Bool) where S.Iterator.Element == Element {
57-
internalArray = preSorted ? Array(sequence) : Array(sequence).sorted()
57+
self.internalArray = preSorted ? Array(sequence) : Array(sequence).sorted()
5858
}
5959

6060
/// Returns the first index in which an element of the array satisfies the given predicate.
@@ -68,19 +68,19 @@ public struct SortedArray<Element: Comparable> {
6868
@inlinable
6969
public func firstIndex(where predicate: (Element) -> Bool) -> Int? {
7070
// cover trivial cases
71-
guard !array.isEmpty else { return nil }
71+
guard !self.array.isEmpty else { return nil }
7272

73-
if let first = array.first, predicate(first) { return array.startIndex }
73+
if let first = array.first, predicate(first) { return self.array.startIndex }
7474
if let last = array.last, !predicate(last) { return nil }
7575

7676
// binary search for first matching element
7777
var foundMatch = false
78-
var lowerIndex = array.startIndex
79-
var upperIndex = array.endIndex
78+
var lowerIndex = self.array.startIndex
79+
var upperIndex = self.array.endIndex
8080

8181
while lowerIndex != upperIndex {
8282
let middleIndex = lowerIndex + (upperIndex - lowerIndex) / 2
83-
guard predicate(array[middleIndex]) else {
83+
guard predicate(self.array[middleIndex]) else {
8484
lowerIndex = middleIndex + 1
8585
continue
8686
}
@@ -140,8 +140,8 @@ public struct SortedArray<Element: Comparable> {
140140
/// - newElement: The new element to be inserted into the array.
141141
@inlinable
142142
public mutating func insert(_ newElement: Element) {
143-
let insertIndex = internalArray.firstIndex { $0 >= newElement } ?? internalArray.endIndex
144-
internalArray.insert(newElement, at: insertIndex)
143+
let insertIndex = self.internalArray.firstIndex { $0 >= newElement } ?? self.internalArray.endIndex
144+
self.internalArray.insert(newElement, at: insertIndex)
145145
}
146146

147147
/// Adds the contents of a sequence to the SortedArray.
@@ -152,7 +152,7 @@ public struct SortedArray<Element: Comparable> {
152152
/// - sequence
153153
@inlinable
154154
public mutating func insert<S: Sequence>(contentsOf sequence: S) where S.Iterator.Element == Element {
155-
sequence.forEach { insert($0) }
155+
sequence.forEach { self.insert($0) }
156156
}
157157

158158
/// Removes an item from the sorted array.
@@ -163,15 +163,15 @@ public struct SortedArray<Element: Comparable> {
163163
/// - index: The index of the element to remove from the sorted array.
164164
@inlinable
165165
public mutating func remove(at index: Int) {
166-
internalArray.remove(at: index)
166+
self.internalArray.remove(at: index)
167167
}
168168

169169
/// Removes an item from the sorted array.
170170
///
171171
/// - Complexity: O(*n*), where *n* is the length of the collection.
172172
@inlinable
173173
public mutating func removeAll(where condition: (Element) -> Bool) {
174-
internalArray.removeAll(where: condition)
174+
self.internalArray.removeAll(where: condition)
175175
}
176176

177177
/// Accesses a contiguous subrange of the SortedArray's elements.
@@ -180,7 +180,7 @@ public struct SortedArray<Element: Comparable> {
180180
/// - bounds: A range of the SortedArray's indices. The bounds of the range must be valid indices.
181181
@inlinable
182182
public subscript(bounds: Range<Int>) -> SortedArray {
183-
SortedArray(sequence: array[bounds], preSorted: true)
183+
SortedArray(sequence: self.array[bounds], preSorted: true)
184184
}
185185
}
186186

@@ -194,46 +194,46 @@ extension SortedArray: BidirectionalCollection {
194194
///
195195
/// If the collection is empty, `startIndex` is equal to `endIndex`.
196196
@inlinable public var startIndex: Int {
197-
internalArray.startIndex
197+
self.internalArray.startIndex
198198
}
199199

200200
/// The collection's "past-the-end" position---that is, the position one greater than the last valid subscript argument.
201201
///
202202
/// When you need a range that includes the last element of a collection, use the `..<` operator with `endIndex`.
203203
public var endIndex: Int {
204-
internalArray.endIndex
204+
self.internalArray.endIndex
205205
}
206206

207207
/// Returns the elements of the collection in sorted order.
208208
///
209209
/// - Returns: An array containing the sorted elements of the collection.
210210
@inlinable
211211
public func sorted() -> [Element] {
212-
internalArray
212+
self.internalArray
213213
}
214214

215215
/// Returns the position immediately after the given index.
216216
///
217217
/// - Parameter index: A valid index of the collection. `index` must be less than `endIndex`.
218218
/// - Returns: The index value immediately after `index`.
219219
public func index(after index: Int) -> Int {
220-
internalArray.index(after: index)
220+
self.internalArray.index(after: index)
221221
}
222222

223223
/// Returns the position immediately before the given index.
224224
///
225225
/// - Parameter index: A valid index of the collection. `index` must be greater than `startIndex`.
226226
/// - Returns: The index value immediately before `index`.
227227
public func index(before index: Int) -> Int {
228-
internalArray.index(before: index)
228+
self.internalArray.index(before: index)
229229
}
230230

231231
/// Accesses the element at the specified position.
232232
///
233233
/// - Parameter position: The position of the element to access. `position` must be a valid index of the collection.
234234
/// - Returns: The element at the specified index.
235235
public subscript(position: Int) -> Element {
236-
internalArray[position]
236+
self.internalArray[position]
237237
}
238238
}
239239

0 commit comments

Comments
 (0)