Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 6d19a71

Browse files
committed
Swiftlint
1 parent a2c4edd commit 6d19a71

File tree

12 files changed

+278
-140
lines changed

12 files changed

+278
-140
lines changed

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.0

.swiftlint.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
excluded:
2+
- Carthage
3+
- Pods
4+
- vendor
5+
6+
disabled_rules:
7+
- nesting
8+
- opening_brace
9+
- statement_position
10+
- weak_delegate
11+
12+
opt_in_rules:
13+
# - array_init # is causing a false positive on `.map { !$0 }`
14+
- closure_end_indentation
15+
- closure_spacing
16+
- contains_over_first_not_nil
17+
- empty_count
18+
- explicit_init
19+
- explicit_top_level_acl
20+
- fatal_error_message
21+
- file_header
22+
- first_where
23+
- force_unwrapping
24+
- implicit_return
25+
- let_var_whitespace
26+
- literal_expression_end_indentation
27+
- multiline_arguments
28+
- multiple_closures_with_trailing_closure
29+
- operator_usage_whitespace
30+
- redundant_nil_coalescing
31+
- single_test_class
32+
- sorted_imports
33+
# - trailing_closure # causing a false positive on `.subscribe(onNext:)`
34+
- unneeded_parentheses_in_closure_argument
35+
36+
vertical_whitespace:
37+
max_empty_lines: 2
38+
39+
file_header:
40+
required_pattern: |
41+
\/\/
42+
\/\/ .*?\.swift
43+
\/\/ RxWebSocket
44+
\/\/
45+
\/\/ Created by .*? on \d{4}-\d{2}-\d{2}\.
46+
\/\/ Copyright © \d{4} RxWebSocket\. All rights reserved\.
47+
\/\/

Example/Podfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
platform :ios, 8.0
2+
13
source 'https://github.com/CocoaPods/Specs.git'
4+
25
use_frameworks!
36

47
target 'RxWebSocket_Example' do
5-
pod 'RxWebSocket', :path => '../'
8+
pod 'RxWebSocket', :path => '.'
69

10+
pod 'SwiftLint', '~> 0.23.1'
11+
712
target 'RxWebSocket_Tests' do
813
inherit! :search_paths
914
end

Example/RxWebSocket.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,20 @@
365365
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
366366
showEnvVarsInLog = 0;
367367
};
368+
F2A14DF71FB0CEF600933B88 /* Swiftlint */ = {
369+
isa = PBXShellScriptBuildPhase;
370+
buildActionMask = 2147483647;
371+
files = (
372+
);
373+
inputPaths = (
374+
);
375+
name = Swiftlint;
376+
outputPaths = (
377+
);
378+
runOnlyForDeploymentPostprocessing = 0;
379+
shellPath = /bin/sh;
380+
shellScript = "if [ -f \"${PODS_ROOT}/SwiftLint/swiftlint\" ]; then\n \"${PODS_ROOT}/SwiftLint/swiftlint\" --path \"${PROJECT_DIR}\"\nelse\n echo \"error: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\n exit 1\nfi";
381+
};
368382
/* End PBXShellScriptBuildPhase section */
369383

370384
/* Begin PBXSourcesBuildPhase section */

Example/RxWebSocket/AppDelegate.swift

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,22 @@
22
// AppDelegate.swift
33
// RxWebSocket
44
//
5-
// Created by Flávio Caetano on 01/22/2016.
6-
// Copyright (c) 2016 Flávio Caetano. All rights reserved.
5+
// Created by Flávio Caetano on 2016-01-22.
6+
// Copyright © 2016 RxWebSocket. All rights reserved.
77
//
88

99
import UIKit
1010

1111
@UIApplicationMain
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
13-
13+
1414
var window: UIWindow?
15-
16-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
15+
16+
func application(
17+
_ application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
19+
) -> Bool {
1720
// Override point for customization after application launch.
1821
return true
1922
}
20-
21-
func applicationWillResignActive(_ application: UIApplication) {
22-
// 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.
23-
// 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.
24-
}
25-
26-
func applicationDidEnterBackground(_ application: UIApplication) {
27-
// 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.
28-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
29-
}
30-
31-
func applicationWillEnterForeground(_ application: UIApplication) {
32-
// 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.
33-
}
34-
35-
func applicationDidBecomeActive(_ application: UIApplication) {
36-
// 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.
37-
}
38-
39-
func applicationWillTerminate(_ application: UIApplication) {
40-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
41-
}
42-
43-
4423
}
45-

