From aff924a72b2da8b9a5ae76ad8eac8be32435f666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Feb 2023 10:39:26 +0100 Subject: [PATCH] Upgrade Swiftlint and fix warnings --- GRDB/Core/Database.swift | 8 ++++---- GRDB/Core/DatabaseSnapshotPool.swift | 2 +- GRDB/Core/SQL.swift | 4 ++-- GRDB/Core/SQLRequest.swift | 4 ++-- GRDB/Core/TransactionObserver.swift | 2 +- GRDB/Core/WALSnapshot.swift | 2 +- GRDB/FTS/FTS5TokenizerDescriptor.swift | 2 +- .../SQL/SQLForeignKeyRequest.swift | 2 +- .../QueryInterface/Schema/TableDefinition.swift | 2 +- GRDB/Record/TableRecord.swift | 4 ++-- GRDB/Utils/Utils.swift | 6 +++--- .../Observers/ValueWriteOnlyObserver.swift | 6 +++++- Scripts/swiftlint.yml | 17 +++++++++++++---- 13 files changed, 37 insertions(+), 24 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index dd07cfb9a..094cc0446 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -1861,10 +1861,10 @@ extension Database { enum Impl { case trace_v1(String) case trace_v2( - sqliteStatement: SQLiteStatement, - unexpandedSQL: UnsafePointer?, - sqlite3_expanded_sql: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer?, - publicStatementArguments: Bool) // See Configuration.publicStatementArguments + sqliteStatement: SQLiteStatement, + unexpandedSQL: UnsafePointer?, + sqlite3_expanded_sql: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer?, + publicStatementArguments: Bool) // See Configuration.publicStatementArguments } var impl: Impl diff --git a/GRDB/Core/DatabaseSnapshotPool.swift b/GRDB/Core/DatabaseSnapshotPool.swift index dcfbd4cb8..33cee1292 100644 --- a/GRDB/Core/DatabaseSnapshotPool.swift +++ b/GRDB/Core/DatabaseSnapshotPool.swift @@ -322,7 +322,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader { return result } } else { - /// There is no unsafe access to a snapshot. + // There is no unsafe access to a snapshot. return try read(value) } } diff --git a/GRDB/Core/SQL.swift b/GRDB/Core/SQL.swift index 644251c81..4246cf202 100644 --- a/GRDB/Core/SQL.swift +++ b/GRDB/Core/SQL.swift @@ -121,8 +121,8 @@ public struct SQL { fileprivate func qualified(with alias: TableAlias) -> Element { switch self { case .sql: - /// A raw SQL string can't be qualified with a table alias, - /// because we can't parse it. + // A raw SQL string can't be qualified with a table alias, + // because we can't parse it. return self case .subquery: // Subqueries don't need table alias diff --git a/GRDB/Core/SQLRequest.swift b/GRDB/Core/SQLRequest.swift index 8a0bd2043..6ec272c57 100644 --- a/GRDB/Core/SQLRequest.swift +++ b/GRDB/Core/SQLRequest.swift @@ -206,9 +206,9 @@ extension SQLRequest: FetchRequest { switch cache { case .none: statement = try db.makeStatement(sql: sql) - case .public?: + case .public: statement = try db.cachedStatement(sql: sql) - case .internal?: + case .internal: statement = try db.internalCachedStatement(sql: sql) } try statement.setArguments(context.arguments) diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index c0730130e..28e902426 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -1482,7 +1482,7 @@ public struct DatabasePreUpdateEvent { /// The triggering depth of the row update /// Returns: /// 0 if the preupdate callback was invoked as a result of a direct insert, - // update, or delete operation; + /// update, or delete operation; /// 1 for inserts, updates, or deletes invoked by top-level triggers; /// 2 for changes resulting from triggers called by top-level triggers; /// ... and so forth diff --git a/GRDB/Core/WALSnapshot.swift b/GRDB/Core/WALSnapshot.swift index 7ce291061..36f21eb69 100644 --- a/GRDB/Core/WALSnapshot.swift +++ b/GRDB/Core/WALSnapshot.swift @@ -65,7 +65,7 @@ final class WALSnapshot: Sendable { /// /// See . func compare(_ other: WALSnapshot) -> CInt { - return sqlite3_snapshot_cmp(sqliteSnapshot, other.sqliteSnapshot) + sqlite3_snapshot_cmp(sqliteSnapshot, other.sqliteSnapshot) } #else static let available = false diff --git a/GRDB/FTS/FTS5TokenizerDescriptor.swift b/GRDB/FTS/FTS5TokenizerDescriptor.swift index 032f6181a..f62814ac3 100644 --- a/GRDB/FTS/FTS5TokenizerDescriptor.swift +++ b/GRDB/FTS/FTS5TokenizerDescriptor.swift @@ -86,7 +86,7 @@ public struct FTS5TokenizerDescriptor { /// /// - parameters: /// - base: An eventual wrapping tokenizer which replaces the - // default unicode61() base tokenizer. + /// default unicode61() base tokenizer. /// /// See public static func porter(wrapping base: FTS5TokenizerDescriptor? = nil) -> FTS5TokenizerDescriptor { diff --git a/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift b/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift index 1a74399c5..3dbe56009 100644 --- a/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift +++ b/GRDB/QueryInterface/SQL/SQLForeignKeyRequest.swift @@ -22,7 +22,7 @@ struct SQLForeignKeyRequest { /// The (origin, destination) column pairs that join a left table to a right table. func fetchForeignKeyMapping(_ db: Database) throws -> ForeignKeyMapping { - if let originColumns, let destinationColumns = destinationColumns { + if let originColumns, let destinationColumns { // Total information: no need to query the database schema. GRDBPrecondition(originColumns.count == destinationColumns.count, "Number of columns don't match") let mapping = zip(originColumns, destinationColumns).map { diff --git a/GRDB/QueryInterface/Schema/TableDefinition.swift b/GRDB/QueryInterface/Schema/TableDefinition.swift index 20019c986..03b399176 100644 --- a/GRDB/QueryInterface/Schema/TableDefinition.swift +++ b/GRDB/QueryInterface/Schema/TableDefinition.swift @@ -1927,7 +1927,7 @@ public final class ColumnDefinition { switch notNullConflictResolution { case .none: break - case .abort?: + case .abort: chunks.append("NOT NULL") case let conflictResolution?: chunks.append("NOT NULL ON CONFLICT") diff --git a/GRDB/Record/TableRecord.swift b/GRDB/Record/TableRecord.swift index 3bac80d32..9f17829da 100644 --- a/GRDB/Record/TableRecord.swift +++ b/GRDB/Record/TableRecord.swift @@ -700,7 +700,7 @@ extension TableRecord { /// Returns an error for a record that does not exist in the database. public static func recordNotFound(key: [String: (any DatabaseValueConvertible)?]) -> RecordError { - return RecordError.recordNotFound( + RecordError.recordNotFound( databaseTableName: databaseTableName, key: key.mapValues { $0?.databaseValue ?? .null }) } @@ -713,7 +713,7 @@ extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible { /// - returns: ``RecordError/recordNotFound(databaseTableName:key:)``, or /// any error that prevented the `RecordError` from being constructed. public static func recordNotFound(_ db: Database, id: Self.ID) -> any Error { - return recordNotFound(db, key: id) + recordNotFound(db, key: id) } } diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index 63dec625e..b186d43ae 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -31,9 +31,9 @@ func GRDBPrecondition( file: StaticString = #file, line: UInt = #line) { - /// Custom precondition function which aims at solving - /// and - /// + // Custom precondition function which aims at solving + // and + // if !condition() { fatalError(message(), file: file, line: line) } diff --git a/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift b/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift index e73e9a394..c81ac1bcc 100644 --- a/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift +++ b/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift @@ -18,7 +18,11 @@ import Foundation /// reducing stage. /// /// **Notify** is calling user callbacks, in case of database change or error. -final class ValueWriteOnlyObserver { +final class ValueWriteOnlyObserver< + Writer: DatabaseWriter, + Reducer: ValueReducer, + Scheduler: ValueObservationScheduler> +{ // MARK: - Configuration // // Configuration is not mutable. diff --git a/Scripts/swiftlint.yml b/Scripts/swiftlint.yml index dc8568d0c..00f9d3c47 100644 --- a/Scripts/swiftlint.yml +++ b/Scripts/swiftlint.yml @@ -6,13 +6,14 @@ disabled_rules: - cyclomatic_complexity - duplicate_enum_cases - file_length + - for_where - force_cast - force_try - - for_where - function_body_length - function_parameter_count - identifier_name - is_disjoint + - large_tuple - nesting - opening_brace - redundant_optional_initialization @@ -25,11 +26,10 @@ disabled_rules: - unused_setter_value opt_in_rules: - - anyobject_protocol - array_init - - capture_variable - closure_spacing - collection_alignment + - comma_inheritance - contains_over_filter_count - contains_over_filter_is_empty - contains_over_first_not_nil @@ -48,20 +48,29 @@ opt_in_rules: - last_where - legacy_multiple - legacy_random + - local_doc_comment - lower_acl_than_parent - modifier_order - no_extension_access_modifier + - optional_enum_case_matching - overridden_super_call - pattern_matching_keywords - prohibited_super_call - reduce_into - redundant_type_annotation + - shorthand_optional_binding - sorted_first_last - sorted_imports - toggle_bool + - unused_capture_list + - vertical_parameter_alignment_on_call + - yoda_condition + +analyzer_rules: + - capture_variable + - typesafe_array_init - unused_declaration - unused_import - - yoda_condition vertical_whitespace: max_empty_lines: 2