Skip to content

Commit 9a2af47

Browse files
authored
Merge pull request #147 from Carthage/swiftlint
[lint] Add .swiftlint.yml, .hound.yml and address some violations
2 parents 191b3f7 + b0ecd1c commit 9a2af47

File tree

7 files changed

+53
-38
lines changed

7 files changed

+53
-38
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+
disabled_rules:
6+
- function_body_length
7+
- identifier_name
8+
- line_length
9+
- opening_brace
10+
- operator_whitespace
11+
12+
trailing_comma:
13+
mandatory_comma: true

Sources/Commandant/Command.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import Result
1111

1212
/// Represents a subcommand that can be executed with its own set of arguments.
1313
public protocol CommandProtocol {
14-
14+
1515
/// The command's options type.
1616
associatedtype Options: OptionsProtocol
1717

1818
associatedtype ClientError where ClientError == Options.ClientError
19-
19+
2020
/// The action that users should specify to use this subcommand (e.g.,
2121
/// `help`).
2222
var verb: String { get }
@@ -33,9 +33,9 @@ public protocol CommandProtocol {
3333
public struct CommandWrapper<ClientError: Error> {
3434
public let verb: String
3535
public let function: String
36-
36+
3737
public let run: (ArgumentParser) -> Result<(), CommandantError<ClientError>>
38-
38+
3939
public let usage: () -> CommandantError<ClientError>?
4040

4141
/// Creates a command that wraps another.
@@ -134,10 +134,10 @@ extension CommandRegistry {
134134
/// If a matching command could not be found or a usage error occurred,
135135
/// a helpful error message will be written to `stderr`, then the process
136136
/// will exit with a failure error code.
137-
public func main(defaultVerb: String, errorHandler: (ClientError) -> ()) -> Never {
137+
public func main(defaultVerb: String, errorHandler: (ClientError) -> Void) -> Never {
138138
main(arguments: CommandLine.arguments, defaultVerb: defaultVerb, errorHandler: errorHandler)
139139
}
140-
140+
141141
/// Hands off execution to the CommandRegistry, by parsing `arguments`
142142
/// and then running whichever command has been identified in the argument
143143
/// list.
@@ -155,7 +155,7 @@ extension CommandRegistry {
155155
/// If a matching command could not be found or a usage error occurred,
156156
/// a helpful error message will be written to `stderr`, then the process
157157
/// will exit with a failure error code.
158-
public func main(arguments: [String], defaultVerb: String, errorHandler: (ClientError) -> ()) -> Never {
158+
public func main(arguments: [String], defaultVerb: String, errorHandler: (ClientError) -> Void) -> Never {
159159
assert(arguments.count >= 1)
160160

161161
var arguments = arguments
@@ -170,7 +170,7 @@ extension CommandRegistry {
170170
// Remove the command name.
171171
arguments.remove(at: 0)
172172
}
173-
173+
174174
switch run(command: verb, arguments: arguments) {
175175
case .success?:
176176
exit(EXIT_SUCCESS)

Sources/Commandant/HelpCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct HelpCommand<ClientError: Error>: CommandProtocol {
2323

2424
public let verb = "help"
2525
public let function: String
26-
26+
2727
private let registry: CommandRegistry<ClientError>
2828

2929
/// Initializes the command to provide help from the given registry of
@@ -61,7 +61,7 @@ public struct HelpCommand<ClientError: Error>: CommandProtocol {
6161

6262
public struct HelpOptions<ClientError: Error>: OptionsProtocol {
6363
fileprivate let verb: String?
64-
64+
6565
private init(verb: String?) {
6666
self.verb = verb
6767
}

Sources/Commandant/Option.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public protocol OptionsProtocol {
4747
/// An `OptionsProtocol` that has no options.
4848
public struct NoOptions<ClientError: Error>: OptionsProtocol {
4949
public init() {}
50-
50+
5151
public static func evaluate(_ m: CommandMode) -> Result<NoOptions, CommandantError<ClientError>> {
5252
return .success(NoOptions())
5353
}
@@ -184,7 +184,7 @@ extension CommandMode {
184184
if let value = T.from(string: stringValue) {
185185
return .success(value)
186186
}
187-
187+
188188
let description = "Invalid value for '--\(key)': \(stringValue)"
189189
return .failure(.usageError(description: description))
190190
} else {

Tests/CommandantTests/OptionSpec.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,34 @@ class OptionsProtocolSpec: QuickSpec {
3535

3636
it("should succeed with some strings array arguments separated by comma") {
3737
let value = tryArguments("required", "--intValue", "3", "--optionalStringValue", "baz", "fuzzbuzz", "--stringsArray", "a,b,c").value
38-
let expected = TestOptions(intValue: 3, stringValue: "foobar", stringsArray: ["a","b","c"], optionalStringsArray: nil, optionalStringValue: "baz", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
38+
let expected = TestOptions(intValue: 3, stringValue: "foobar", stringsArray: ["a", "b", "c"], optionalStringsArray: nil, optionalStringValue: "baz", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
3939
expect(value).to(equal(expected))
4040
}
41-
41+
4242
it("should succeed with some strings array arguments separated by space") {
4343
let value = tryArguments("required", "--intValue", "3", "--optionalStringValue", "baz", "--stringsArray", "a b c", "fuzzbuzz").value
4444
let expected = TestOptions(intValue: 3, stringValue: "foobar", stringsArray: ["a", "b", "c"], optionalStringsArray: nil, optionalStringValue: "baz", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
4545
expect(value).to(equal(expected))
4646
}
47-
47+
4848
it("should succeed with some strings array arguments separated by comma and space") {
4949
let value = tryArguments("required", "--intValue", "3", "--optionalStringValue", "baz", "--stringsArray", "a, b, c", "fuzzbuzz").value
5050
let expected = TestOptions(intValue: 3, stringValue: "foobar", stringsArray: ["a", "b", "c"], optionalStringsArray: nil, optionalStringValue: "baz", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
5151
expect(value).to(equal(expected))
5252
}
53-
53+
5454
it("should succeed with some optional string arguments") {
5555
let value = tryArguments("required", "--intValue", "3", "--optionalStringValue", "baz", "fuzzbuzz").value
5656
let expected = TestOptions(intValue: 3, stringValue: "foobar", stringsArray: [], optionalStringsArray: nil, optionalStringValue: "baz", optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
5757
expect(value).to(equal(expected))
5858
}
59-
59+
6060
it("should succeed without optional array arguments") {
6161
let value = tryArguments("required").value
6262
let expected = TestOptions(intValue: 42, stringValue: "foobar", stringsArray: [], optionalStringsArray: nil, optionalStringValue: nil, optionalFilename: "filename", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
6363
expect(value).to(equal(expected))
6464
}
65-
65+
6666
it("should succeed with some optional array arguments") {
6767
let value = tryArguments("required", "--intValue", "3", "--optionalStringsArray", "one, two", "fuzzbuzz").value
6868
let expected = TestOptions(intValue: 3, stringValue: "foobar", stringsArray: [], optionalStringsArray: ["one", "two"], optionalStringValue: nil, optionalFilename: "fuzzbuzz", requiredName: "required", enabled: false, force: false, glob: false, arguments: [])
@@ -178,7 +178,7 @@ func ==(lhs: TestOptions, rhs: TestOptions) -> Bool {
178178
}
179179

180180
func ==<T: Equatable>(lhs: [T]?, rhs: [T]?) -> Bool {
181-
switch (lhs,rhs) {
181+
switch (lhs, rhs) {
182182
case let (lhs?, rhs?):
183183
return lhs == rhs
184184
case (nil, nil):

Tests/CommandantTests/OptionsWithEnumProtocolSpec.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class OptionsWithEnumProtocolSpec: QuickSpec {
1818
func tryArguments(_ arguments: String...) -> Result<TestEnumOptions, CommandantError<NoError>> {
1919
return TestEnumOptions.evaluate(.arguments(ArgumentParser(arguments)))
2020
}
21-
21+
2222
it("should fail if a required argument is missing") {
2323
expect(tryArguments().value).to(beNil())
2424
}
@@ -30,78 +30,78 @@ class OptionsWithEnumProtocolSpec: QuickSpec {
3030
it("should fail if an option is missing a value") {
3131
expect(tryArguments("required", "--strictStringValue", "drop").value).to(beNil())
3232
}
33-
33+
3434
it("should fail if an optional strict int parameter is wrong") {
3535
expect(tryArguments("required", "256").value).to(beNil())
3636
}
37-
37+
3838
it("should succeed without optional string arguments") {
3939
let value = tryArguments("required").value
4040
let expected = TestEnumOptions(strictIntValue: .theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: nil, optionalStrictInt: .min, requiredName: "required", arguments: [])
4141
expect(value).to(equal(expected))
4242
}
43-
43+
4444
it("should succeed without optional strict int value") {
4545
let value = tryArguments("required", "5").value
4646
let expected = TestEnumOptions(strictIntValue: .theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: nil, optionalStrictInt: .giveFive, requiredName: "required", arguments: [])
4747
expect(value).to(equal(expected))
4848
}
49-
49+
5050
it("should succeed with some strings array arguments separated by comma") {
5151
let value = tryArguments("required", "--strictIntValue", "3", "--optionalStrictStringValue", "baz", "255", "--strictStringsArray", "a,b,c").value
5252
let expected = TestEnumOptions(strictIntValue: .three, strictStringValue: .foobar, strictStringsArray: [.a, .b, .c], optionalStrictStringsArray: nil, optionalStrictStringValue: .baz, optionalStrictInt: .max, requiredName: "required", arguments: [])
5353
expect(value).to(equal(expected))
5454
}
55-
55+
5656
it("should succeed with some strings array arguments separated by space") {
5757
let value = tryArguments("required", "--strictIntValue", "3", "--optionalStrictStringValue", "baz", "--strictStringsArray", "a b c", "255").value
5858
let expected = TestEnumOptions(strictIntValue: .three, strictStringValue: .foobar, strictStringsArray: [.a, .b, .c], optionalStrictStringsArray: nil, optionalStrictStringValue: .baz, optionalStrictInt: .max, requiredName: "required", arguments: [])
5959
expect(value).to(equal(expected))
6060
}
61-
61+
6262
it("should succeed with some strings array arguments separated by comma and space") {
6363
let value = tryArguments("required", "--strictIntValue", "3", "--optionalStrictStringValue", "baz", "--strictStringsArray", "a, b, c", "255").value
6464
let expected = TestEnumOptions(strictIntValue: .three, strictStringValue: .foobar, strictStringsArray: [.a, .b, .c], optionalStrictStringsArray: nil, optionalStrictStringValue: .baz, optionalStrictInt: .max, requiredName: "required", arguments: [])
6565
expect(value).to(equal(expected))
6666
}
67-
67+
6868
it("should succeed with some optional string arguments") {
6969
let value = tryArguments("required", "--strictIntValue", "3", "--optionalStrictStringValue", "baz", "255").value
7070
let expected = TestEnumOptions(strictIntValue: .three, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: .baz, optionalStrictInt: .max, requiredName: "required", arguments: [])
7171
expect(value).to(equal(expected))
7272
}
73-
73+
7474
it("should succeed without optional array arguments") {
7575
let value = tryArguments("required").value
7676
let expected = TestEnumOptions(strictIntValue: .theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: nil, optionalStrictInt: .min, requiredName: "required", arguments: [])
7777
expect(value).to(equal(expected))
7878
}
79-
79+
8080
it("should succeed with some optional array arguments") {
8181
let value = tryArguments("required", "--strictIntValue", "3", "--optionalStrictStringsArray", "one, two", "255").value
8282
let expected = TestEnumOptions(strictIntValue: .three, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: [.one, .two], optionalStrictStringValue: nil, optionalStrictInt: .max, requiredName: "required", arguments: [])
8383
expect(value).to(equal(expected))
8484
}
85-
85+
8686
it("should override previous optional arguments") {
8787
let value = tryArguments("required", "--strictIntValue", "3", "--strictStringValue", "fuzzbuzz", "--strictIntValue", "5", "--strictStringValue", "bazbuzz").value
8888
let expected = TestEnumOptions(strictIntValue: .giveFive, strictStringValue: .bazbuzz, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: nil, optionalStrictInt: .min, requiredName: "required", arguments: [])
8989
expect(value).to(equal(expected))
9090
}
91-
91+
9292
it("should consume the rest of positional arguments") {
9393
let value = tryArguments("required", "255", "value1", "value2").value
9494
let expected = TestEnumOptions(strictIntValue: .theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: nil, optionalStrictInt: .max, requiredName: "required", arguments: [ "value1", "value2" ])
9595
expect(value).to(equal(expected))
9696
}
97-
97+
9898
it("should treat -- as the end of valued options") {
9999
let value = tryArguments("--", "--strictIntValue").value
100100
let expected = TestEnumOptions(strictIntValue: .theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, strictStringValue: .foobar, strictStringsArray: [], optionalStrictStringsArray: nil, optionalStrictStringValue: nil, optionalStrictInt: .min, requiredName: "--strictIntValue", arguments: [])
101101
expect(value).to(equal(expected))
102102
}
103103
}
104-
104+
105105
describe("CommandMode.Usage") {
106106
it("should return an error containing usage information") {
107107
let error = TestEnumOptions.evaluate(.usage).error
@@ -123,15 +123,15 @@ struct TestEnumOptions: OptionsProtocol, Equatable {
123123
let optionalStrictInt: StrictIntValue
124124
let requiredName: String
125125
let arguments: [String]
126-
126+
127127
typealias ClientError = NoError
128-
128+
129129
static func create(_ a: StrictIntValue) -> (StrictStringValue) -> ([StrictStringValue]) -> ([StrictStringValue]?) -> (StrictStringValue?) -> (String) -> (StrictIntValue) -> ([String]) -> TestEnumOptions {
130130
return { b in { c in { d in { e in { f in { g in { h in
131131
return self.init(strictIntValue: a, strictStringValue: b, strictStringsArray: c, optionalStrictStringsArray: d, optionalStrictStringValue: e, optionalStrictInt: g, requiredName: f, arguments: h)
132132
} } } } } } }
133133
}
134-
134+
135135
static func evaluate(_ m: CommandMode) -> Result<TestEnumOptions, CommandantError<NoError>> {
136136
return create
137137
<*> m <| Option(key: "strictIntValue", defaultValue: .theAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything, usage: "`0` - zero, `255` - max, `3` - three, `5` - five or `42` - The Answer")
@@ -157,7 +157,7 @@ extension TestEnumOptions: CustomStringConvertible {
157157

158158
enum StrictStringValue: String, ArgumentProtocol {
159159
static var name: String = "Strict string value: `foobar`, `bazbuzz`, `one`, `two`, `baz`, `a`, `b` or `c`"
160-
160+
161161
case foobar
162162
case bazbuzz
163163
case one
@@ -170,7 +170,7 @@ enum StrictStringValue: String, ArgumentProtocol {
170170

171171
enum StrictIntValue: UInt8, ArgumentProtocol {
172172
static var name: String = "Strict int value: `3`, `5`, `42`, `0`, `255`"
173-
173+
174174
case min = 0
175175
case three = 3
176176
case giveFive = 5

0 commit comments

Comments
 (0)