Skip to content

Commit 0e95fe3

Browse files
committed
Added swiftlint
1 parent 06b7b21 commit 0e95fe3

23 files changed

+279
-217
lines changed

.swiftlint.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
excluded:
2+
- Carthage
3+
opt_in_rules:
4+
- overridden_super_call
5+
- private_outlet
6+
- prohibited_super_call
7+
- first_where
8+
- closure_spacing
9+
- unneeded_parentheses_in_closure_argument
10+
- redundant_nil_coalescing
11+
- pattern_matching_keywords
12+
- explicit_init
13+
- contains_over_first_not_nil
14+
disabled_rules:
15+
- line_length
16+
- trailing_whitespace
17+
- type_name
18+
- identifier_name
19+
- vertical_whitespace
20+
- trailing_newline
21+
- opening_brace
22+
- large_tuple
23+
- file_length
24+
- comma
25+
- colon
26+
- private_over_fileprivate
27+
- force_cast
28+
- force_try
29+
- function_parameter_count
30+
- statement_position
31+
- legacy_hashing
32+
- todo
33+
- operator_whitespace
34+
- type_body_length
35+
- function_body_length
36+
- cyclomatic_complexity

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ notifications:
99
install: true
1010

1111
env:
12+
- BUILD="brew install swiftlint"
1213
- BUILD="carthage update --platform iOS && pushd Examples && set -o pipefail && (xcodebuild -project Example.xcodeproj -scheme ExampleUITests -configuration Release -destination 'platform=iOS Simulator,name=iPhone 7' test && xcodebuild -project Example.xcodeproj -scheme Example -configuration Release -destination 'platform=iOS Simulator,name=iPhone 7' build) | xcpretty"
1314
- BUILD="carthage update --platform ios && set -o pipefail && (xcodebuild -project RxDataSources.xcodeproj -scheme Tests -configuration Release -destination 'platform=iOS Simulator,name=iPhone 7' test) | xcpretty"
1415
- BUILD="gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet; pod repo update && pod lib lint RxDataSources.podspec --verbose && pod lib lint Differentiator.podspec --verbose "

Examples/Example/Example1_CustomizationUsingTableViewDelegate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension MySection : AnimatableSectionModelType {
3232
}
3333

