Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Improve linting #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
excluded:
- Pods

- docs
- build
- scripts

disabled_rules:
- line_length
- todo
# metrics
- nesting
- function_parameter_count

# lint
- notification_center_detachment
- unused_closure_parameter
- weak_delegate

# idiomatic
- fallthrough
- force_cast
- type_name

# style
- identifier_name
- closure_parameter_position

opt_in_rules:
# performance
- empty_count
- first_where
- sorted_first_last
- contains_over_first_not_nil

# idiomatic
- fatal_error_message

# style
- attributes
- number_separator
- operator_usage_whitespace
- sorted_imports
- vertical_parameter_alignment_on_call

# lint
- overridden_super_call

line_length: 200
file_length: 600

type_body_length: 500

function_body_length: 250

cyclomatic_complexity: 15

# limit whitespace only lines to 2
vertical_whitespace:
max_empty_lines: 2
6 changes: 3 additions & 3 deletions Brisk iOS/App/AppCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import UIKit
import InterfaceBacked
import Sonar
import AcknowList
import InterfaceBacked
import SafariServices
import Sonar
import UIKit

final class AppCoordinator {

Expand Down
2 changes: 1 addition & 1 deletion Brisk iOS/App/StatusDisplay.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import SVProgressHUD
import UIKit

protocol StatusDisplay {
func showLoading()
Expand Down
3 changes: 2 additions & 1 deletion Brisk iOS/Dupe/DupeViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import InterfaceBacked
import UIKit

protocol DupeViewDelegate: class {
func controllerDidCancel(_ controller: DupeViewController)
Expand All @@ -20,6 +20,7 @@ final class DupeViewController: UIViewController, StoryboardBacked, StatusDispla
// MARK: - UIViewController Methods

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let content = UIPasteboard.general.string, content.isOpenRadar && number.isEmpty {
numberField.text = content.extractRadarNumber()
hintLabel.text = "Found \(content) on your clipboard"
Expand Down
2 changes: 1 addition & 1 deletion Brisk iOS/Login/LoginCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import SafariServices
import UIKit

private let kAPIKeyURL = URL(string: "https://openradar.appspot.com/apikey")!
private let kOpenRadarUsername = "openradar"
Expand Down
3 changes: 2 additions & 1 deletion Brisk iOS/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import InterfaceBacked
import UIKit

protocol LoginViewDelegate: class {
func submitTapped(user: User)
Expand All @@ -20,6 +20,7 @@ final class LoginViewController: UIViewController, StoryboardBacked {
// MARK: - UIViewController Methods

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
emailField.becomeFirstResponder()
validateSubmitButton()
}
Expand Down
2 changes: 1 addition & 1 deletion Brisk iOS/Login/OpenRadarViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import InterfaceBacked
import UIKit

protocol OpenRadarViewDelegate: class {
func openSafariTapped()
Expand Down
2 changes: 1 addition & 1 deletion Brisk iOS/Menu/MenuViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import InterfaceBacked
import UIKit

protocol MenuViewDelegate: class {
func dupeTapped()
Expand Down
2 changes: 1 addition & 1 deletion Brisk iOS/Model/APIController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Alamofire
import Foundation
import Sonar
import Alamofire

protocol APIDelegate: class {
func didStartLoading()
Expand Down
8 changes: 4 additions & 4 deletions Brisk iOS/Model/KeyboardObservable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension KeyboardObservable where Self: UITextView {
}
private var textHeight: CGFloat {
guard let font = font else {
fatalError()
fatalError("Can't calculate text height without a font.")
}
let size = (text ?? "").size(with: font, constrainedToWidth: frame.width)
return size.height
Expand Down Expand Up @@ -88,18 +88,18 @@ extension KeyboardObservable where Self: UITextView {
let window = superview.window,
let font = font,
let userInfo = notification.userInfo else {
fatalError()
fatalError("Missing required superview, window, font & userInfo.")
}
let keyboardScreenFrame: CGRect
switch state {
case .show:
guard let frame = userInfo[UIKeyboardFrameEndUserInfoKey] as? CGRect else {
fatalError()
fatalError("No frame in userInfo found for key UIKeyboardFrameEndUserInfoKey")
}
keyboardScreenFrame = frame
case .hide:
guard let frame = userInfo[UIKeyboardFrameBeginUserInfoKey] as? CGRect else {
fatalError()
fatalError("No frame in userInfo found for key UIKeyboardFrameBeginUserInfoKey")
}
keyboardScreenFrame = frame
}
Expand Down
5 changes: 4 additions & 1 deletion Brisk iOS/Radar/EnterDetailsViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import InterfaceBacked
import UIKit

final class TextView: UITextView, KeyboardObservable {
private var observers: [Any]?
Expand Down Expand Up @@ -33,6 +33,7 @@ final class EnterDetailsViewController: UIViewController, StoryboardBacked {
// MARK: - UIViewController Methods

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if placeholder.isNotEmpty && prefilledContent.isEmpty {
applyStyling(.placeholder)
textView.text = placeholder
Expand All @@ -43,10 +44,12 @@ final class EnterDetailsViewController: UIViewController, StoryboardBacked {
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
textView.becomeFirstResponder()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if placeholder.isEmpty ||
textView.text != placeholder {
onDisappear(textView.text)
Expand Down
7 changes: 3 additions & 4 deletions Brisk iOS/Radar/RadarCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation
import UIKit
import Sonar

// FIXME: This grew fast. Extract stuff...
import UIKit

final class RadarCoordinator: NSObject {

Expand Down Expand Up @@ -127,7 +125,8 @@ final class RadarCoordinator: NSObject {

}

@objc fileprivate func enterDetailsDidFinish() {
@objc
fileprivate func enterDetailsDidFinish() {
root.presentedViewController?.dismiss(animated: true)
if let selected = radarViewController?.tableView.indexPathForSelectedRow {
radarViewController?.tableView.deselectRow(at: selected, animated: true)
Expand Down
3 changes: 1 addition & 2 deletions Brisk iOS/Radar/RadarViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit
import InterfaceBacked
import Sonar
import UIKit

protocol RadarViewDelegate: class {
func productTapped()
Expand Down Expand Up @@ -72,7 +72,6 @@ final class RadarViewController: UITableViewController, StoryboardBacked, Status
}

// swiftlint:disable cyclomatic_complexity
// swiftlint:disable:next function_body_length
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell"), let radar = self.radar else { preconditionFailure() }
var left = ""
Expand Down
3 changes: 2 additions & 1 deletion Brisk iOS/Radar/SingleChoiceTableViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit
import InterfaceBacked
import Sonar
import UIKit

final class SingleChoiceViewController<T: Choice>: UITableViewController {

Expand All @@ -14,6 +14,7 @@ final class SingleChoiceViewController<T: Choice>: UITableViewController {
// MARK: - UIViewController Methods

override func viewDidLoad() {
super.viewDidLoad()
precondition(all != nil, "All choices must be set before the view controller is presented")
precondition(all!.isNotEmpty, "All choices must not be empty")
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
Expand Down
3 changes: 2 additions & 1 deletion Brisk iOS/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import InterfaceBacked
import UIKit

protocol SettingsDelegate: class {
func doneTapped()
Expand Down Expand Up @@ -27,6 +27,7 @@ final class SettingsViewController: UITableViewController, StoryboardBacked {
// MARK: - UIViewController Methods

override func viewDidLoad() {
super.viewDidLoad()
configureVersionLabel()
}

Expand Down
2 changes: 1 addition & 1 deletion Brisk iOSTests/EmailTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import Brisk_iOS
import XCTest

class EmailTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion Brisk iOSTests/RadarNumberEtractionTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
@testable import Brisk_iOS
import XCTest

class RadarNumberEtractionTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion Brisk iOSTests/SubmitRadarTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XCTest
@testable import Brisk_iOS
@testable import Sonar
import XCTest

final class MockDisplay: StatusDisplay {
var didShowLoading = false
Expand Down
13 changes: 8 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Brisk

[![Build status](https://badge.buildkite.com/672895d57514714220c79243148e0423061d2f04ca6ff5f6e8.svg)](https://buildkite.com/florianbuerger/brisk)
Expand All @@ -25,24 +24,28 @@ Posting to OpenRadar only works when you entered your API key in settings. Re-en

## URL Scheme

Brisk supports an URL scheme `brisk-rdar` to integrate with other apps.
Brisk supports an URL scheme `brisk-rdar` to integrate with other apps.

Pass an OpenRadar number: `brisk-rdar://radar/123456`. Per default, Brisk searches for the number with user interaction. If you don't want that, use `brisk-radar://radar/123456?submit=false`.

## Installation

iOS apps have to be signed in order to be installed on a device. To let Xcode handle everything for you change the `Bundle Identifier` to something unique, `com.<yourname>.brisk` for example and select your development team in Xcode.
iOS apps have to be signed in order to be installed on a device. To let Xcode handle everything for you change the `Bundle Identifier` to something unique, `com.<yourname>.brisk` for example and select your development team in Xcode.

1. Open `Brisk iOS.xcworkspace`
2. Go to Xcode > Preferences > Accounts and add an active iOS developer account if you haven't done that already
3. Change the `Bundle identifier` to `com.<yourname>.brisk`
3. Change the `Bundle identifier` to `com.<yourname>.brisk`
4. Select the project in Xcode's sidebar, select the `Brisk iOS` target and select your Apple ID in `Signing > Team`

Feel free to [contact me](mailto:[email protected]) if you need help or open a new issue.

## Development

The app is built with Swift 4.0 and everything should work after you clone the project.
The app is built with Swift 4 using Xcode 9. It requires [swiftlint](https://github.com/realm/SwiftLint) to be installed in your `$PATH`. If you haven't yet, please install it using [Homebrew](https://brew.sh/):

```
$ brew install swiftlint
```

## Credits

Expand Down