From 15cdfc042c3613b449d4b815c6603bbd733ffaae Mon Sep 17 00:00:00 2001 From: IKEDA Sho Date: Fri, 22 May 2020 00:33:05 +0900 Subject: [PATCH] [SwiftLint] Enable line_length rule --- .swiftlint.yml | 5 ++++- Sources/Quick/Behavior.swift | 6 ++---- Sources/Quick/DSL/DSL.swift | 4 ++++ Sources/Quick/DSL/World+DSL.swift | 19 ++++++++++--------- Sources/Quick/World.swift | 7 +++++-- Tests/.swiftlint.yml | 1 + .../FunctionalTests/AfterEachTests.swift | 2 +- .../FunctionalTests/BeforeEachTests.swift | 2 +- .../FunctionalTests/BehaviorTests.swift | 2 +- .../FunctionalTests/ContextTests.swift | 2 +- .../FunctionalTests/DescribeTests.swift | 2 +- .../QuickTests/FunctionalTests/ItTests.swift | 6 +++--- .../FunctionalTests/SharedExamplesTests.swift | 2 +- 13 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index f834a1754..ac96db3d5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,5 +1,8 @@ disabled_rules: - - line_length included: - Sources - Tests + +line_length: + warning: 160 + error: 240 diff --git a/Sources/Quick/Behavior.swift b/Sources/Quick/Behavior.swift index da301a1db..7a25a36c8 100644 --- a/Sources/Quick/Behavior.swift +++ b/Sources/Quick/Behavior.swift @@ -1,7 +1,5 @@ -/** - A `Behavior` encapsulates a set of examples that can be re-used in several locations using the `itBehavesLike` function with a context instance of the generic type. - */ - +/// A `Behavior` encapsulates a set of examples that can be re-used in several locations using the `itBehavesLike` +/// function with a context instance of the generic type. open class Behavior { /** diff --git a/Sources/Quick/DSL/DSL.swift b/Sources/Quick/DSL/DSL.swift index 3093e1ed6..7a9766aa0 100644 --- a/Sources/Quick/DSL/DSL.swift +++ b/Sources/Quick/DSL/DSL.swift @@ -1,3 +1,5 @@ +// swiftlint:disable line_length + /** Defines a closure to be run prior to any examples in the test suite. You may define an unlimited number of these closures, but there is no @@ -269,3 +271,5 @@ public func fitBehavesLike(_ name: String, flags: FilterFlags = [:], file: FileS public func fitBehavesLike(_ behavior: Behavior.Type, flags: FilterFlags = [:], file: FileString = #file, line: UInt = #line, context: @escaping () -> C) { World.sharedWorld.fitBehavesLike(behavior, context: context, flags: flags, file: file, line: line) } + +// swiftlint:enable line_length diff --git a/Sources/Quick/DSL/World+DSL.swift b/Sources/Quick/DSL/World+DSL.swift index 14dcdbf45..957023eee 100644 --- a/Sources/Quick/DSL/World+DSL.swift +++ b/Sources/Quick/DSL/World+DSL.swift @@ -20,9 +20,10 @@ extension World { internal func describe(_ description: String, flags: FilterFlags, closure: () -> Void) { guard currentExampleMetadata == nil else { - raiseError("'describe' cannot be used inside '\(currentPhase)', 'describe' may only be used inside 'context' or 'describe'. ") + raiseError("'describe' cannot be used inside '\(currentPhase)', 'describe' may only be used inside 'context' or 'describe'.") } guard currentExampleGroup != nil else { + // swiftlint:disable:next line_length raiseError("Error: example group was not created by its parent QuickSpec spec. Check that describe() or context() was used in QuickSpec.spec() and not a more general context (i.e. an XCTestCase test)") } let group = ExampleGroup(description: description, flags: flags) @@ -32,7 +33,7 @@ extension World { internal func context(_ description: String, flags: FilterFlags, closure: () -> Void) { guard currentExampleMetadata == nil else { - raiseError("'context' cannot be used inside '\(currentPhase)', 'context' may only be used inside 'context' or 'describe'. ") + raiseError("'context' cannot be used inside '\(currentPhase)', 'context' may only be used inside 'context' or 'describe'.") } self.describe(description, flags: flags, closure: closure) } @@ -51,7 +52,7 @@ extension World { internal func beforeEach(_ closure: @escaping BeforeExampleClosure) { guard currentExampleMetadata == nil else { - raiseError("'beforeEach' cannot be used inside '\(currentPhase)', 'beforeEach' may only be used inside 'context' or 'describe'. ") + raiseError("'beforeEach' cannot be used inside '\(currentPhase)', 'beforeEach' may only be used inside 'context' or 'describe'.") } currentExampleGroup.hooks.appendBefore(closure) } @@ -69,7 +70,7 @@ extension World { internal func afterEach(_ closure: @escaping AfterExampleClosure) { guard currentExampleMetadata == nil else { - raiseError("'afterEach' cannot be used inside '\(currentPhase)', 'afterEach' may only be used inside 'context' or 'describe'. ") + raiseError("'afterEach' cannot be used inside '\(currentPhase)', 'afterEach' may only be used inside 'context' or 'describe'.") } currentExampleGroup.hooks.appendAfter(closure) } @@ -88,13 +89,13 @@ extension World { @nonobjc internal func it(_ description: String, flags: FilterFlags, file: FileString, line: UInt, closure: @escaping () -> Void) { if beforesCurrentlyExecuting { - raiseError("'it' cannot be used inside 'beforeEach', 'it' may only be used inside 'context' or 'describe'. ") + raiseError("'it' cannot be used inside 'beforeEach', 'it' may only be used inside 'context' or 'describe'.") } if aftersCurrentlyExecuting { - raiseError("'it' cannot be used inside 'afterEach', 'it' may only be used inside 'context' or 'describe'. ") + raiseError("'it' cannot be used inside 'afterEach', 'it' may only be used inside 'context' or 'describe'.") } guard currentExampleMetadata == nil else { - raiseError("'it' cannot be used inside 'it', 'it' may only be used inside 'context' or 'describe'. ") + raiseError("'it' cannot be used inside 'it', 'it' may only be used inside 'context' or 'describe'.") } let callsite = Callsite(file: file, line: line) let example = Example(description: description, callsite: callsite, flags: flags, closure: closure) @@ -118,7 +119,7 @@ extension World { @nonobjc internal func itBehavesLike(_ name: String, sharedExampleContext: @escaping SharedExampleContext, flags: FilterFlags, file: FileString, line: UInt) { guard currentExampleMetadata == nil else { - raiseError("'itBehavesLike' cannot be used inside '\(currentPhase)', 'itBehavesLike' may only be used inside 'context' or 'describe'. ") + raiseError("'itBehavesLike' cannot be used inside '\(currentPhase)', 'itBehavesLike' may only be used inside 'context' or 'describe'.") } let callsite = Callsite(file: file, line: line) let closure = World.sharedWorld.sharedExample(name) @@ -144,7 +145,7 @@ extension World { internal func itBehavesLike(_ behavior: Behavior.Type, context: @escaping () -> C, flags: FilterFlags, file: FileString, line: UInt) { guard currentExampleMetadata == nil else { - raiseError("'itBehavesLike' cannot be used inside '\(currentPhase)', 'itBehavesLike' may only be used inside 'context' or 'describe'. ") + raiseError("'itBehavesLike' cannot be used inside '\(currentPhase)', 'itBehavesLike' may only be used inside 'context' or 'describe'.") } let callsite = Callsite(file: file, line: line) let closure = behavior.spec diff --git a/Sources/Quick/World.swift b/Sources/Quick/World.swift index 05109e7e7..5b11436cc 100644 --- a/Sources/Quick/World.swift +++ b/Sources/Quick/World.swift @@ -98,8 +98,11 @@ final internal class World: _WorldBase { be mutated to change Quick's behavior. */ internal func configure(_ closure: QuickConfigurer) { - assert(!isConfigurationFinalized, - "Quick cannot be configured outside of a +[QuickConfiguration configure:] method. You should not call -[World configure:] directly. Instead, subclass QuickConfiguration and override the +[QuickConfiguration configure:] method.") + assert( + !isConfigurationFinalized, + // swiftlint:disable:next line_length + "Quick cannot be configured outside of a +[QuickConfiguration configure:] method. You should not call -[World configure:] directly. Instead, subclass QuickConfiguration and override the +[QuickConfiguration configure:] method." + ) closure(configuration) } diff --git a/Tests/.swiftlint.yml b/Tests/.swiftlint.yml index 311cdc7cc..e7477749a 100644 --- a/Tests/.swiftlint.yml +++ b/Tests/.swiftlint.yml @@ -1,4 +1,5 @@ disabled_rules: - function_body_length - identifier_name + - line_length - type_name diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/AfterEachTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/AfterEachTests.swift index f6b6777b2..bb1e5703a 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/AfterEachTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/AfterEachTests.swift @@ -57,7 +57,7 @@ class FunctionalTests_AfterEachSpec: QuickSpec { afterEach { } }.to(raiseException { (exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'afterEach' cannot be used inside 'it', 'afterEach' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'afterEach' cannot be used inside 'it', 'afterEach' may only be used inside 'context' or 'describe'.")) }) } } diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/BeforeEachTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/BeforeEachTests.swift index 17b222e6b..0a99c5592 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/BeforeEachTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/BeforeEachTests.swift @@ -42,7 +42,7 @@ class FunctionalTests_BeforeEachSpec: QuickSpec { beforeEach { } }.to(raiseException { (exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'beforeEach' cannot be used inside 'it', 'beforeEach' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'beforeEach' cannot be used inside 'it', 'beforeEach' may only be used inside 'context' or 'describe'.")) }) } } diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift index 54bcb4231..7615fbb63 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/BehaviorTests.swift @@ -27,7 +27,7 @@ class FunctionalTests_BehaviorTests_ErrorSpec: QuickSpec { } .to(raiseException {(exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'itBehavesLike' cannot be used inside 'it', 'itBehavesLike' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'itBehavesLike' cannot be used inside 'it', 'itBehavesLike' may only be used inside 'context' or 'describe'.")) }) } } diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/ContextTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/ContextTests.swift index eb6c03a2e..20d08467d 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/ContextTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/ContextTests.swift @@ -11,7 +11,7 @@ class QuickContextTests: QuickSpec { context("A nested context that should throw") { } }.to(raiseException { (exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'context' cannot be used inside 'it', 'context' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'context' cannot be used inside 'it', 'context' may only be used inside 'context' or 'describe'.")) }) } } diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/DescribeTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/DescribeTests.swift index a923f4db2..9481f291e 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/DescribeTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/DescribeTests.swift @@ -24,7 +24,7 @@ class QuickDescribeTests: QuickSpec { describe("A nested describe that should throw") { } }.to(raiseException { (exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'describe' cannot be used inside 'it', 'describe' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'describe' cannot be used inside 'it', 'describe' may only be used inside 'context' or 'describe'.")) }) } } diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/ItTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/ItTests.swift index 762a45d3b..bbf88c810 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/ItTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/ItTests.swift @@ -59,7 +59,7 @@ class FunctionalTests_ItSpec: QuickSpec { it("will throw an error when it is nested in another it") { } }.to(raiseException { (exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'it' cannot be used inside 'it', 'it' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'it' cannot be used inside 'it', 'it' may only be used inside 'context' or 'describe'.")) }) } @@ -79,7 +79,7 @@ class FunctionalTests_ItSpec: QuickSpec { it("should have thrown an exception with the correct error message") { expect(exception).toNot(beNil()) - expect(exception!.reason).to(equal("'it' cannot be used inside 'beforeEach', 'it' may only be used inside 'context' or 'describe'. ")) + expect(exception!.reason).to(equal("'it' cannot be used inside 'beforeEach', 'it' may only be used inside 'context' or 'describe'.")) } } @@ -90,7 +90,7 @@ class FunctionalTests_ItSpec: QuickSpec { let capture = NMBExceptionCapture(handler: ({ e in exception = e expect(exception).toNot(beNil()) - expect(exception!.reason).to(equal("'it' cannot be used inside 'afterEach', 'it' may only be used inside 'context' or 'describe'. ")) + expect(exception!.reason).to(equal("'it' cannot be used inside 'afterEach', 'it' may only be used inside 'context' or 'describe'.")) }), finally: nil) capture.tryBlock { diff --git a/Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift b/Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift index f75f5245e..128bad427 100644 --- a/Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift +++ b/Tests/QuickTests/QuickTests/FunctionalTests/SharedExamplesTests.swift @@ -24,7 +24,7 @@ class FunctionalTests_SharedExamples_ErrorSpec: QuickSpec { itBehavesLike("a group of three shared examples") }.to(raiseException { (exception: NSException) in expect(exception.name).to(equal(NSExceptionName.internalInconsistencyException)) - expect(exception.reason).to(equal("'itBehavesLike' cannot be used inside 'it', 'itBehavesLike' may only be used inside 'context' or 'describe'. ")) + expect(exception.reason).to(equal("'itBehavesLike' cannot be used inside 'it', 'itBehavesLike' may only be used inside 'context' or 'describe'.")) }) } }