3434
class CustomizationUsingTableViewDelegate : UIViewController {
35-
@IBOutlet var tableView: UITableView!
35+
@IBOutlet private var tableView: UITableView!
3636

3737
let disposeBag = DisposeBag()
3838

@@ -44,7 +44,7 @@ class CustomizationUsingTableViewDelegate : UIViewController {
4444
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
4545

4646
let dataSource = RxTableViewSectionedAnimatedDataSource<MySection>(
47-
configureCell: { ds, tv, ip, item in
47+
configureCell: { ds, tv, _, item in
4848
let cell = tv.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style: .default, reuseIdentifier: "Cell")
4949
cell.textLabel?.text = "Item \(item)"
5050

@@ -83,7 +83,7 @@ extension CustomizationUsingTableViewDelegate : UITableViewDelegate {
8383
// you can also fetch item
8484
guard let item = dataSource?[indexPath],
8585
// .. or section and customize what you like
86-
let _ = dataSource?[indexPath.section]
86+
dataSource?[indexPath.section] != nil
8787
else {
8888
return 0.0
8989
}

Examples/Example/Example2_RandomizedSectionsAnimation.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,27 @@ import RxCocoa
1313
import CoreLocation
1414

1515
class NumberCell : UICollectionViewCell {
16-
@IBOutlet var value: UILabel?
16+
@IBOutlet private var value: UILabel?
17+
18+
func configure(with value: String) {
19+
self.value?.text = value
20+
}
1721
}
1822

1923
class NumberSectionView : UICollectionReusableView {
20-
@IBOutlet weak var value: UILabel?
24+
@IBOutlet private weak var value: UILabel?
25+
26+
func configure(value: String) {
27+
self.value?.text = value
28+
}
2129
}
2230

2331
class PartialUpdatesViewController: UIViewController {
2432

25-
@IBOutlet weak var animatedTableView: UITableView!
26-
@IBOutlet weak var tableView: UITableView!
27-
@IBOutlet weak var animatedCollectionView: UICollectionView!
28-
@IBOutlet weak var refreshButton: UIButton!
33+
@IBOutlet private weak var animatedTableView: UITableView!
34+
@IBOutlet private weak var tableView: UITableView!
35+
@IBOutlet private weak var animatedCollectionView: UICollectionView!
36+
@IBOutlet private weak var refreshButton: UIButton!
2937

3038
let disposeBag = DisposeBag()
3139

@@ -96,12 +104,12 @@ extension PartialUpdatesViewController {
96104
TableViewSectionedDataSource<NumberSection>.TitleForHeaderInSection
97105
) {
98106
return (
99-
{ (_, tv, ip, i) in
107+
{ _, tv, ip, i in
100108
let cell = tv.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style:.default, reuseIdentifier: "Cell")
101109
cell.textLabel!.text = "\(i)"
102110
return cell
103111
},
104-
{ (ds, section) -> String? in
112+
{ ds, section -> String? in
105113
return ds[section].header
106114
}
107115
)
@@ -112,15 +120,15 @@ extension PartialUpdatesViewController {
112120
CollectionViewSectionedDataSource<NumberSection>.ConfigureSupplementaryView
113121
) {
114122
return (
115-
{ (_, cv, ip, i) in
123+
{ _, cv, ip, i in
116124
let cell = cv.dequeueReusableCell(withReuseIdentifier: "Cell", for: ip) as! NumberCell
117-
cell.value!.text = "\(i)"
125+
cell.configure(with: "\(i)")
118126
return cell
119127

120128
},
121-
{ (ds ,cv, kind, ip) in
129+
{ ds ,cv, kind, ip in
122130
let section = cv.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Section", for: ip) as! NumberSectionView
123-
section.value!.text = "\(ds[ip.section].header)"
131+
section.configure(value: "\(ds[ip.section].header)")
124132
return section
125133
}
126134
)

Examples/Example/Example3_TableViewEditing.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import RxCocoa
1414
// redux like editing example
1515
class EditingExampleViewController: UIViewController {
1616

17-
@IBOutlet weak var addButton: UIBarButtonItem!
17+
@IBOutlet private weak var addButton: UIBarButtonItem!
1818

19-
@IBOutlet weak var tableView: UITableView!
19+
@IBOutlet private weak var tableView: UITableView!
2020
let disposeBag = DisposeBag()
2121

2222
override func viewDidLoad() {
@@ -66,12 +66,12 @@ extension EditingExampleViewController {
6666
animationConfiguration: AnimationConfiguration(insertAnimation: .top,
6767
reloadAnimation: .fade,
6868
deleteAnimation: .left),
69-
configureCell: { (dataSource, table, idxPath, item) in
69+
configureCell: { _, table, idxPath, item in
7070
let cell = table.dequeueReusableCell(withIdentifier: "Cell", for: idxPath)
7171
cell.textLabel?.text = "\(item)"
7272
return cell
7373
},
74-
titleForHeaderInSection: { (ds, section) -> String? in
74+
titleForHeaderInSection: { ds, section -> String? in
7575
return ds[section].header
7676
},
7777
canEditRowAtIndexPath: { _, _ in

Examples/Example/Example4_DifferentSectionAndItemTypes.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Differentiator
1515
// the trick is to just use enum for different section types
1616
class MultipleSectionModelViewController: UIViewController {
1717

18-
@IBOutlet weak var tableView: UITableView!
18+
@IBOutlet private weak var tableView: UITableView!
1919
let disposeBag = DisposeBag()
2020

2121
override func viewDidLoad() {
@@ -41,24 +41,19 @@ class MultipleSectionModelViewController: UIViewController {
4141
extension MultipleSectionModelViewController {
4242
static func dataSource() -> RxTableViewSectionedReloadDataSource<MultipleSectionModel> {
4343
return RxTableViewSectionedReloadDataSource<MultipleSectionModel>(
44-
configureCell: { (dataSource, table, idxPath, _) in
44+
configureCell: { dataSource, table, idxPath, _ in
4545
switch dataSource[idxPath] {
4646
case let .ImageSectionItem(image, title):
4747
let cell: ImageTitleTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath)
48-
cell.titleLabel.text = title
49-
cell.cellImageView.image = image
50-
48+
cell.configure(image: image, title: title)
5149
return cell
5250
case let .StepperSectionItem(title):
5351
let cell: TitleSteperTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath)
54-
cell.titleLabel.text = title
55-
52+
cell.configure(title: title)
5653
return cell
5754
case let .ToggleableSectionItem(title, enabled):
5855
let cell: TitleSwitchTableViewCell = table.dequeueReusableCell(forIndexPath: idxPath)
59-
cell.switchControl.isOn = enabled
60-
cell.titleLabel.text = title
61-
56+
cell.configure(title: title, isEnabled: enabled)
6257
return cell
6358
}
6459
},
@@ -88,11 +83,11 @@ extension MultipleSectionModel: SectionModelType {
8883
var items: [SectionItem] {
8984
switch self {
9085
case .ImageProvidableSection(title: _, items: let items):
91-
return items.map {$0}
86+
return items.map { $0 }
9287
case .StepperableSection(title: _, items: let items):
93-
return items.map {$0}
88+
return items.map { $0 }
9489
case .ToggleableSection(title: _, items: let items):
95-
return items.map {$0}
90+
return items.map { $0 }
9691
}
9792
}
9893

Examples/Example/Example5_UIPickerView.swift

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,49 @@ import RxDataSources
1313

1414
final class ReactivePickerViewControllerExample: UIViewController {
1515

16-
@IBOutlet weak var firstPickerView: UIPickerView!
17-
@IBOutlet weak var secondPickerView: UIPickerView!
18-
@IBOutlet weak var thirdPickerView: UIPickerView!
16+
@IBOutlet private weak var firstPickerView: UIPickerView!
17+
@IBOutlet private weak var secondPickerView: UIPickerView!
18+
@IBOutlet private weak var thirdPickerView: UIPickerView!
1919

2020
let disposeBag = DisposeBag()
2121

2222
private let stringPickerAdapter = RxPickerViewStringAdapter<[String]>(components: [],
2323
numberOfComponents: { _,_,_ in 1 },
24-
numberOfRowsInComponent: { (_, _, items, _) -> Int in
24+
numberOfRowsInComponent: { _, _, items, _ -> Int in
2525
return items.count
2626
},
27-
titleForRow: { (_, _, items, row, _) -> String? in
27+
titleForRow: { _, _, items, row, _ -> String? in
2828
return items[row]
2929
})
30-
private let attributedStringPickerAdapter = RxPickerViewAttributedStringAdapter<[String]>(components: [],
31-
numberOfComponents: { _,_,_ in 1 },
32-
numberOfRowsInComponent: { (_, _, items, _) -> Int in
33-
return items.count
34-
}) { (_, _, items, row, _) -> NSAttributedString? in
35-
return NSAttributedString(string: items[row],
36-
attributes: [
37-
.foregroundColor: UIColor.purple,
38-
.underlineStyle: NSUnderlineStyle.double.rawValue,
39-
.textEffect: NSAttributedString.TextEffectStyle.letterpressStyle
40-
])
41-
}
42-
private let viewPickerAdapter = RxPickerViewViewAdapter<[String]>(components: [],
43-
numberOfComponents: { _,_,_ in 1 },
44-
numberOfRowsInComponent: { (_, _, items, _) -> Int in
45-
return items.count
46-
}) { (_, _, _, row, _, view) -> UIView in
47-
let componentView = view ?? UIView()
48-
componentView.backgroundColor = row % 2 == 0 ? UIColor.red : UIColor.blue
49-
return componentView
50-
}
30+
private let attributedStringPickerAdapter = RxPickerViewAttributedStringAdapter<[String]>(
31+
components: [],
32+
numberOfComponents: { _,_,_ in 1 },
33+
numberOfRowsInComponent: { _, _, items, _ -> Int in
34+
return items.count
35+
},
36+
attributedTitleForRow: { _, _, items, row, _ -> NSAttributedString? in
37+
NSAttributedString(
38+
string: items[row],
39+
attributes: [
40+
.foregroundColor: UIColor.purple,
41+
.underlineStyle: NSUnderlineStyle.double.rawValue,
42+
.textEffect: NSAttributedString.TextEffectStyle.letterpressStyle
43+
]
44+
)
45+
}
46+
)
47+
private let viewPickerAdapter = RxPickerViewViewAdapter<[String]>(
48+
components: [],
49+
numberOfComponents: { _,_,_ in 1 },
50+
numberOfRowsInComponent: { _, _, items, _ -> Int in
51+
return items.count
52+
},
53+
viewForRow: { _, _, _, row, _, view -> UIView in
54+
let componentView = view ?? UIView()
55+
componentView.backgroundColor = row % 2 == 0 ? UIColor.red : UIColor.blue
56+
return componentView
57+
}
58+
)
5159

5260
override func viewDidLoad() {
5361
super.viewDidLoad()

Examples/Example/Views/ImageTitleTableViewCell.swift

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

1111
class ImageTitleTableViewCell: UITableViewCell {
1212

13-
@IBOutlet weak var cellImageView: UIImageView!
14-
@IBOutlet weak var titleLabel: UILabel!
13+
@IBOutlet private weak var cellImageView: UIImageView!
14+
@IBOutlet private weak var titleLabel: UILabel!
15+
16+
func configure(image: UIImage, title: String) {
17+
cellImageView.image = image
18+
titleLabel.text = title
19+
}
1520
}

Examples/Example/Views/TitleSteperTableViewCell.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ import UIKit
1010

1111
class TitleSteperTableViewCell: UITableViewCell {
1212

13-
@IBOutlet weak var stepper: UIStepper!
14-
@IBOutlet weak var titleLabel: UILabel!
15-
override func awakeFromNib() {
16-
super.awakeFromNib()
17-
// Initialization code
18-
}
19-
20-
override func setSelected(_ selected: Bool, animated: Bool) {
21-
super.setSelected(selected, animated: animated)
13+
@IBOutlet private weak var stepper: UIStepper!
14+
@IBOutlet private weak var titleLabel: UILabel!
2215

23-
// Configure the view for the selected state
16+
func configure(title: String) {
17+
titleLabel.text = title
2418
}
2519

2620
}

0 commit comments

Comments
 (0)