Skip to content

Commit

Permalink
Adds swiftlint to Form and fixes warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasil Nunev committed Oct 31, 2018
1 parent fcf2aac commit bbad7f0
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 35 deletions.
27 changes: 27 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
disabled_rules:
- file_length
- line_length
- function_body_length

- nesting
- cyclomatic_complexity
- todo

- force_try
- force_cast
- void_return
- trailing_comma
- shorthand_operator

included:
- Form
- FormTests
- Examples

identifier_name:
excluded: [id, i, vc, at, to, l, r, j,
shouldRecognizeSimultaneouslyWithOtherGestureRecognizer,
shouldRequireFailureOtherGestureRecognizer,
shouldBeRequiredToFailByOtherGestureRecognizer,
didEndDisplayingSupplementaryViewCallbacker]
severity: warning
1 change: 0 additions & 1 deletion Examples/Demo/Example/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,3 @@ let testMessages: [Message] = {
let decoder = JSONDecoder()
return try! decoder.decode([Message].self, from: messagesJSON.data(using: .utf8)!)
}()

18 changes: 18 additions & 0 deletions Form.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
F6A9D5D91C1728BA009A0EEB /* Sources */,
F6A9D5DB1C1728BA009A0EEB /* Headers */,
F6A9D5DC1C1728BA009A0EEB /* Resources */,
ED7163CF2189C1A0008AD729 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -544,6 +545,23 @@
shellPath = /bin/sh;
shellScript = "/usr/local/bin/carthage copy-frameworks";
};
ED7163CF2189C1A0008AD729 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
2 changes: 1 addition & 1 deletion Form/ButtonStateStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public extension ButtonStateStyle {
}

