Skip to content

Commit 663c0f4

Browse files
committed
Updates code to match new SwiftLint requirements
Changes include: 1. Relax identifier_name warning criteria - Many functions in this pod use the ip_functionName naming scheme, so we should allow underscores. - Many library functions use r, g, b, x, y as identifiers. Permit it. - Finally, there are enough existing two character identifiers that we should simply allow them. 2. Cleanup remaining identifier_name warnings 3. Replace class with AnyObject in protocols 4. Fix method access levels 5. Disable several warnings locally (in-file), including: - function_default_parameter_at_end - type_name - static_operator - nslocalizedstring_key Some public methods violate these rules. We're not going to change the public API for those, so deactivate those warnings at specific sites. 6. Mark unavailable methods as such 7. Replace arc4random_uniform with random In Swift 4.2, arc4random_uniform(:) is replaced by Int.random(in:) When rewriting our random(inRange:) function to account for that, I realized that random(inRange:) is IDENTICAL to Int.random(in:). So I deprecated random(inRange:) in favor of Int.random(in:)
1 parent c8ce09e commit 663c0f4

File tree

17 files changed

+43
-17
lines changed

17 files changed

+43
-17
lines changed

.swiftlint.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,16 @@ file_length:
198198
error: 1500
199199

200200
identifier_name:
201+
allowed_symbols: "_"
202+
min_length: 2
201203
excluded:
202204
- id
205+
- r
206+
- g
207+
- b
208+
- a
209+
- x
210+
- y
203211

204212
lower_acl_than_parent:
205213
severity: error

SwiftWisdom/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
1717
// Override point for customization after application launch.
1818
return true
1919
}

SwiftWisdom/Core/Async/Qu/Qu.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public typealias CompletableBlock = (@escaping Block) -> ()
1616

1717
// MARK: Qu
1818

