Skip to content

Commit

Permalink
Added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered committed Sep 15, 2024
1 parent 76f4609 commit 57511ee
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Tests/SwiftLintFrameworkTests/CustomRulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertTrue(try violations(forExample: example, customRules: customRules).isEmpty)
}

func testNestedCustomRuleDoNotTriggerSuperfluousDisableCommand() throws {
func testNestedCustomRuleDisablesDoNotTriggerSuperfluousDisableCommand() throws {
let customRules: [String: Any] = [
"rule1": [
"regex": "pattern1"
Expand All @@ -447,6 +447,34 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertTrue(try violations(forExample: example, customRules: customRules).isEmpty)
}

func testNestedAndOverlappingCustomRuleDisables() throws {
let customRules: [String: Any] = [
"rule1": [
"regex": "pattern1"
],
"rule2": [
"regex": "pattern2"
],
"rule3": [
"regex": "pattern3"
],
]
let example = Example("""
// swiftlint:disable rule1
// swiftlint:disable rule2
// swiftlint:disable rule3
let pattern2 = ""
// swiftlint:enable rule2
// swiftlint:enable rule3
let pattern1 = ""
// swiftlint:enable rule1
""")
let violations = try violations(forExample: example, customRules: customRules)

XCTAssertEqual(violations.count, 1)
XCTAssertTrue(violations[0].isSuperfluousDisableCommandViolation(for: "rule3"))
}

// MARK: - Private

private func getCustomRules(_ extraConfig: [String: Any] = [:]) -> (Configuration, CustomRules) {
Expand Down

0 comments on commit 57511ee

Please sign in to comment.