Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from agoda-com/update-custom-rules
Browse files Browse the repository at this point in the history
Update rules
  • Loading branch information
i-pavlov authored Jul 5, 2022
2 parents 10f7636 + 1ffec48 commit 6796df8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct XCTMissingSuperSetUpTearDownRule: OptInRule, ConfigurationProvider
description: "XCTestCase that overrides setUp() or tearDown() methods should call super.",
kind: .idiomatic,
nonTriggeringExamples: [
"""
Example("""
class TestCase: XCTestCase {
override func setUp() {
super.setUp()
Expand All @@ -20,11 +20,11 @@ public struct XCTMissingSuperSetUpTearDownRule: OptInRule, ConfigurationProvider
super.tearDown()
}
}
""",
"""
"""),
Example("""
class TestCase: XCTestCase {}
""",
"""
"""),
Example("""
struct MyStruct {
func setUp() {
print("setUp")
Expand All @@ -33,10 +33,10 @@ public struct XCTMissingSuperSetUpTearDownRule: OptInRule, ConfigurationProvider
print("tearDown")
}
}
"""
""")
],
triggeringExamples: [
"""
Example("""
class TestCase: XCTestCase {
override func ↓setUp() {
print("setUp")
Expand All @@ -50,7 +50,7 @@ public struct XCTMissingSuperSetUpTearDownRule: OptInRule, ConfigurationProvider
override class func ↓tearDown() {
print("tearDown")
}
"""
""")
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct XCTNullifyStoredPropertiesRule: OptInRule, ConfigurationProviderRu
description: "XCTestCase should nullify all stored properties in tearDown().",
kind: .idiomatic,
nonTriggeringExamples: [
"""
Example("""
class TestCase: XCTestCase {
var api: API!
var data: String? = "data"
Expand All @@ -29,10 +29,10 @@ public struct XCTNullifyStoredPropertiesRule: OptInRule, ConfigurationProviderRu
super.tearDown()
}
}
"""
""")
],
triggeringExamples: [
"""
Example("""
class TestCase: XCTestCase {
var ↓api: API!
var data: String? = "data"
Expand All @@ -47,8 +47,8 @@ public struct XCTNullifyStoredPropertiesRule: OptInRule, ConfigurationProviderRu
super.tearDown()
}
}
""",
"""
"""),
Example("""
class TestCase: XCTestCase {
var ↓api: API!
var ↓data: String? = "data"
Expand All @@ -58,8 +58,8 @@ public struct XCTNullifyStoredPropertiesRule: OptInRule, ConfigurationProviderRu
api = API()
}
}
""",
"""
"""),
Example("""
class TestCase: XCTestCase {
var ↓api: API!
var data: String? = "data"
Expand All @@ -70,7 +70,7 @@ public struct XCTNullifyStoredPropertiesRule: OptInRule, ConfigurationProviderRu
super.tearDown()
}
}
"""
""")
]
)

Expand Down Expand Up @@ -113,9 +113,8 @@ public struct XCTNullifyStoredPropertiesRule: OptInRule, ConfigurationProviderRu
extension SwiftLintFile {
func bodyRange(of dictionary: SourceKittenDictionary) -> NSRange? {
guard
let offset = dictionary.bodyOffset,
let length = dictionary.bodyLength,
let range = stringView.byteRangeToNSRange(start: offset, length: length)
let bodyByteRange = dictionary.bodyByteRange,
let range = stringView.byteRangeToNSRange(bodyByteRange)
else {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct XCTResetSharedStateRule: OptInRule, ConfigurationProviderRule, Aut
description: "XCTestCase should reset shared state in tearDown().",
kind: .idiomatic,
nonTriggeringExamples: [
"""
Example("""
class TestCase: XCTestCase {
override func setUp() {
super.setUp()
Expand All @@ -28,8 +28,8 @@ public struct XCTResetSharedStateRule: OptInRule, ConfigurationProviderRule, Aut
MySharedStateComponent.setUp(with: Configuration())
}
}
""",
"""
"""),
Example("""
class TestCase: XCTestCase {
override func setUp() {
super.setUp()
Expand All @@ -41,10 +41,10 @@ public struct XCTResetSharedStateRule: OptInRule, ConfigurationProviderRule, Aut
MySharedStateComponent.setUp()
}
}
"""
""")
],
triggeringExamples: [
"""
Example("""
class TestCase: XCTestCase {
override func setUp() {
super.setUp()
Expand All @@ -55,22 +55,22 @@ public struct XCTResetSharedStateRule: OptInRule, ConfigurationProviderRule, Aut
super.tearDown()
}
}
""",
"""
"""),
Example("""
class TestCase: XCTestCase {
override func setUp() {
super.setUp()
↓MySharedStateComponent.setUp()
}
}
""",
"""
"""),
Example("""
class TestCase: XCTestCase {
func testComponent() {
↓MySharedStateComponent.setUp(with: Configuration())
}
}
"""
""")
]
)

Expand Down

0 comments on commit 6796df8

Please sign in to comment.