Skip to content

Commit ed7ebf1

Browse files
committed
Add .swiftlint.yml and .hound.yml, address lint warnings
1 parent 699e6ac commit ed7ebf1

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

.hound.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
swiftlint:
2+
config_file: .swiftlint.yml

.swiftlint.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
included:
2+
- Sources
3+
- Tests
4+
5+
excluded:
6+
- Sources/Availability.swift
7+
8+
disabled_rules:
9+
- file_length
10+
- line_length
11+
12+
trailing_comma:
13+
mandatory_comma: true

Sources/Task.swift

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ public struct Task {
3636
self.workingDirectoryPath = workingDirectoryPath
3737
self.environment = environment
3838
}
39-
39+
4040
/// A GCD group which to wait completion
4141
fileprivate static let group = DispatchGroup()
42-
42+
4343
/// wait for all task termination
4444
public static func waitForAllTaskTermination() {
45-
let _ = Task.group.wait(timeout: DispatchTime.distantFuture)
45+
_ = Task.group.wait(timeout: DispatchTime.distantFuture)
4646
}
4747
}
4848

4949
extension String {
50+
// swiftlint:disable:next force_try
5051
private static let whitespaceRegularExpression = try! NSRegularExpression(pattern: "\\s")
5152

5253
var escapingWhitespaces: String {
@@ -76,15 +77,11 @@ extension Task: Hashable {
7677
&& lhs.environment == rhs.environment
7778
}
7879

79-
public var hashValue: Int {
80-
var result = launchPath.hashValue ^ (workingDirectoryPath?.hashValue ?? 0)
81-
for argument in arguments {
82-
result ^= argument.hashValue
83-
}
84-
for (key, value) in environment ?? [:] {
85-
result ^= key.hashValue ^ value.hashValue
86-
}
87-
return result
80+
public func hash(into hasher: inout Hasher) {
81+
hasher.combine(launchPath)
82+
hasher.combine(arguments)
83+
hasher.combine(workingDirectoryPath)
84+
hasher.combine(environment)
8885
}
8986
}
9087

@@ -100,7 +97,7 @@ private final class Pipe {
10097

10198
/// A GCD queue upon which to deliver I/O callbacks.
10299
let queue: DispatchQueue
103-
100+
104101
/// A GCD group which to wait completion
105102
let group: DispatchGroup
106103

@@ -169,7 +166,7 @@ private final class Pipe {
169166
if let dispatchData = dispatchData {
170167
// Cast DispatchData to Data.
171168
// See https://gist.github.com/mayoff/6e35e263b9ddd04d9b77e5261212be19.
172-
let nsdata = dispatchData as Any as! NSData
169+
let nsdata = dispatchData as Any as! NSData // swiftlint:disable:this force_cast
173170
let data = Data(referencing: nsdata)
174171
observer.send(value: data)
175172
}
@@ -223,8 +220,8 @@ private final class Pipe {
223220
let buffer = UnsafeRawBufferPointer(start: bytes, count: data.count)
224221
return DispatchData(bytes: buffer)
225222
}
226-
227-
channel.write(offset: 0, data: dispatchData, queue: self.queue) { (done, data, error) in
223+
224+
channel.write(offset: 0, data: dispatchData, queue: self.queue) { _, _, error in
228225
if error == ECANCELED {
229226
observer.sendInterrupted()
230227
} else if error != 0 {
@@ -247,7 +244,7 @@ private final class Pipe {
247244

248245
public protocol TaskEventType {
249246
/// The type of value embedded in a `Success` event.
250-
associatedtype T
247+
associatedtype T // swiftlint:disable:this type_name
251248

252249
/// The resulting value, if the event is `Success`.
253250
var value: T? { get }
@@ -264,7 +261,7 @@ public protocol TaskEventType {
264261
public enum TaskEvent<T>: TaskEventType {
265262
/// The task is about to be launched.
266263
case launch(Task)
267-
264+
268265
/// Some data arrived from the task on `stdout`.
269266
case standardOutput(Data)
270267

@@ -305,7 +302,7 @@ public enum TaskEvent<T>: TaskEventType {
305302
switch self {
306303
case let .launch(task):
307304
return .init(value: .launch(task))
308-
305+
309306
case let .standardOutput(data):
310307
return .init(value: .standardOutput(data))
311308

@@ -348,7 +345,7 @@ extension TaskEvent: CustomStringConvertible {
348345
switch self {
349346
case let .launch(task):
350347
return "launch: \(task)"
351-
348+
352349
case let .standardOutput(data):
353350
return "stdout: " + dataDescription(data)
354351

@@ -368,7 +365,7 @@ extension SignalProducer where Value: TaskEventType {
368365
return taskEvent.producerMap(transform)
369366
}
370367
}
371-
368+
372369
/// Ignores incremental standard output and standard error data from the given
373370
/// task, sending only a single value with the final, aggregated result.
374371
public func ignoreTaskData() -> SignalProducer<Value.T, Error> {
@@ -395,8 +392,10 @@ extension Task {
395392
///
396393
/// - Returns: A producer that will launch the receiver when started, then send
397394
/// `TaskEvent`s as execution proceeds.
398-
public func launch(standardInput: SignalProducer<Data, NoError>? = nil,
399-
shouldBeTerminatedOnParentExit: Bool = false) -> SignalProducer<TaskEvent<Data>, TaskError> {
395+
public func launch( // swiftlint:disable:this function_body_length cyclomatic_complexity
396+
standardInput: SignalProducer<Data, NoError>? = nil,
397+
shouldBeTerminatedOnParentExit: Bool = false
398+
) -> SignalProducer<TaskEvent<Data>, TaskError> {
400399
return SignalProducer { observer, lifetime in
401400
let queue = DispatchQueue(label: self.description, attributes: [])
402401
let group = Task.group
@@ -518,7 +517,7 @@ extension Task {
518517
}
519518
group.leave()
520519
}
521-
520+
522521
observer.send(value: .launch(self))
523522
process.launch()
524523
close(stdoutPipe.writeFD)

Tests/ReactiveTaskTests/StringExtensionSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class StringExtensionSpec: QuickSpec {
1313
it("should escape the NULL terminator with the 'symbol for null' glyph (U+2400)") {
1414
expect("abc\0".escapingWhitespaces).to(equal("abc␀"))
1515
}
16-
16+
1717
it("should not change the original string if it does not contain whitespaces") {
1818
expect("ReactiveTask").to(equal("ReactiveTask"))
1919
}

Tests/ReactiveTaskTests/TaskSpec.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright (c) 2014 Carthage. All rights reserved.
77
//
88

9+
// swiftlint:disable function_body_length
10+
911
import Foundation
1012
import Nimble
1113
import Quick

0 commit comments

Comments
 (0)