Skip to content

Commit 66e01e2

Browse files
committed
Fix lint post merge
1 parent 8ba6c0e commit 66e01e2

File tree

5 files changed

+53
-48
lines changed

5 files changed

+53
-48
lines changed

.swiftlint.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ type_body_length:
2828
warning: 260
2929
error: 260
3030

31+
function_body_length:
32+
warning: 60
33+
error: 60
34+
3135
line_length:
3236
warning: 150
3337
error: 150
3438
ignores_comments: true
3539

3640
file_length:
37-
warning: 760
38-
error: 760
41+
warning: 900
42+
error: 900

Sources/SQLite/Core/Connection.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import SQLite3
3535
#endif
3636

3737
/// A connection to SQLite.
38+
// swiftlint:disable:next type_body_length
3839
public final class Connection {
3940

4041
/// The location of a SQLite database.
@@ -585,7 +586,7 @@ public final class Connection {
585586
/// - block: A block of code to run when the function is called. The block
586587
/// is called with an array of raw SQL values mapped to the function’s
587588
/// parameters and should return a raw SQL value (or nil).
588-
// swiftlint:disable:next cyclomatic_complexity function_body_length
589+
// swiftlint:disable:next cyclomatic_complexity
589590
public func createFunction(_ function: String, argumentCount: UInt? = nil, deterministic: Bool = false,
590591
_ block: @escaping (_ args: [Binding?]) -> Binding?) {
591592
let argc = argumentCount.map { Int($0) } ?? -1
@@ -636,7 +637,7 @@ public final class Connection {
636637
if functions[function] == nil { functions[function] = [:] }
637638
functions[function]?[argc] = box
638639
}
639-
640+
640641
/// Creates or redefines a custom SQL aggregate.
641642
///
642643
/// - Parameters:
@@ -665,19 +666,19 @@ public final class Connection {
665666
/// - state: A block of code to run to produce a fresh state variable for
666667
/// each aggregation group. The block should return an
667668
/// UnsafeMutablePointer to the fresh state variable.
669+
// swiftlint:disable:next cyclomatic_complexity
668670
public func createAggregation<T>(
669671
_ aggregate: String,
670672
argumentCount: UInt? = nil,
671673
deterministic: Bool = false,
672-
step: @escaping ([Binding?], UnsafeMutablePointer<T>) -> (),
674+
step: @escaping ([Binding?], UnsafeMutablePointer<T>) -> Void,
673675
final: @escaping (UnsafeMutablePointer<T>) -> Binding?,
674676
state: @escaping () -> UnsafeMutablePointer<T>) {
675-
676-
677+
677678
let argc = argumentCount.map { Int($0) } ?? -1
678-
let box : Aggregate = { (stepFlag: Int, context: OpaquePointer?, argc: Int32, argv: UnsafeMutablePointer<OpaquePointer?>?) in
679+
let box: Aggregate = { (stepFlag: Int, context: OpaquePointer?, argc: Int32, argv: UnsafeMutablePointer<OpaquePointer?>?) in
679680
let ptr = sqlite3_aggregate_context(context, 64)! // needs to be at least as large as uintptr_t; better way to do this?
680-
let p = ptr.assumingMemoryBound(to: UnsafeMutableRawPointer.self)
681+
let mutablePointer = ptr.assumingMemoryBound(to: UnsafeMutableRawPointer.self)
681682
if stepFlag > 0 {
682683
let arguments: [Binding?] = (0..<Int(argc)).map { idx in
683684
let value = argv![idx]
@@ -696,14 +697,14 @@ public final class Connection {
696697
fatalError("unsupported value type: \(type)")
697698
}
698699
}
699-
700+
700701
if ptr.assumingMemoryBound(to: Int64.self).pointee == 0 {
701-
let v = state()
702-
p.pointee = UnsafeMutableRawPointer(mutating: v)
702+
let value = state()
703+
mutablePointer.pointee = UnsafeMutableRawPointer(mutating: value)
703704
}
704-
step(arguments, p.pointee.assumingMemoryBound(to: T.self))
705+
step(arguments, mutablePointer.pointee.assumingMemoryBound(to: T.self))
705706
} else {
706-
let result = final(p.pointee.assumingMemoryBound(to: T.self))
707+
let result = final(mutablePointer.pointee.assumingMemoryBound(to: T.self))
707708
if let result = result as? Blob {
708709
sqlite3_result_blob(context, result.bytes, Int32(result.bytes.count), nil)
709710
} else if let result = result as? Double {
@@ -719,14 +720,14 @@ public final class Connection {
719720
}
720721
}
721722
}
722-
723+
723724
var flags = SQLITE_UTF8
724725
#if !os(Linux)
725726
if deterministic {
726727
flags |= SQLITE_DETERMINISTIC
727728
}
728729
#endif
729-
730+
730731
sqlite3_create_function_v2(
731732
handle,
732733
aggregate,
@@ -737,8 +738,7 @@ public final class Connection {
737738
{ context, argc, value in
738739
let function = unsafeBitCast(sqlite3_user_data(context), to: Aggregate.self)
739740
function(1, context, argc, value)
740-
},
741-
{ context in
741+
}, { context in
742742
let function = unsafeBitCast(sqlite3_user_data(context), to: Aggregate.self)
743743
function(0, context, 0, nil)
744744
},

Sources/SQLite/Typed/CoreFunctions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
// THE SOFTWARE.
2323
//
24-
// swiftlint:disable file_length
2524
import Foundation
2625

2726
private enum Function: String {

Sources/SQLite/Typed/CustomFunctions.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,25 @@ public extension Connection {
170170
result: @escaping (T) -> Binding?
171171
) {
172172

173-
let step: ([Binding?], UnsafeMutablePointer<UnsafeMutableRawPointer>) -> () = { (bindings, ptr) in
174-
let p = ptr.pointee.assumingMemoryBound(to: T.self)
175-
let current = Unmanaged<T>.fromOpaque(p).takeRetainedValue()
173+
let step: ([Binding?], UnsafeMutablePointer<UnsafeMutableRawPointer>) -> Void = { (bindings, ptr) in
174+
let pointer = ptr.pointee.assumingMemoryBound(to: T.self)
175+
let current = Unmanaged<T>.fromOpaque(pointer).takeRetainedValue()
176176
let next = reduce(current, bindings)
177177
ptr.pointee = Unmanaged.passRetained(next).toOpaque()
178178
}
179179

180180
let final: (UnsafeMutablePointer<UnsafeMutableRawPointer>) -> Binding? = { (ptr) in
181-
let p = ptr.pointee.assumingMemoryBound(to: T.self)
182-
let obj = Unmanaged<T>.fromOpaque(p).takeRetainedValue()
181+
let pointer = ptr.pointee.assumingMemoryBound(to: T.self)
182+
let obj = Unmanaged<T>.fromOpaque(pointer).takeRetainedValue()
183183
let value = result(obj)
184184
ptr.deallocate()
185185
return value
186186
}
187187

188188
let state: () -> UnsafeMutablePointer<UnsafeMutableRawPointer> = {
189-
let p = UnsafeMutablePointer<UnsafeMutableRawPointer>.allocate(capacity: 1)
190-
p.pointee = Unmanaged.passRetained(initialValue).toOpaque()
191-
return p
189+
let pointer = UnsafeMutablePointer<UnsafeMutableRawPointer>.allocate(capacity: 1)
190+
pointer.pointee = Unmanaged.passRetained(initialValue).toOpaque()
191+
return pointer
192192
}
193193

194194
createAggregation(aggregate, step: step, final: final, state: state)
@@ -203,22 +203,22 @@ public extension Connection {
203203
result: @escaping (T) -> Binding?
204204
) {
205205

206-
let step: ([Binding?], UnsafeMutablePointer<T>) -> () = { (bindings, p) in
207-
let current = p.pointee
206+
let step: ([Binding?], UnsafeMutablePointer<T>) -> Void = { (bindings, pointer) in
207+
let current = pointer.pointee
208208
let next = reduce(current, bindings)
209-
p.pointee = next
209+
pointer.pointee = next
210210
}
211211

212-
let final: (UnsafeMutablePointer<T>) -> Binding? = { (p) in
213-
let v = result(p.pointee)
214-
p.deallocate()
215-
return v
212+
let final: (UnsafeMutablePointer<T>) -> Binding? = { pointer in
213+
let value = result(pointer.pointee)
214+
pointer.deallocate()
215+
return value
216216
}
217217

218218
let state: () -> UnsafeMutablePointer<T> = {
219-
let p = UnsafeMutablePointer<T>.allocate(capacity: 1)
220-
p.pointee = initialValue
221-
return p
219+
let pointer = UnsafeMutablePointer<T>.allocate(capacity: 1)
220+
pointer.pointee = initialValue
221+
return pointer
222222
}
223223

224224
createAggregation(aggregate, step: step, final: final, state: state)

Tests/SQLiteTests/CustomAggregationTests.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import CSQLite
1313
import SQLite3
1414
#endif
1515

16-
class CustomAggregationTests : SQLiteTestCase {
16+
class CustomAggregationTests: SQLiteTestCase {
1717
override func setUp() {
1818
super.setUp()
1919
createUsersTable()
@@ -35,7 +35,7 @@ class CustomAggregationTests : SQLiteTestCase {
3535
p.deallocate()
3636
return v
3737
}
38-
let _ = db.createAggregation("mySUM1", step: step, final: final) {
38+
_ = db.createAggregation("mySUM1", step: step, final: final) {
3939
let v = UnsafeMutableBufferPointer<Int64>.allocate(capacity: 1)
4040
v[0] = 0
4141
return v.baseAddress!
@@ -60,7 +60,7 @@ class CustomAggregationTests : SQLiteTestCase {
6060
p.deallocate()
6161
return v
6262
}
63-
let _ = db.createAggregation("mySUM2", step: step, final: final) {
63+
_ = db.createAggregation("mySUM2", step: step, final: final) {
6464
let v = UnsafeMutableBufferPointer<Int64>.allocate(capacity: 1)
6565
v[0] = 0
6666
return v.baseAddress!
@@ -72,11 +72,11 @@ class CustomAggregationTests : SQLiteTestCase {
7272
}
7373

7474
func testCustomSum() {
75-
let reduce : (Int64, [Binding?]) -> Int64 = { (last, bindings) in
75+
let reduce: (Int64, [Binding?]) -> Int64 = { (last, bindings) in
7676
let v = (bindings[0] as? Int64) ?? 0
7777
return last + v
7878
}
79-
let _ = db.createAggregation("myReduceSUM1", initialValue: Int64(2000), reduce: reduce, result: { $0 })
79+
_ = db.createAggregation("myReduceSUM1", initialValue: Int64(2000), reduce: reduce, result: { $0 })
8080
let result = try! db.prepare("SELECT myReduceSUM1(age) AS s FROM users")
8181
let i = result.columnNames.firstIndex(of: "s")!
8282
for row in result {
@@ -86,11 +86,11 @@ class CustomAggregationTests : SQLiteTestCase {
8686
}
8787

8888
func testCustomSumGrouping() {
89-
let reduce : (Int64, [Binding?]) -> Int64 = { (last, bindings) in
89+
let reduce: (Int64, [Binding?]) -> Int64 = { (last, bindings) in
9090
let v = (bindings[0] as? Int64) ?? 0
9191
return last + v
9292
}
93-
let _ = db.createAggregation("myReduceSUM2", initialValue: Int64(3000), reduce: reduce, result: { $0 })
93+
_ = db.createAggregation("myReduceSUM2", initialValue: Int64(3000), reduce: reduce, result: { $0 })
9494
let result = try! db.prepare("SELECT myReduceSUM2(age) AS s FROM users GROUP BY admin ORDER BY s")
9595
let i = result.columnNames.firstIndex(of: "s")!
9696
let values = result.compactMap { $0[i] as? Int64 }
@@ -99,11 +99,11 @@ class CustomAggregationTests : SQLiteTestCase {
9999

100100
func testCustomStringAgg() {
101101
let initial = String(repeating: " ", count: 64)
102-
let reduce : (String, [Binding?]) -> String = { (last, bindings) in
102+
let reduce: (String, [Binding?]) -> String = { (last, bindings) in
103103
let v = (bindings[0] as? String) ?? ""
104104
return last + v
105105
}
106-
let _ = db.createAggregation("myReduceSUM3", initialValue: initial, reduce: reduce, result: { $0 })
106+
_ = db.createAggregation("myReduceSUM3", initialValue: initial, reduce: reduce, result: { $0 })
107107
let result = try! db.prepare("SELECT myReduceSUM3(email) AS s FROM users")
108108
let i = result.columnNames.firstIndex(of: "s")!
109109
for row in result {
@@ -115,14 +115,16 @@ class CustomAggregationTests : SQLiteTestCase {
115115
func testCustomObjectSum() {
116116
{
117117
let initial = TestObject(value: 1000)
118-
let reduce : (TestObject, [Binding?]) -> TestObject = { (last, bindings) in
118+
let reduce: (TestObject, [Binding?]) -> TestObject = { (last, bindings) in
119119
let v = (bindings[0] as? Int64) ?? 0
120120
return TestObject(value: last.value + v)
121121
}
122-
let _ = db.createAggregation("myReduceSUMX", initialValue: initial, reduce: reduce, result: { $0.value })
122+
db.createAggregation("myReduceSUMX", initialValue: initial, reduce: reduce, result: { $0.value })
123123
// end this scope to ensure that the initial value is retained
124124
// by the createAggregation call.
125+
// swiftlint:disable:next trailing_semicolon
125126
}();
127+
126128
{
127129
XCTAssertEqual(TestObject.inits, 1)
128130
let result = try! db.prepare("SELECT myReduceSUMX(age) AS s FROM users")

0 commit comments

Comments
 (0)