Example/RxWebSocket/Base.lproj/LaunchScreen.xib

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
3+
<device id="retina5_9" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
59
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
611
</dependencies>
712
<objects>
813
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -11,7 +16,7 @@
1116
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
1217
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1318
<subviews>
14-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 CocoaPods. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
19+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2016 RxWebSocket. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
1520
<rect key="frame" x="20" y="439" width="441" height="21"/>
1621
<fontDescription key="fontDescription" type="system" pointSize="17"/>
1722
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@@ -24,7 +29,7 @@
2429
<nil key="highlightedColor"/>
2530
</label>
2631
</subviews>
27-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
32+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2833
<constraints>
2934
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
3035
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>

Example/RxWebSocket/ViewController.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,47 @@
22
// ViewController.swift
33
// RxWebSocket
44
//
5-
// Created by Flávio Caetano on 01/22/2016.
6-
// Copyright (c) 2016 Flávio Caetano. All rights reserved.
5+
// Created by Flávio Caetano on 2016-01-22.
6+
// Copyright © 2016 RxWebSocket. All rights reserved.
77
//
88

9-
import UIKit
10-
import RxWebSocket
11-
import RxSwift
129
import RxCocoa
10+
import RxSwift
11+
import RxWebSocket
12+
import UIKit
1313

1414

1515
class ViewController: UIViewController {
16-
16+
17+
// swiftlint:disable force_unwrapping
1718
private let socket = RxWebSocket(url: URL(string: "ws://echo.websocket.org")!)
1819
private let disposeBag = DisposeBag()
19-
20+
2021
// MARK: Outlets
21-
22+
2223
@IBOutlet fileprivate weak var textView: UITextView!
2324
@IBOutlet fileprivate weak var textField: UITextField!
2425
@IBOutlet fileprivate weak var sendButton: UIButton!
2526
@IBOutlet fileprivate weak var connectButton: UIButton!
26-
27+
2728
override func viewDidLoad() {
2829
super.viewDidLoad()
29-
30-
30+
31+
3132
// Connect/Disconnect events
3233
let connect = socket.rx.connect
3334
.do(onNext: { [weak self] in
3435
self?.append("CONNECTED")
3536
})
3637
.map { true }
37-
38+
3839
let disconnect = socket.rx.disconnect
3940
.do(onNext: { [weak self] _ in
4041
self?.append("DISCONNECTED")
4142
})
4243
.map { _ in false }
43-
44-
44+
45+
4546
Observable.of(connect, disconnect)
4647
.merge()
4748
.subscribe(onNext: { [weak self] isConnected in
@@ -50,21 +51,21 @@ class ViewController: UIViewController {
5051
self?.sendButton.isEnabled = isConnected
5152
})
5253
.disposed(by: disposeBag)
53-
54-
54+
55+
5556
// Text events
5657
socket.rx.text
5758
.subscribe(onNext: { [weak self] text in
5859
self?.append("RECEIVED: \(text)")
5960
})
6061
.disposed(by: disposeBag)
61-
62-
62+
63+
6364
// Connect Button
6465
connectButton.rx.tap
6566
.subscribe(onNext: { [unowned self] in
6667
self.connectButton.isEnabled = false
67-
68+
6869
if self.connectButton.isSelected {
6970
self.socket.disconnect()
7071
}
@@ -73,8 +74,8 @@ class ViewController: UIViewController {
7374
}
7475
})
7576
.disposed(by: disposeBag)
76-
77-
77+
78+
7879
// Send Button
7980
sendButton.rx.tap
8081
.flatMap { self.textField.rx.text.orEmpty.take(1) }
@@ -84,17 +85,16 @@ class ViewController: UIViewController {
8485
.bind(to: socket.rx.text)
8586
.disposed(by: disposeBag)
8687
}
87-
88+
8889
// MARK: - Private Methods
89-
90+
9091
private func append(_ message: String) {
9192
let currentText = textView.text ?? ""
9293
textView.text = "\(currentText)\n\n\(message)"
93-
94-
textView.scrollRangeToVisible(NSMakeRange(textView.text.count, 0))
94+
95+
textView.scrollRangeToVisible(NSRange(location: textView.text.count, length: 0))
9596
// lolwut? i know
9697
textView.isScrollEnabled = false
9798
textView.isScrollEnabled = true
9899
}
99100
}
100-

0 commit comments

Comments
 (0)