Skip to content

Commit

Permalink
Fix a bunch of newly added swiftlint checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed May 20, 2024
1 parent afa2de6 commit af67f0a
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 98 deletions.
22 changes: 11 additions & 11 deletions Realm/ObjectServerTests/AsyncSyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase {
try await write { realm in
let object = SwiftCustomColumnObject()
object.id = objectId
object.binaryCol = "string".data(using: String.Encoding.utf8)!
object.binaryCol = Data("string".utf8)
let linkedObject = SwiftCustomColumnObject()
linkedObject.id = linkedObjectId
object.objectCol = linkedObject
Expand All @@ -207,7 +207,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase {
XCTAssertEqual(object.intCol, 1)
XCTAssertEqual(object.doubleCol, 1.1)
XCTAssertEqual(object.stringCol, "string")
XCTAssertEqual(object.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(object.binaryCol, Data("string".utf8))
XCTAssertEqual(object.dateCol, Date(timeIntervalSince1970: -1))
XCTAssertEqual(object.longCol, 1)
XCTAssertEqual(object.decimalCol, Decimal128(1))
Expand Down Expand Up @@ -462,7 +462,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase {
XCTAssertEqual(obj.intCol, 1)
XCTAssertEqual(obj.doubleCol, 1.1)
XCTAssertEqual(obj.stringCol, "string")
XCTAssertEqual(obj.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(obj.binaryCol, Data("string".utf8))
XCTAssertEqual(obj.decimalCol, Decimal128(1))
XCTAssertEqual(obj.dateCol, Date(timeIntervalSince1970: -1))
XCTAssertEqual(obj.longCol, Int64(1))
Expand Down Expand Up @@ -1168,7 +1168,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
"intCol": 365,
"doubleCol": 365.365,
"stringCol": "@#¢∞¬÷÷",
"binaryCol": "string".data(using: String.Encoding.utf8)!,
"binaryCol": Data("string".utf8),
"dateCol": Date(timeIntervalSince1970: -365),
"longCol": 365,
"decimalCol": Decimal128(365),
Expand All @@ -1193,7 +1193,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
XCTAssertEqual(foundObject!.intCol, 365)
XCTAssertEqual(foundObject!.doubleCol, 365.365)
XCTAssertEqual(foundObject!.stringCol, "@#¢∞¬÷÷")
XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8))
XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -365))
XCTAssertEqual(foundObject!.longCol, 365)
XCTAssertEqual(foundObject!.decimalCol, Decimal128(365))
Expand All @@ -1209,7 +1209,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
try await write { realm in
let object = SwiftCustomColumnObject()
object.id = objectId
object.binaryCol = "string".data(using: String.Encoding.utf8)!
object.binaryCol = Data("string".utf8)
let linkedObject = SwiftCustomColumnObject()
linkedObject.id = linkedObjectId
object.objectCol = linkedObject
Expand All @@ -1232,7 +1232,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
XCTAssertEqual(foundObject!.intCol, 1)
XCTAssertEqual(foundObject!.doubleCol, 1.1)
XCTAssertEqual(foundObject!.stringCol, "string")
XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8))
XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -1))
XCTAssertEqual(foundObject!.longCol, 1)
XCTAssertEqual(foundObject!.decimalCol, Decimal128(1))
Expand All @@ -1248,7 +1248,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
try await write { realm in
let object = SwiftCustomColumnObject()
object.id = objectId
object.binaryCol = "string".data(using: String.Encoding.utf8)!
object.binaryCol = Data("string".utf8)
let linkedObject = SwiftCustomColumnObject()
linkedObject.id = linkedObjectId
object.objectCol = linkedObject
Expand All @@ -1271,7 +1271,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
XCTAssertEqual(foundObject!.intCol, 1)
XCTAssertEqual(foundObject!.doubleCol, 1.1)
XCTAssertEqual(foundObject!.stringCol, "string")
XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8))
XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -1))
XCTAssertEqual(foundObject!.longCol, 1)
XCTAssertEqual(foundObject!.decimalCol, Decimal128(1))
Expand All @@ -1287,7 +1287,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
try await write { realm in
let object = SwiftCustomColumnObject()
object.id = objectId
object.binaryCol = "string".data(using: String.Encoding.utf8)!
object.binaryCol = Data("string".utf8)
let linkedObject = SwiftCustomColumnObject()
linkedObject.id = linkedObjectId
object.objectCol = linkedObject
Expand All @@ -1313,7 +1313,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
XCTAssertEqual(foundObject!.intCol, 1)
XCTAssertEqual(foundObject!.doubleCol, 1.1)
XCTAssertEqual(foundObject!.stringCol, "string")
XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8))
XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -1))
XCTAssertEqual(foundObject!.longCol, 1)
XCTAssertEqual(foundObject!.decimalCol, Decimal128(1))
Expand Down
8 changes: 5 additions & 3 deletions Realm/ObjectServerTests/RealmServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extension URLSession {
completionHandler(.success(data))
} else if let error = error {
completionHandler(.failure(error))
// swiftlint:disable:next non_optional_string_data_conversion
} else if let data = data, let string = String(data: data, encoding: .utf8) {
completionHandler(.failure(NSError(domain: URLError.errorDomain,
code: URLError.badServerResponse.rawValue,
Expand Down Expand Up @@ -654,6 +655,7 @@ public class RealmServer: NSObject {
let logLevel = self.logLevel
pipe.fileHandleForReading.readabilityHandler = { file in
guard file.availableData.count > 0,
// swiftlint:disable:next non_optional_string_data_conversion
let available = String(data: file.availableData, encoding: .utf8)?.split(separator: "\t") else {
return
}
Expand All @@ -674,9 +676,9 @@ public class RealmServer: NSObject {
} else if part.contains("ERROR") {
parts.append("🔴")
} else if let json = try? JSONSerialization.jsonObject(with: part.data(using: .utf8)!) {
parts.append(String(data: try! JSONSerialization.data(withJSONObject: json,
options: .prettyPrinted),
encoding: .utf8)!)
parts.append(String(decoding: try! JSONSerialization.data(withJSONObject: json,
options: .prettyPrinted),
as: UTF8.self))
} else if !part.isEmpty {
parts.append(String(part))
}
Expand Down
4 changes: 2 additions & 2 deletions Realm/ObjectServerTests/SwiftObjectServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase {
XCTAssertEqual(obj.intCol, 1)
XCTAssertEqual(obj.doubleCol, 1.1)
XCTAssertEqual(obj.stringCol, "string")
XCTAssertEqual(obj.binaryCol, "string".data(using: String.Encoding.utf8)!)
XCTAssertEqual(obj.binaryCol, Data("string".utf8))
XCTAssertEqual(obj.decimalCol, Decimal128(1))
XCTAssertEqual(obj.dateCol, Date(timeIntervalSince1970: -1))
XCTAssertEqual(obj.longCol, Int64(1))
Expand Down Expand Up @@ -506,7 +506,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase {
let ex = expectation(description: "async open")
ex.expectedFulfillmentCount = 2
let config = try configuration()
let completion = { (result: Result<Realm, Error>) -> Void in
let completion = { (result: Result<Realm, Error>) in
guard case .failure = result else {
XCTFail("No error on cancelled async open")
return ex.fulfill()
Expand Down
4 changes: 2 additions & 2 deletions Realm/ObjectServerTests/SwiftServerObjects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class SwiftTypesSyncObject: Object {
@Persisted public var intCol: Int = 1
@Persisted public var doubleCol: Double = 1.1
@Persisted public var stringCol: String = "string"
@Persisted public var binaryCol: Data = "string".data(using: String.Encoding.utf8)!
@Persisted public var binaryCol: Data = Data("string".utf8)
@Persisted public var dateCol: Date = Date(timeIntervalSince1970: -1)
@Persisted public var longCol: Int64 = 1
@Persisted public var decimalCol: Decimal128 = Decimal128(1)
Expand Down Expand Up @@ -208,7 +208,7 @@ public class SwiftCustomColumnObject: Object {
@Persisted public var intCol: Int = 1
@Persisted public var doubleCol: Double = 1.1
@Persisted public var stringCol: String = "string"
@Persisted public var binaryCol = "string".data(using: String.Encoding.utf8)!
@Persisted public var binaryCol = Data("string".utf8)
@Persisted public var dateCol: Date = Date(timeIntervalSince1970: -1)
@Persisted public var longCol: Int64 = 1
@Persisted public var decimalCol: Decimal128 = Decimal128(1)
Expand Down
2 changes: 1 addition & 1 deletion Realm/RLMObjectId.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (id)copyWithZone:(NSZone *)zone {
}

+ (instancetype)objectId {
return [[RLMObjectId alloc] initWithValue:realm::ObjectId::gen()];
return [[self alloc] initWithValue:realm::ObjectId::gen()];
}

- (BOOL)isEqual:(id)object {
Expand Down
6 changes: 3 additions & 3 deletions Realm/Tests/Swift/SwiftObjectInterfaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase {
func testPrimitiveArray() {
let obj = SwiftRLMPrimitiveArrayObject()
let str = "str" as NSString
let data = "str".data(using: .utf8)! as Data as NSData
let data = Data("str".utf8) as NSData
let date = NSDate()
let str2 = "str2" as NSString
let data2 = "str2".data(using: .utf8)! as Data as NSData
let data2 = Data("str2".utf8) as NSData
let date2 = NSDate(timeIntervalSince1970: 0)

obj.stringCol.add(str)
Expand Down Expand Up @@ -291,7 +291,7 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase {
func testPrimitiveSet() {
let obj = SwiftRLMPrimitiveSetObject()
let str = "str" as NSString
let data = "str".data(using: .utf8)! as Data as NSData
let data = Data("str".utf8) as NSData
let date = NSDate()
obj.stringCol.add(str)
XCTAssertTrue(obj.stringCol.contains(str))
Expand Down
2 changes: 1 addition & 1 deletion Realm/Tests/Swift/SwiftPropertyTypeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SwiftRLMPropertyTypeTest: RLMTestCase {
let realm = realmWithTestPath()
var object: SwiftRLMObjectiveCTypesObject!
let now = NSDate()
let data = "fizzbuzz".data(using: .utf8)! as Data as NSData
let data = Data("fizzbuzz".utf8) as NSData
try! realm.transaction {
object = SwiftRLMObjectiveCTypesObject()
realm.add(object)
Expand Down
4 changes: 2 additions & 2 deletions RealmSwift/AsymmetricObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ extension AsymmetricObject {
It is not considered part of the public API.
:nodoc:
*/
public override final class func _getProperties() -> [RLMProperty] {
return ObjectUtil.getSwiftProperties(self)
public override static func _getProperties() -> [RLMProperty] {
ObjectUtil.getSwiftProperties(self)
}

// MARK: Object Customization
Expand Down
8 changes: 4 additions & 4 deletions RealmSwift/EmbeddedObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import Realm.Private
public typealias EmbeddedObject = RealmSwiftEmbeddedObject
extension EmbeddedObject: _RealmCollectionValueInsideOptional {
/// :nodoc:
public class override final func isEmbedded() -> Bool {
return true
public static override func isEmbedded() -> Bool {
true
}

// MARK: Initializers
Expand Down Expand Up @@ -114,8 +114,8 @@ extension EmbeddedObject: _RealmCollectionValueInsideOptional {
It is not considered part of the public API.
:nodoc:
*/
public override final class func _getProperties() -> [RLMProperty] {
return ObjectUtil.getSwiftProperties(self)
public override static func _getProperties() -> [RLMProperty] {
ObjectUtil.getSwiftProperties(self)
}

// MARK: Object Customization
Expand Down
6 changes: 3 additions & 3 deletions RealmSwift/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public final class List<Element: RealmCollectionValue>: RLMSwiftCollectionBase,
rlmArray.exchangeObject(at: UInt(index1), withObjectAt: UInt(index2))
}

@objc class func _unmanagedCollection() -> RLMArray<AnyObject> {
@objc static func _unmanagedCollection() -> RLMArray<AnyObject> {
if let type = Element.self as? ObjectBase.Type {
return RLMArray(objectClassName: type.className())
}
Expand All @@ -222,8 +222,8 @@ public final class List<Element: RealmCollectionValue>: RLMSwiftCollectionBase,
}

/// :nodoc:
@objc public override class func _backingCollectionType() -> AnyClass {
return RLMManagedArray.self
@objc public override static func _backingCollectionType() -> AnyClass {
RLMManagedArray.self
}

// Printable requires a description property defined in Swift (and not obj-c),
Expand Down
10 changes: 5 additions & 5 deletions RealmSwift/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public final class Map<Key: _MapKey, Value: RealmCollectionValue>: RLMSwiftColle
for more information.
*/
public func freeze() -> Map {
return Map(objc: rlmDictionary.freeze())
Map(objc: rlmDictionary.freeze())
}

/**
Expand All @@ -739,10 +739,10 @@ public final class Map<Key: _MapKey, Value: RealmCollectionValue>: RLMSwiftColle
If called on a live `Map`, will return itself.
*/
public func thaw() -> Map? {
return Map(objc: rlmDictionary.thaw())
Map(objc: rlmDictionary.thaw())
}

@objc class func _unmanagedCollection() -> RLMDictionary<AnyObject, AnyObject> {
@objc static func _unmanagedCollection() -> RLMDictionary<AnyObject, AnyObject> {
if let type = Value.self as? HasClassName.Type ?? Value.PersistedType.self as? HasClassName.Type {
return RLMDictionary(objectClassName: type.className(), keyType: Key._rlmType)
}
Expand All @@ -753,8 +753,8 @@ public final class Map<Key: _MapKey, Value: RealmCollectionValue>: RLMSwiftColle
}

/// :nodoc:
@objc public override class func _backingCollectionType() -> AnyClass {
return RLMManagedDictionary.self
@objc public override static func _backingCollectionType() -> AnyClass {
RLMManagedDictionary.self
}

/**
Expand Down
6 changes: 3 additions & 3 deletions RealmSwift/MutableSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public final class MutableSet<Element: RealmCollectionValue>: RLMSwiftCollection
rlmSet.union(other.rlmSet)
}

@objc class func _unmanagedCollection() -> RLMSet<AnyObject> {
@objc static func _unmanagedCollection() -> RLMSet<AnyObject> {
if let type = Element.self as? ObjectBase.Type {
return RLMSet(objectClassName: type.className())
}
Expand All @@ -197,8 +197,8 @@ public final class MutableSet<Element: RealmCollectionValue>: RLMSwiftCollection
}

/// :nodoc:
@objc public override class func _backingCollectionType() -> AnyClass {
return RLMManagedSet.self
@objc public override static func _backingCollectionType() -> AnyClass {
RLMManagedSet.self
}

// Printable requires a description property defined in Swift (and not obj-c),
Expand Down
12 changes: 6 additions & 6 deletions RealmSwift/Object.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ extension Object: _RealmCollectionValueInsideOptional {
It is not considered part of the public API.
:nodoc:
*/
public override final class func _getProperties() -> [RLMProperty] {
return ObjectUtil.getSwiftProperties(self)
public override static func _getProperties() -> [RLMProperty] {
ObjectUtil.getSwiftProperties(self)
}

// MARK: Object Customization
Expand Down Expand Up @@ -713,7 +713,7 @@ public final class DynamicObject: Object {

/// :nodoc:
public override func value(forUndefinedKey key: String) -> Any? {
return self[key]
self[key]
}

/// :nodoc:
Expand All @@ -722,11 +722,11 @@ public final class DynamicObject: Object {
}

/// :nodoc:
public override class func shouldIncludeInDefaultSchema() -> Bool {
return false
public override static func shouldIncludeInDefaultSchema() -> Bool {
false
}

override public class func sharedSchema() -> RLMObjectSchema? {
override public static func sharedSchema() -> RLMObjectSchema? {
nil
}

Expand Down
6 changes: 4 additions & 2 deletions RealmSwift/ObjectId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public final class ObjectId: RLMObjectId, Decodable, @unchecked Sendable {
super.init()
}

// swiftlint:disable unneeded_override
/// Creates a new randomly-initialized ObjectId.
public override class func generate() -> ObjectId {
return unsafeDowncast(super.generate(), to: ObjectId.self)
public override static func generate() -> ObjectId {
super.generate()
}
// swiftlint:enable unneeded_override

/// Creates a new ObjectId from the given 24-byte hexadecimal string.
///
Expand Down
Loading

0 comments on commit af67f0a

Please sign in to comment.