Skip to content

Commit

Permalink
Add SwiftLint support
Browse files Browse the repository at this point in the history
- adjust code/silence warnings where needed
  • Loading branch information
siemensikkema committed Jan 15, 2017
1 parent e30dc47 commit e9906f8
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 17 deletions.
15 changes: 15 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
included:
- Sources
- Tests
excluded:
- Sources/Misc/Then.swift
opt_in_rules:
- file_header
line_length: 100
file_header:
required_pattern: |
variable_name:
excluded:
- at
type_name:
min_length: 1
2 changes: 1 addition & 1 deletion Sources/Core Data/Managed object context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension NSManagedObjectContext: ManagedObjectContextProtocol {
return object
}

public func performChanges(_ block: @escaping (NSManagedObjectContext) -> ()) {
public func performChanges(_ block: @escaping (NSManagedObjectContext) -> Void) {
perform {
block(self)
_ = self.saveOrRollback()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core Data/Managed object.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public extension ManagedObjectProtocol {
static func materializedObject(in managedObjectContext: ManagedObjectContextProtocol,
matching predicate: NSPredicate) -> Self? {
for object in managedObjectContext.registeredObjects where !object.isFault {
guard let result = object as? Self , predicate.evaluate(with: result) else {
guard let result = object as? Self, predicate.evaluate(with: result) else {
continue
}
return result
Expand Down Expand Up @@ -82,7 +82,7 @@ public extension NSManagedObject {

func save(inContext context: NSManagedObjectContext? = nil) {
(context ?? managedObjectContext)?.performChanges {
try! $0.save()
try! $0.save() // swiftlint:disable:this force_try
}
}
}
9 changes: 6 additions & 3 deletions Sources/Data source/Fetched results data source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ public class FetchedResultsDataSource<Model: NSFetchRequestResult, Item> {
fetchedResultsControllerDelegate = FetchedResultsControllerDelegate(
tableUpdater: tableUpdater)
fetchedResultsController.delegate = fetchedResultsControllerDelegate
try! fetchedResultsController.performFetch()
do {
try fetchedResultsController.performFetch()
} catch {
fatalError("Fetch request lacks a sort descriptor that uses sectionNameKeyPath")
}

self.tableUpdater = tableUpdater
self.transform = transform
}

fileprivate let fetchedResultsController: NSFetchedResultsController<Model>
fileprivate let transform: (Model) -> Item
// swiftlint:disable:next weak_delegate
private let fetchedResultsControllerDelegate: FetchedResultsControllerDelegate<Model>
private let tableUpdater: TableUpdatable
}

extension FetchedResultsDataSource: DataSourceProtocol {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Data source/Supplementary view providing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public struct SupplementaryViewProvider<F: UICollectionReusableView, H: UICollec
withTitle title: String?) {
switch kind {
case UICollectionElementKindSectionFooter:
var footer = supplementaryView as! F
var footer = supplementaryView as! F // swiftlint:disable:this force_cast
footer.viewModel = title
case UICollectionElementKindSectionHeader:
var header = supplementaryView as! H
var header = supplementaryView as! H // swiftlint:disable:this force_cast
header.viewModel = title
default:
fatalError("Unsupported supplementary view kind: \(kind)")
Expand Down
1 change: 1 addition & 0 deletions Sources/Data source/TableChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public func == (left: TableChange, right: TableChange) -> Bool {

extension TableChange: Comparable {}

// swiftlint:disable cyclomatic_complexity function_body_length
public func < (left: TableChange, right: TableChange) -> Bool {
switch (left, right) {

Expand Down
6 changes: 3 additions & 3 deletions Sources/UI/Closure support.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extension ClosureSupport where Self: UIBarButtonItem {
extension UIControl: ClosureSupport {}
extension ClosureSupport where Self: UIControl {

// TODO: support adding multiple actions
public func setAction(for controlEvents: UIControlEvents = .touchUpInside, callback: @escaping (Self) -> Void) {
public func setAction(for controlEvents: UIControlEvents = .touchUpInside,
callback: @escaping (Self) -> Void) {
let target = Target(callback: callback)
objc_setAssociatedObject(self, &associationKey, target, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
addTarget(target, action: #selector(Target.action), for: controlEvents)
Expand All @@ -36,7 +36,7 @@ private final class Target<T: NSObject> {
}

@objc func action(object: NSObject) {
bridgingAction(control: object as! T)
bridgingAction(control: object as! T) // swiftlint:disable:this force_cast
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/UI/Post init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ open class CollectionReusableView: UICollectionReusableView {
super.init(frame: frame)
postInit()
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
postInit()
Expand All @@ -38,7 +38,7 @@ open class TableViewCell: UITableViewCell {
super.init(coder: aDecoder)
postInit()
}

open func postInit() {}
}

Expand Down
1 change: 0 additions & 1 deletion Sources/UI/Refresh control.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UIKit

extension UIScrollView {

public func onRefresh(_ action: @escaping (UIRefreshControl) -> Void) {
refreshControl = UIRefreshControl().then {
$0.setAction(for: .valueChanged, callback: action)
Expand Down
24 changes: 21 additions & 3 deletions UnclutterKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

/* Begin PBXFileReference section */
5F20B8721DCB3D3500E302DB /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
5F2A74021D38284600F795AC /* UnclutterKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UnclutterKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5F2A74021D38284600F795AC /* .framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = .framework; sourceTree = BUILT_PRODUCTS_DIR; };
5F2A74061D38284600F795AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5F2A74111D382A4600F795AC /* .xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = .xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5F2A74151D382A4600F795AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -138,7 +138,7 @@
5F2A74031D38284600F795AC /* Products */ = {
isa = PBXGroup;
children = (
5F2A74021D38284600F795AC /* UnclutterKit.framework */,
5F2A74021D38284600F795AC /* .framework */,
5F2A74111D382A4600F795AC /* .xctest */,
);
name = Products;
Expand Down Expand Up @@ -354,14 +354,15 @@
5F2A73FE1D38284600F795AC /* Frameworks */,
5F2A73FF1D38284600F795AC /* Headers */,
5F2A74001D38284600F795AC /* Resources */,
5F3626EF1E2AC6EB004ECD28 /* SwiftLint */,
);
buildRules = (
);
dependencies = (
);
name = UnclutterKit;
productName = UnclutterKit;
productReference = 5F2A74021D38284600F795AC /* UnclutterKit.framework */;
productReference = 5F2A74021D38284600F795AC /* .framework */;
productType = "com.apple.product-type.framework";
};
5F2A74101D382A4600F795AC /* UnclutterKitTests */ = {
Expand Down Expand Up @@ -442,6 +443,23 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
5F3626EF1E2AC6EB004ECD28 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
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";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
5F2A73FD1D38284600F795AC /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "F573EA13BBB55DF91C193F916841714DE61091A3",
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {

},
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"F573EA13BBB55DF91C193F916841714DE61091A3" : 9223372036854775807,
"E084C86B03F81D63323C9E7510697EA528A758C7" : 9223372036854775807
},
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "B7CDF03E-A893-4480-A44E-8A33D3B3E9C4",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"F573EA13BBB55DF91C193F916841714DE61091A3" : "UnclutterKit\/",
"E084C86B03F81D63323C9E7510697EA528A758C7" : "UnclutterKit\/Config\/xcconfigs\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "UnclutterKit",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "UnclutterKit.xcodeproj",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/jspahrsummers\/xcconfigs",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "E084C86B03F81D63323C9E7510697EA528A758C7"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/siemensikkema\/UnclutterKit.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "F573EA13BBB55DF91C193F916841714DE61091A3"
}
]
}

0 comments on commit e9906f8

Please sign in to comment.