extension UIControlState: Equatable {
public static func ==(lhs: UIControlState, rhs: UIControlState) -> Bool {
public static func == (lhs: UIControlState, rhs: UIControlState) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
Expand Down
4 changes: 2 additions & 2 deletions Form/Collection+Changes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ extension Collection where Index == Int {
}

var i = 1
while (i < newEntries.count - 1) {
while i < newEntries.count - 1 {
if case .index(let j) = newEntries[i], j + 1 < oldEntries.count {
if case .symbol(let newEntry) = newEntries[i + 1],
case .symbol(let oldEntry) = oldEntries[j + 1],
Expand All @@ -167,7 +167,7 @@ extension Collection where Index == Int {
}

i = newEntries.count - 1
while (i > 0) {
while i > 0 {
if case .index(let j) = newEntries[i], j - 1 >= 0 {
if case .symbol(let newEntry) = newEntries[i - 1],
case .symbol(let oldEntry) = oldEntries[j - 1],
Expand Down
8 changes: 4 additions & 4 deletions Form/CollectionKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ extension CollectionKit: TableAnimatable {
/// - rowNeedsUpdate: Optional closure indicating whether two rows with equal identifiers have any updates.
/// Defaults to true. If provided, unnecessary reconfigure calls to visible rows could be avoided.
public func set<SectionIdentifier: Hashable, RowIdentifier: Hashable>(_ table: Table,
animation: CollectionAnimation = CollectionKit.defaultAnimation,
sectionIdentifier: (Section) -> SectionIdentifier,
rowIdentifier: (Row) -> RowIdentifier,
rowNeedsUpdate: ((Row, Row) -> Bool)?) {
animation: CollectionAnimation = CollectionKit.defaultAnimation,
sectionIdentifier: (Section) -> SectionIdentifier,
rowIdentifier: (Row) -> RowIdentifier,
rowNeedsUpdate: ((Row, Row) -> Bool)?) {
let from = self.table
dataSource.table = table
delegate.table = table
Expand Down
4 changes: 2 additions & 2 deletions Form/Constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ public func deactivate(_ constraints: NSLayoutConstraint...) {
deactivate(constraints)
}

public func -(lhs: UILayoutPriority, rhs: Float) -> UILayoutPriority {
public func - (lhs: UILayoutPriority, rhs: Float) -> UILayoutPriority {
return UILayoutPriority(rawValue: lhs.rawValue - rhs)
}

public func -= (lhs: inout UILayoutPriority, rhs: Float) {
lhs = lhs-rhs
}

public func +(lhs: UILayoutPriority, rhs: Float) -> UILayoutPriority {
public func + (lhs: UILayoutPriority, rhs: Float) -> UILayoutPriority {
return UILayoutPriority(rawValue: lhs.rawValue + rhs)
}

Expand Down
2 changes: 1 addition & 1 deletion Form/KeyboardEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private extension UIViewAnimationCurve {
}

private typealias ViewOrderedValue = (view: UIView, prio: Int)
private func <(_ lhs: ViewOrderedValue, _ rhs: ViewOrderedValue) -> Bool {
private func < (_ lhs: ViewOrderedValue, _ rhs: ViewOrderedValue) -> Bool {
if lhs.view == rhs.view {
return lhs.prio > rhs.prio
}
Expand Down
8 changes: 4 additions & 4 deletions Form/NumberEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private extension NumberFormatter {

private extension NumberFormatter {
func value(forFormattedValue value: NSDecimalNumber) -> NSDecimalNumber {
switch (numberStyle) {
switch numberStyle {
case .percent:
return value.multiplying(byPowerOf10: -2)
default:
Expand All @@ -274,7 +274,7 @@ private extension NumberFormatter {
}

func formattedValue(for value: NSDecimalNumber) -> NSDecimalNumber {
switch (numberStyle) {
switch numberStyle {
case .percent:
return value.multiplying(byPowerOf10: 2)
default:
Expand All @@ -298,10 +298,10 @@ extension NSCopying where Self: NSObject {
}
}

func <(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
func < (lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .orderedAscending
}

func >(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
func > (lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .orderedDescending
}
2 changes: 1 addition & 1 deletion Form/Reusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public protocol Reusable {
public extension Reusable {
static func makeAndConfigure() -> (make: ReuseType, configure: (Self) -> Disposable) {
let (resuseType, reconfigure) = makeAndReconfigure()
var prevValue: Self? = nil
var prevValue: Self?
return (resuseType, {
let bag = reconfigure(prevValue, $0)
prevValue = $0
Expand Down
2 changes: 1 addition & 1 deletion Form/SelectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class SelectView: UIView, Selectable, Highlightable {
super.didMoveToWindow()
bag.dispose()
if window != nil { // in didMoveToWindow to break any retain cycles when the view is removed
bag += Flow.combineLatest(isSelectedSignal.atOnce(), isHighlightedSignal.atOnce()).onValue { [weak self] (_, isHighlighted: Bool) in
bag += Flow.combineLatest(isSelectedSignal.atOnce(), isHighlightedSignal.atOnce()).onValue { [weak self] _, _ in
self?.updateCurrentState()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Form/Selectable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public extension Collection where Iterator.Element == ReadWriteSignal<Bool> {
}
}
for isSelected in self {
bag += isSelected.distinct().onValue { selected in
bag += isSelected.distinct().onValue { _ in
enforceOneSelection(fromSelection: isSelected)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Form/Table.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public extension Table {
init<S: Sequence>(rows: S, sectionValue: (Row) -> Section?) where S.Iterator.Element == Row {
let rows = Array(rows)

var prev: Section? = nil
var prev: Section?
var sectionStart = 0
var sections = [(Section, Range<Int>)]()
for (index, row) in rows.enumerated() {
Expand Down Expand Up @@ -110,7 +110,7 @@ public extension Table where Section: Equatable {
///
/// Table(rows: 0..<100) { row in "\(row/5)" }
init<S: Sequence>(rows: S, sectionValue: (Row) -> Section) where S.Iterator.Element == Row {
var prev: Section? = nil
var prev: Section?
self.init(rows: rows) { row -> Section? in
let section = sectionValue(row)
guard section != prev else { return nil }
Expand Down Expand Up @@ -237,11 +237,11 @@ public struct TableIndex {
}

extension TableIndex: Comparable {
public static func ==(lhs: TableIndex, rhs: TableIndex) -> Bool {
public static func == (lhs: TableIndex, rhs: TableIndex) -> Bool {
return lhs.section == rhs.section && lhs.row == rhs.row
}

public static func <(lhs: TableIndex, rhs: TableIndex) -> Bool {
public static func < (lhs: TableIndex, rhs: TableIndex) -> Bool {
return lhs.section == rhs.section ? lhs.row < rhs.row : lhs.section < rhs.section
}

Expand Down
2 changes: 1 addition & 1 deletion Form/TableKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class TableKit<Section, Row> {
let bag = DisposeBag()
guard let `self` = self else { return bag }

var currentView: UIView? = nil
var currentView: UIView?
bag += self.atOnce().onValue { table in
if let prevView = currentView {
currentView = nil
Expand Down
2 changes: 1 addition & 1 deletion Form/TableViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public extension TableViewDelegate {
func installAction(title: DisplayableString, style: UITableViewRowActionStyle = .normal, backgroundColor: UIColor? = nil, isVisibleAt: @escaping (TableIndex) -> Bool = { _ in true }) -> Signal<TableIndex> {
return Signal { callback in
let callbacker = Callbacker<TableIndex>()
let action = UITableViewRowAction(title: title, style: style, handler: { (action, indexPath) in
let action = UITableViewRowAction(title: title, style: style, handler: { (_, indexPath) in
guard let tableIndex = TableIndex(indexPath, in: self.table) else { return }
callbacker.callAll(with: tableIndex)
})
Expand Down
2 changes: 1 addition & 1 deletion Form/TextStyle+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private extension NSAttributedString {
func map(_ transform: (String) -> String) -> NSAttributedString {
let result = NSMutableAttributedString()

self.enumerateAttributes(in: NSMakeRange(0, self.string.count), options: []) { attributes, range, _ in
self.enumerateAttributes(in: NSRange(location: 0, length: self.string.count), options: []) { attributes, range, _ in
let substring = (self.string as NSString).substring(with: range)
result.append(NSAttributedString(string: transform(substring), attributes: attributes))
}
Expand Down
2 changes: 1 addition & 1 deletion Form/TextStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public extension TextStyle {
}

extension TextStyle: Equatable {
public static func ==(lhs: TextStyle, rhs: TextStyle) -> Bool {
public static func == (lhs: TextStyle, rhs: TextStyle) -> Bool {
// fast-path
guard lhs.changeIndex != rhs.changeIndex else {
return true
Expand Down
3 changes: 0 additions & 3 deletions Form/UICollectionViewCell+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public extension UICollectionView {
return cell
}


/// Dequeues (reuses) or creates a new view and using the `item`'s conformance to `Reusable` to create and configure the view to embed in the returned cell.
func dequeueCell<Item: Reusable>(forItem item: Item, at indexPath: IndexPath) -> UICollectionViewCell where Item.ReuseType: ViewRepresentable {
return dequeueCell(forItem: item, at: indexPath, reuseIdentifier: item.reuseIdentifier, contentViewAndConfigure: {
Expand Down Expand Up @@ -98,7 +97,6 @@ public extension UICollectionView {
return supplementaryView
}


/// Dequeues (reuses) or creates a new view and using the `item`'s conformance to `Reusable` to create and configure the view to embed in the returned cell.
func dequeueSupplementaryView<Item: Reusable>(forItem item: Item, kind: String = String(describing: Item.self), at indexPath: IndexPath) -> UICollectionReusableView where Item.ReuseType: ViewRepresentable {
return dequeueSupplementaryView(forItem: item, at: indexPath, kind: kind, reuseIdentifier: item.reuseIdentifier, contentViewAndConfigure: {
Expand Down Expand Up @@ -144,7 +142,6 @@ private extension UICollectionReusableView {
}
private var collectionConfigureKey = false


private extension UICollectionReusableView {
func setItem<Item>(_ item: Item, contentViewAndReconfigure: () -> (UIView, (Item?, Item) -> Disposable)) {
if let (reconfigure, bag) = reconfigureAndBag(Item.self) {
Expand Down
4 changes: 2 additions & 2 deletions Form/UIEdgeInsets+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public extension UIEdgeInsets {
}

/// Returns a new edge insets with components set as the sum of `lhs` and `rhs` components, respectively.
public func +(lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> UIEdgeInsets {
public func + (lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> UIEdgeInsets {
return UIEdgeInsets(top: lhs.top + rhs.top, left: lhs.left + rhs.left, bottom: lhs.bottom + rhs.bottom, right: lhs.right + rhs.right)
}

/// Returns a new edge insets with components set as the difference of `lhs` and `rhs` components, respectively.
public func -(lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> UIEdgeInsets {
public func - (lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> UIEdgeInsets {
return UIEdgeInsets(top: lhs.top - rhs.top, left: lhs.left - rhs.left, bottom: lhs.bottom - rhs.bottom, right: lhs.right - rhs.right)
}
2 changes: 1 addition & 1 deletion Form/UIResponders+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public func chainResponders(_ controls: [UIControl], shouldLoop: Bool = false, r

let shouldLoop = shouldLoop && controls.count > 1

var previousControl: UIControl? = nil
var previousControl: UIControl?
for control in controls {
bag += previousControl?.setNextResponder(control)
previousControl = control
Expand Down
2 changes: 1 addition & 1 deletion Form/ValueField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public final class ValueField<Value>: UIControl, UIKeyInput {
get { return .no }
set { /* ignore */ }
}

public dynamic var keyboardType: UIKeyboardType = .default

public override var intrinsicContentSize: CGSize {
Expand Down
1 change: 0 additions & 1 deletion FormTests/NumberEditorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class DecimalEditorTests: XCTestCase {
formatter.maximumFractionDigits = 3
let editor = NumberEditor(formatter: formatter)


test(editor, "-.", "-0.", 0, 0)
test(editor, ".-", "-0.", 0, 0)
test(editor, "-.<", "-0", 0, 0)
Expand Down
1 change: 0 additions & 1 deletion FormTests/TableChangeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import XCTest
import Form
import Flow

// swiftlint:disable identifier_name
class TableChangeTests: XCTestCase {
var window: UIWindow!
let bag = DisposeBag()
Expand Down

0 comments on commit bbad7f0

Please sign in to comment.