Skip to content

Commit

Permalink
Revise documentation
Browse files Browse the repository at this point in the history
Add SwiftLint
  • Loading branch information
huri000 committed Nov 24, 2018
1 parent 7cdf513 commit 2368176
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 69 deletions.
73 changes: 73 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
disabled_rules:
- trailing_whitespace # A little trust here ;-)
- force_cast # Enable force cast - (UITableViewCell casting is necessary sometimes)

opt_in_rules:
- empty_count # Prefer checking isEmpty over comparing count to zero.
- closure_spacing # Closure expressions should have a single space inside each brace.
- private_outlet # IBOutlets should be private to avoid leaking UIKit to higher layers.
- private_action # IBActions should be private.
- conditional_returns_on_newline # Conditional statements should always return on the next line
- operator_usage_whitespace # Operators should be surrounded by a single whitespace when they are being used.
- prefixed_toplevel_constant # Top-level constants should be prefixed by k
- lower_acl_than_parent # Ensure definitions have a lower access control level than their enclosing parent
- let_var_whitespace # Let and var should be separated from other statements by a blank line.
- literal_expression_end_indentation # Array and dictionary literal end should have the same indentation as the line that started it.
- function_default_parameter_at_end # Prefer to locate parameters with defaults toward the end of the parameter list.
- fatal_error_message # A fatalError call should have a message.
- first_where # Prefer using .first(where:) over .filter { }.first in collections.
- contains_over_first_not_nil # Prefer contains over first(where:) != nil
- discouraged_optional_boolean # Prefer non-optional booleans over optional booleans.
- discouraged_optional_collection # Prefer empty collection over optional collection.
- redundant_nil_coalescing #nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant
- comma # There should be no space before and one after any comma
- control_statement # if,for,while,do,catch statements shouldn't wrap their conditionals or arguments in parentheses - colon
- colon # Colons should be next to the identifier when specifying a type and next to the key in dictionary literals.
- redundant_optional_initialization # Initializing an optional variable with nil is redundant.
- redundant_set_access_control # Property setter access level shouldn't be explicit if it's the same as the variable access level.
- redundant_string_enum_value # String enum values can be omitted when they are equal to the enumcase name.
- redundant_void_return # Returning Void in a function declaration is redundant.
- return_arrow_whitespace # Return arrow and return type should be separated by a single space or on a separate line.
- shorthand_operator # Prefer shorthand operators (+=, -=, *=, /=) over doing the operation and assigning.
- sorted_first_last # Prefer using min() or max() over sorted().first or sorted().last
- statement_position # Else and catch should be on the same line, one space after the previous declaration.
- switch_case_on_newline # Cases inside a switch should always be on a newline
- trailing_closure # Trailing closure syntax should be used whenever possible.
- unneeded_parentheses_in_closure_argument # Parentheses are not needed when declaring closure arguments.
- vertical_parameter_alignment_on_call # Function parameters should be aligned vertically if they're in multiple lines in a method call.
- yoda_condition # The variable should be placed on the left, the constant on the right of a comparison operator.
- closure_end_indentation # Closure end should have the same indentation as the line that started it.
- empty_string # Prefer checking isEmpty over comparing string to an empty string literal.

included: # paths to include during linting. `--path` is ignored if present.
- QuickLayout
- Example

excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Example/Pods

line_length: 180

file_length:
warning: 600
error: 1200

function_body_length:
warning: 200
error: 400

type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50

identifier_name:
min_length: # only min_length
error: 3 # only error
excluded:
- x
- y

reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit)
33 changes: 24 additions & 9 deletions Example/CrownControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
607FACE21AFB9204008FA782 /* Frameworks */,
607FACE31AFB9204008FA782 /* Resources */,
533F61999F10E673626110A6 /* [CP] Embed Pods Frameworks */,
144ED2FB21A938880062DD74 /* SwiftLint */,
);
buildRules = (
);
Expand All @@ -360,7 +361,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = "Daniel Huri";
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
Expand Down Expand Up @@ -432,6 +433,24 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
144ED2FB21A938880062DD74 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd ..\nif which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\ncd Example\n";
};
30DA69533D07A255E9C3989F /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -606,12 +625,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -659,12 +680,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -733,10 +756,6 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = D2LR97ELBQ;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -757,10 +776,6 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = D2LR97ELBQ;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
24 changes: 0 additions & 24 deletions Example/CrownControl/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

6 changes: 3 additions & 3 deletions Example/CrownControl/Contacts/Contact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Contact {

// MARK: - Properties

let id: String
let identifier: String
let name: String

var firstLetter: Character {
Expand All @@ -35,11 +35,11 @@ struct Contact {

// MARK: - Setup

init?(id: String, givenName: String, familyName: String) {
init?(identifier: String, givenName: String, familyName: String) {
guard !givenName.isEmpty || !familyName.isEmpty else {
return nil
}
self.id = id
self.identifier = identifier
var name = givenName
if name.isEmpty {
name = familyName
Expand Down
5 changes: 2 additions & 3 deletions Example/CrownControl/Contacts/ContactsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ContactManager {
}
}


// MARK: - Properties

var accessState: AccessState {
Expand All @@ -49,7 +48,7 @@ class ContactManager {
func requestAccess(completionHandler: @escaping AccessRequestCompletionHandler) {
switch accessState {
case .unknown:
CNContactStore().requestAccess(for: .contacts) { (granted, error) in
CNContactStore().requestAccess(for: .contacts) { granted, error in
DispatchQueue.main.async {
completionHandler(error == nil && granted ? .granted : .denied)
}
Expand Down Expand Up @@ -79,7 +78,7 @@ class ContactManager {
let containerContacts = try? contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch: accessKeys as [CNKeyDescriptor])
if let containerContacts = containerContacts {
contacts += containerContacts.compactMap {
guard let contact = Contact(id: $0.identifier, givenName: $0.givenName, familyName: $0.familyName) else {
guard let contact = Contact(identifier: $0.identifier, givenName: $0.givenName, familyName: $0.familyName) else {
return nil
}
self.add(contact: contact)
Expand Down
6 changes: 3 additions & 3 deletions Example/CrownControl/Contacts/UI/ContactTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class ContactTableViewCell: UITableViewCell {
thumbView.initials = contact.initials
thumbView.image = nil

let id = contact.id
let identifier = contact.identifier
DispatchQueue.global(qos: .userInitiated).async {
let image = self.contactManager.thumb(by: id)
let image = self.contactManager.thumb(by: identifier)
DispatchQueue.main.async {
guard id == self.contact.id else {
guard identifier == self.contact.identifier else {
return
}
self.thumbView.image = image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ContactsViewController: UIViewController {

private func setupCrownViewController() {
let attributes = CrownAttributes(using: tableView)
attributes.forgroundStyle.content = .color(color: .white)
attributes.foregroundStyle.content = .color(color: .white)
attributes.backgroundStyle.content = .gradient(gradient: .init(colors: [UIColor(rgb: 0x304352), UIColor(rgb: 0xd7d2cc)], startPoint: .zero, endPoint: CGPoint(x: 1, y: 1)))
attributes.backgroundStyle.border = .value(color: UIColor(rgb: 0x304352), width: 1)
attributes.sizes.scrollRelation = round(tableView.contentSize.height / UIScreen.main.bounds.height)
Expand Down
9 changes: 6 additions & 3 deletions Example/CrownControl/Extensions/UIColor+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import UIKit

extension UIColor {
static func by(r: Int, g: Int, b: Int, a: CGFloat = 1) -> UIColor {
let d = CGFloat(255)
return UIColor(red: CGFloat(r) / d, green: CGFloat(g) / d, blue: CGFloat(b) / d, alpha: a)
static func by(red: Int, green: Int, blue: Int, alpha: CGFloat = 1) -> UIColor {
let spectrum = CGFloat(255)
return UIColor(red: CGFloat(red) / spectrum,
green: CGFloat(green) / spectrum,
blue: CGFloat(blue) / spectrum,
alpha: alpha)
}

convenience init(red: Int, green: Int, blue: Int) {
Expand Down
4 changes: 4 additions & 0 deletions Example/CrownControl/Extensions/UIStoryboard+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ extension UIStoryboard {
static var main: UIStoryboard {
return UIStoryboard(name: "Main", bundle: nil)
}

func instantiate<T: UIViewController>(type: T.Type) -> T {
return instantiateViewController(withIdentifier: T.className) as! T
}
}
2 changes: 1 addition & 1 deletion Example/CrownControl/PDF/PDFViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PDFViewController: UIViewController {

private func setupCrownViewController() {
let attributes = CrownAttributes(using: webView.scrollView)
attributes.forgroundStyle.content = .color(color: .white)
attributes.foregroundStyle.content = .color(color: .white)
crownViewController = CrownIndicatorViewController(with: attributes)
addChild(crownViewController)
view.addSubview(crownViewController.view)
Expand Down
1 change: 0 additions & 1 deletion Example/CrownControl/Photos/PhotoCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import UIKit


class PhotoCollectionViewCell: UICollectionViewCell {

// MARK: - Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class PhotoCollectionViewController: UIViewController {
let color1 = UIColor(rgb: 0xffb347)
let color2 = UIColor(rgb: 0xffcc33)
attributes.backgroundStyle.content = .color(color: UIColor(white: 0.98, alpha: 1))
attributes.forgroundStyle.content = .gradient(gradient: .init(colors: [color1, color2], startPoint: .zero, endPoint: .init(x: 1, y: 1)))
attributes.forgroundStyle.border = .none
attributes.forgroundStyle.shadow = .none
attributes.foregroundStyle.content = .gradient(gradient: .init(colors: [color1, color2], startPoint: .zero, endPoint: .init(x: 1, y: 1)))
attributes.foregroundStyle.border = .none
attributes.foregroundStyle.shadow = .none
attributes.sizes.scrollRelation = CGFloat(dataSource.count) * 0.5
attributes.scrollAxis = .horizontal

Expand Down
1 change: 1 addition & 0 deletions Example/CrownControl/SampleData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

struct SampleData {
typealias Action = () -> Void

let title: String
let action: Action
}
12 changes: 6 additions & 6 deletions Example/CrownControl/SamplesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ extension SamplesViewController: UITableViewDelegate, UITableViewDataSource {
}

private func navigateToPDFViewController() {
let vc = UIStoryboard.main.instantiateViewController(withIdentifier: PDFViewController.className) as! PDFViewController
navigationController!.pushViewController(vc, animated: true)
let viewController = UIStoryboard.main.instantiate(type: PDFViewController.self)
navigationController!.pushViewController(viewController, animated: true)
}

private func navigateToPhotoCollectionView() {
let vc = UIStoryboard.main.instantiateViewController(withIdentifier: PhotoCollectionViewController.className) as! PhotoCollectionViewController
navigationController!.pushViewController(vc, animated: true)
let viewController = UIStoryboard.main.instantiate(type: PhotoCollectionViewController.self)
navigationController!.pushViewController(viewController, animated: true)
}

private func navigateToContactsViewController() {
let vc = UIStoryboard.main.instantiateViewController(withIdentifier: ContactsViewController.className) as! ContactsViewController
navigationController!.pushViewController(vc, animated: true)
let viewController = UIStoryboard.main.instantiate(type: ContactsViewController.self)
navigationController!.pushViewController(viewController, animated: true)
}
}
Loading

0 comments on commit 2368176

Please sign in to comment.