Skip to content

Commit

Permalink
Merge pull request #199 from lennet/swift-format
Browse files Browse the repository at this point in the history
Fixed Swiftformat
  • Loading branch information
fbernutz authored Nov 24, 2019
2 parents cf1444e + 14b1ee7 commit 26e3844
Show file tree
Hide file tree
Showing 39 changed files with 174 additions and 179 deletions.
2 changes: 1 addition & 1 deletion CriticalMaps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [ $CONFIGURATION = \"Debug\" ]; then\n $SOURCE_ROOT/bin/license-plist --output-path ./Settings.bundle\nfi\n";
shellScript = "if [ $CONFIGURATION = \"Debug\" ]; then\n $SOURCE_ROOT/bin/swiftformat .\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
6 changes: 3 additions & 3 deletions CriticalMapsMocksForTests/MockNetworkDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ struct MockNetworkDataProvider: NetworkDataProvider {
var data: Data?
var response: URLResponse?
var error: Error?
func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {

func dataTask(with _: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) {
completionHandler(data, response, error)
}

func invalidateAndCancel() {}
}
2 changes: 1 addition & 1 deletion CriticalMapsMocksForTests/MockThemeController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class MockThemeController: ThemeController {
static let shared = MockThemeController()

private init() {
let store = MockThemeStore()
super.init(store: store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import XCTest

class RulesDetailViewControllerSnapshotTests: XCTestCase {

func testGeneralAppearance() {
// Given
let viewController = RulesDetailViewController(rule: Rule.cork)
Expand Down
10 changes: 5 additions & 5 deletions CriticalMapsSnapshotTests/TweetTableViewCellSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import XCTest
class TweetTableViewCellSnapshotTests: XCTestCase {
private let size = CGSize(width: 320, height: 100)
// use constant date in the past
private let tweetDate = Date(timeIntervalSince1970: 1530230956)
private let tweetDate = Date(timeIntervalSince1970: 1_530_230_956)

override func setUp() {
// use constant date in the past
FormatDisplay.currentDate = Date(timeIntervalSince1970: 1530240956)
FormatDisplay.currentDate = Date(timeIntervalSince1970: 1_530_240_956)
}

func testTweetTableViewCell() {
Expand All @@ -28,10 +28,10 @@ class TweetTableViewCellSnapshotTests: XCTestCase {
profile_image_url_https: "haa"),
id_str: "test_id")
let cell = TweetTableViewCell.fromNib()

// when
cell.setup(for: tweet)

// then
assertViewSnapshot(matching: cell, with: size)
}
Expand Down
12 changes: 6 additions & 6 deletions CriticalMapsSnapshotTests/XCTestCase+SnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import XCTest

extension XCTestCase {
func assertViewSnapshot(for themes: [Theme] = [.light, .dark],
matching value: UIView,
with size: CGSize? = nil,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line) {
matching value: UIView,
with size: CGSize? = nil,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line) {
themes.forEach { theme in
MockThemeController.shared.changeTheme(to: theme)
MockThemeController.shared.applyTheme()
MockThemeController.shared.applyTheme()
assertSnapshot(matching: value,
as: .image(size: size),
named: theme.displayName,
Expand Down
3 changes: 1 addition & 2 deletions CriticalMapsUITests/CriticalMapsUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
import XCTest

class CriticalMapsUITests: XCTestCase {

override func setUp() {
super.setUp()
continueAfterFailure = false

let app = XCUIApplication()
app.launchArguments += [
"SKIP_ANIMATIONS"
"SKIP_ANIMATIONS",
]
setupSnapshot(app, waitForAnimations: false)
app.launch()
Expand Down
19 changes: 9 additions & 10 deletions CriticalMapsUITests/SnapshotHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum SnapshotError: Error, CustomDebugStringConvertible {
return "Couldn't find Snapshot configuration files - can't detect `Users` dir"
case .cannotFindSimulatorHomeDirectory:
return "Couldn't find simulator home location. Please, check SIMULATOR_HOST_HOME env variable."
case .cannotAccessSimulatorHomeDirectory(let simulatorHostHome):
case let .cannotAccessSimulatorHomeDirectory(simulatorHostHome):
return "Can't prepare environment. Simulator home location is inaccessible. Does \(simulatorHostHome) exist?"
case .cannotRunOnPhysicalDevice:
return "Can't use Snapshot on a physical device."
Expand All @@ -70,7 +70,6 @@ open class Snapshot: NSObject {
}

open class func setupSnapshot(_ app: XCUIApplication, waitForAnimations: Bool = true) {

Snapshot.app = app
Snapshot.waitForAnimations = waitForAnimations

Expand All @@ -80,7 +79,7 @@ open class Snapshot: NSObject {
setLanguage(app)
setLocale(app)
setLaunchArguments(app)
} catch let error {
} catch {
NSLog(error.localizedDescription)
}
}
Expand Down Expand Up @@ -117,7 +116,7 @@ open class Snapshot: NSObject {
NSLog("Couldn't detect/set locale...")
}

if locale.isEmpty && !deviceLanguage.isEmpty {
if locale.isEmpty, !deviceLanguage.isEmpty {
locale = Locale(identifier: deviceLanguage).identifier
}

Expand Down Expand Up @@ -184,7 +183,7 @@ open class Snapshot: NSObject {

let path = screenshotsDir.appendingPathComponent("\(simulator)-\(name).png")
try screenshot.pngRepresentation.write(to: path)
} catch let error {
} catch {
NSLog("Problem writing screenshot: \(name) to \(screenshotsDir)/\(simulator)-\(name).png")
NSLog(error.localizedDescription)
}
Expand Down Expand Up @@ -266,13 +265,13 @@ private extension XCUIElementAttributes {

private extension XCUIElementQuery {
var networkLoadingIndicators: XCUIElementQuery {
let isNetworkLoadingIndicator = NSPredicate { (evaluatedObject, _) in
let isNetworkLoadingIndicator = NSPredicate { evaluatedObject, _ in
guard let element = evaluatedObject as? XCUIElementAttributes else { return false }

return element.isNetworkLoadingIndicator
}

return self.containing(isNetworkLoadingIndicator)
return containing(isNetworkLoadingIndicator)
}

var deviceStatusBars: XCUIElementQuery {
Expand All @@ -282,19 +281,19 @@ private extension XCUIElementQuery {

let deviceWidth = app.windows.firstMatch.frame.width

let isStatusBar = NSPredicate { (evaluatedObject, _) in
let isStatusBar = NSPredicate { evaluatedObject, _ in
guard let element = evaluatedObject as? XCUIElementAttributes else { return false }

return element.isStatusBar(deviceWidth)
}

return self.containing(isStatusBar)
return containing(isStatusBar)
}
}

private extension CGFloat {
func isBetween(_ numberA: CGFloat, and numberB: CGFloat) -> Bool {
return numberA...numberB ~= self
return numberA ... numberB ~= self
}
}

Expand Down
2 changes: 1 addition & 1 deletion CriticalMass/AnnotationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class AnnotationController<T: IdentifiableAnnnotation, K: MKAnnotationView> {
self.mapView = mapView
setup()
}

open func setup() {}
}
8 changes: 4 additions & 4 deletions CriticalMass/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AppController {

let networkDataProvider: NetworkDataProvider
if simulationModeEnabled {
networkDataProvider = SimulationNetworkDataProvider(realNetworkDataProvider: session)
networkDataProvider = SimulationNetworkDataProvider(realNetworkDataProvider: session)
} else {
networkDataProvider = session
}
Expand All @@ -44,7 +44,7 @@ class AppController {
private lazy var twitterManager: TwitterManager = {
TwitterManager(networkLayer: networkOperator, request: TwitterRequest())
}()

lazy var rootViewController: UIViewController = {
let rootViewController = MapViewController(themeController: self.themeController)
let navigationOverlay = NavigationOverlayViewController(navigationItems: [
Expand Down Expand Up @@ -75,7 +75,7 @@ class AppController {
RatingHelper().onLaunch()
}
}

public func onWillEnterForeground() {
if #available(iOS 10.3, *) {
RatingHelper().onEnterForeground()
Expand All @@ -85,7 +85,7 @@ class AppController {
public func enableSimulationMode() {
simulationModeEnabled = true
}

private func getRulesViewController() -> RulesViewController {
return RulesViewController()
}
Expand Down
3 changes: 1 addition & 2 deletions CriticalMass/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var appController = AppController()

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// Test Configuration
if let shouldEarlyExitForTests = configureAppForTests() {
return shouldEarlyExitForTests
Expand Down Expand Up @@ -41,7 +40,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if ProcessInfo.processInfo.arguments.contains("SKIP_ANIMATIONS") {
UIView.setAnimationsEnabled(false)
}

if ProcessInfo.processInfo.arguments.contains("SIMULATION_MODE") {
appController.enableSimulationMode()
}
Expand Down
4 changes: 2 additions & 2 deletions CriticalMass/CMLogoActivityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
@IBDesignable public class CMLogoActivityView: UIView, IBConstructable {
private var angle: CGFloat = 0
private lazy var displayLink: CADisplayLink = {
return CADisplayLink(target: self, selector: #selector(updateViewParameter))
CADisplayLink(target: self, selector: #selector(updateViewParameter))
}()

public override func draw(_: CGRect) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public struct CriticalMapsLoader {
//// gear
context.saveGState()
context.translateBy(x: 50, y: 50)
context.rotate(by: -angle * CGFloat.pi/180)
context.rotate(by: -angle * CGFloat.pi / 180)

//// Bezier 4 Drawing
context.saveGState()
Expand Down
2 changes: 1 addition & 1 deletion CriticalMass/ChatInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ class ChatInputView: UIView {

private extension String {
var canBeSent: Bool {
!self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
!trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
}
2 changes: 1 addition & 1 deletion CriticalMass/ChatManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Leonard Thomas on 1/26/19.
//

import Foundation
import Crypto
import Foundation

class ChatManager {
private var cachedMessages: [ChatMessage]?
Expand Down
1 change: 1 addition & 0 deletions CriticalMass/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ChatViewController: UIViewController, ChatInputDelegate {
private enum Constants {
static let chatInputHeight: CGFloat = 64
}

private let chatInput = ChatInputView(frame: .zero)
private let messagesTableViewController = MessagesTableViewController<ChatMessageTableViewCell>(style: .plain)
private let chatManager: ChatManager
Expand Down
1 change: 0 additions & 1 deletion CriticalMass/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation


public enum Constants {
static let apiEndpoint = URL(string: "https://api.criticalmaps.net/")!
static let criticalMapsiOSGitHubEndpoint = URL(string: "https://github.com/criticalmaps/criticalmaps-ios")!
Expand Down
8 changes: 4 additions & 4 deletions CriticalMass/ErrorStateViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import UIKit
typealias ReloadHandler = () -> Void

class ErrorStateViewController: UIViewController, IBConstructable {
@IBOutlet private weak var errorTitle: UILabel!
@IBOutlet private weak var errorMessage: UILabel!
@IBOutlet private weak var retryButton: UIButton!
@IBOutlet private var errorTitle: UILabel!
@IBOutlet private var errorMessage: UILabel!
@IBOutlet private var retryButton: UIButton!

var reloadHandler: ReloadHandler?
var errorStateModel: ErrorStateModel!
Expand All @@ -28,7 +28,7 @@ class ErrorStateViewController: UIViewController, IBConstructable {
errorMessage.text = errorStateModel.errorMessage
}

@IBAction func reload(_ sender: Any) {
@IBAction func reload(_: Any) {
reloadHandler?()
}
}
Expand Down
2 changes: 1 addition & 1 deletion CriticalMass/FormatDisplay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private extension DateComponents {
enum FormatDisplay {
// inject current date to be able to keep the same time difference between tweet date and current date
static var currentDate = Date()

static func dateString(for tweet: Tweet) -> String? {
let components = Calendar.current.dateComponents([.minute, .hour, .day, .month], from: tweet.created_at, to: currentDate).dateomponentFromBiggestComponent
let formatter = DateComponentsFormatter()
Expand Down
2 changes: 1 addition & 1 deletion CriticalMass/IDProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import Foundation
public protocol IDProvider {
var id: String { get }
var token: String { get }

static func hash(id: String, currentDate: Date) -> String
}
9 changes: 4 additions & 5 deletions CriticalMass/IDStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
// Created by Leonard Thomas on 5/2/19.
//

import UIKit
import Crypto
import UIKit

public class IDStore: IDProvider {

public let id: String
public let token: String

public init(currentDate: Date = Date()) {
let deviceID = UIDevice.current.identifierForVendor?.uuidString ?? UUID().uuidString

id = IDStore.hash(id: deviceID, currentDate: currentDate)
token = deviceID
}

static public func hash(id: String, currentDate: Date = Date()) -> String {
public static func hash(id: String, currentDate: Date = Date()) -> String {
let format = DateFormatter()
format.dateFormat = "yyyy-MM-dd"
let dateString = format.string(from: currentDate)

return String(id + dateString).md5!
}
}
Loading

0 comments on commit 26e3844

Please sign in to comment.