19+
//swiftlint:disable type_name
1920
public class Qu {
21+
//swiftlint:enable type_name
2022

2123
// MARK: Priority Enumeration
2224

SwiftWisdom/Core/CommonTypes/Multicast.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct Weak<T> where T: AnyObject {
2525
Only subclasses of NSObject can conform to this protocol. In addition, you can only typealias `MulticastDelegate` to a
2626
class or an `@objc` protocol.
2727
*/
28-
public protocol Multicast: class {
28+
public protocol Multicast: AnyObject {
2929

3030
associatedtype MulticastDelegate: AnyObject
3131

SwiftWisdom/Core/Controls/VideoPlayer.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extension Video {
6969

7070
// MARK: Player
7171

72-
public protocol VideoPlayerDelegate: class {
72+
public protocol VideoPlayerDelegate: AnyObject {
7373
/**
7474
The delegate is notified when the video finishes playing and returns
7575
a boolean whether or not the video should repeat
@@ -109,6 +109,7 @@ public final class VideoPlayer: UIViewController {
109109
setupItemNotification(item)
110110
}
111111

112+
@available(*, unavailable)
112113
public required init?(coder aDecoder: NSCoder) {
113114
fatalError("init(coder:) has not been implemented")
114115
}

SwiftWisdom/Core/DirectoryManager/DirectoryManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public final class DirectoryManager {
5959
return ((try? data.write(to: URL(fileURLWithPath: path), options: [.atomicWrite])) != nil)
6060
}
6161

62+
//swiftlint:disable function_default_parameter_at_end
6263
public func writeInBackground(_ data: Data, withName name: String = UUID().uuidString, completion: @escaping (String, Bool) -> Void = { _, _ in }) {
6364
Background {
6465
let success = self.write(data, withName: name)
@@ -67,6 +68,7 @@ public final class DirectoryManager {
6768
}
6869
}
6970
}
71+
//swiftlint:enable function_default_parameter_at_end
7072

7173
// MARK: Delete
7274

SwiftWisdom/Core/Foundation/Data/Data+Extensions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ extension Data {
141141
}
142142

143143
extension Data {
144+
//swiftlint:disable function_default_parameter_at_end
144145
public func ip_segmentIterator(start: Int = 0, chunkLength: Int) -> AnyIterator<Data> {
145146
var iteratedData = ip_suffix(from: start)
146147
return AnyIterator {
@@ -157,4 +158,5 @@ extension Data {
157158
return nextData
158159
}
159160
}
161+
//swiftlint:enable function_default_parameter_at_end
160162
}

SwiftWisdom/Core/Foundation/Not.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
let newNames = ["Joe", "Betty"].filter(!existingNames.contains)
1313
*/
14+
15+
//swiftlint:disable static_operator
1416
public prefix func ! <T>(original: @escaping (T) -> Bool) -> (T) -> Bool {
1517
return { !original($0) }
1618
}
19+
//swiftlint:enable static_operator

SwiftWisdom/Core/StandardLibrary/Array/Sequence+Utilities.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extension Sequence where Iterator.Element: Equatable {
7979
///
8080
/// - returns: `true` if the sequence contains `all`
8181
public func ip_contains<T: Sequence>(all: T) -> Bool where T.Iterator.Element == Iterator.Element {
82-
for e in all where !contains(e) {
82+
for element in all where !contains(element) {
8383
return false
8484
}
8585
return true

SwiftWisdom/Core/StandardLibrary/Numbers/UnsignedInteger+Extensions.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ import Foundation
1111
extension UnsignedInteger {
1212
public static func ip_random() -> Self {
1313
let intMax = Int(Int64(ip_maxValue))
14-
let rand = random(inRange: 0...intMax)
14+
let rand = Int.random(in: 0...intMax)
1515
return self.init(ip_safely: rand)
1616
}
1717
}
1818

19-
// TODO: evaluate whether we should move random to be a member of CountableClosedRange
19+
@available(*, deprecated, message: "Use Int.random(in:) instead", renamed: "Int.random(in:)")
2020
public func random(inRange range: CountableClosedRange<Int>) -> Int {
21-
let diff = range.upperBound - range.lowerBound
22-
let randomOffset = Int(arc4random_uniform(UInt32(diff + 1)))
23-
let random = range.lowerBound + randomOffset
24-
return random
21+
return Int.random(in: range)
2522
}
2623

2724
// TODO: write tests for this extension

SwiftWisdom/Core/StandardLibrary/String/String+Data.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ extension String {
1717

1818
var data = Data(capacity: trimmed.count / 2)
1919

20-
for i in stride(from: 0, through: trimmed.count - 2, by: 2) {
21-
let byteString = trimmed[i...i + 1]
20+
for step in stride(from: 0, through: trimmed.count - 2, by: 2) {
21+
let byteString = trimmed[step...step + 1]
2222
var byte = UInt8(byteString.ip_hexInt)
2323
data.append(&byte, count: MemoryLayout<UInt8>.size)
2424
}

SwiftWisdom/Core/StandardLibrary/String/String+Localization.swift

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

33
extension String {
44
public func ip_localized(_ args: [CVarArg] = [], comment: String = "") -> String {
5+
//swiftlint:disable nslocalizedstring_key
56
let localizedFormat = NSLocalizedString(self, comment: comment)
7+
//swiftlint:enable nslocalizedstring_key
68
return String(format: localizedFormat, arguments: args)
79
}
810
}

SwiftWisdom/Core/UIKit/CoreAnimation/BasicVerticalGradientLayer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class BasicVerticalGradientLayer: CAGradientLayer {
1818
colors = [topColor.cgColor, bottomColor.cgColor]
1919
}
2020

21+
@available(*, unavailable)
2122
required public init(coder aDecoder: NSCoder) {
2223
fatalError("init(coder:) has not been implemented")
2324
}

SwiftWisdom/Core/UIKit/PercentAnimator/PercentAnimator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private final class PercentAnimator {
5252

5353
private static let shared = PercentAnimator()
5454

55-
static func animateWithDuration(
55+
fileprivate static func animateWithDuration(
5656
_ duration: TimeInterval,
5757
animation: @escaping (AnimationState) -> Void) {
5858
let id = UUID().uuidString

SwiftWisdom/Core/UIKit/UIButton+AttributedTitle.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import UIKit
1010

1111
public extension UIButton {
1212

13+
//swiftlint:disable function_default_parameter_at_end
1314
/**
1415
This will use existing attributes on the attributed text, plus the spacing passed in and apply
1516
them to the string passed in.
@@ -30,4 +31,5 @@ public extension UIButton {
3031
}
3132
setAttributedTitle(spacedText, for: state)
3233
}
34+
//swiftlint:enable function_default_parameter_at_end
3335
}

SwiftWisdom/Core/UIKit/UIView+Nib.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ public extension UIView {
1313
return ip_fromNib(nibNameOrNil, type: self)
1414
}
1515

16+
//swiftlint:disable function_default_parameter_at_end
1617
class func ip_fromNib<T: UIView>(_ nibNameOrNil: String? = nil, type: T.Type) -> T {
17-
let v: T? = ip_fromNib(nibNameOrNil, type: T.self)
18-
return v!
18+
let view: T? = ip_fromNib(nibNameOrNil, type: T.self)
19+
return view!
1920
}
21+
//swiftlint:enable function_default_parameter_at_end
2022

23+
//swiftlint:disable function_default_parameter_at_end
2124
class func ip_fromNib<T: UIView>(_ nibNameOrNil: String? = nil, type: T.Type) -> T? {
2225
var view: T?
2326
let name: String
@@ -28,13 +31,14 @@ public extension UIView {
2831
name = ip_nibName
2932
}
3033
let nibViews = Bundle.main.loadNibNamed(name, owner: nil, options: nil)
31-
for v in nibViews ?? [] {
32-
if let tog = v as? T {
34+
for thisView in nibViews ?? [] {
35+
if let tog = thisView as? T {
3336
view = tog
3437
}
3538
}
3639
return view
3740
}
41+
//swiftlint:enable function_default_parameter_at_end
3842

3943
class var ip_nibName: String {
4044
let name = "\(self)".components(separatedBy: ".").first ?? ""

SwiftWisdom/Rx/Rx+Extensions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import RxSwift
1010
import RxCocoa
1111

12+
//swiftlint:disable static_operator
13+
1214
precedencegroup Binding {
1315
associativity: left
1416
higherThan: Disposing

0 commit comments

Comments
 (0)