Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered committed Aug 9, 2024
1 parent 9260377 commit cb3a854
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Source/SwiftLintCore/Models/Linter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private extension Rule {
region.isRuleDisabled(self)
}
return [(Self.description.identifier, regionsDisablingCurrentRule)]
}().sorted { (lhs, rhs) -> Bool in // make sure that the results are consistently ordered
}().sorted { lhs, rhs -> Bool in // make sure that the results are consistently ordered
lhs.0 < rhs.0
}

Expand Down
25 changes: 19 additions & 6 deletions Tests/SwiftLintFrameworkTests/CustomRulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertEqual(firstViolation.ruleIdentifier, SuperfluousDisableCommandRule.description.identifier)
XCTAssertTrue(firstViolation.didNotTrigger(for: "custom_rules"))
XCTAssertEqual(secondViolation.ruleIdentifier, SuperfluousDisableCommandRule.description.identifier)
XCTAssertEqual(secondViolation.didNotTrigger(for: "\(customRuleIdentifier)"), true)
XCTAssertTrue(secondViolation.didNotTrigger(for: "\(customRuleIdentifier)"))
}

func testSuperfluousDisableCommandAndViolationWithCustomRules() throws {
Expand All @@ -291,7 +291,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertTrue(secondViolation.didNotTrigger(for: customRuleIdentifier))
}

func testDisablingCustomRulesWorks() throws {
func testDisablingCustomRules() throws {
let customRules: [String: Any] = [
"forbidden": [
"regex": "FORBIDDEN",
Expand All @@ -307,7 +307,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertTrue(violations.isEmpty)
}

func testSuperfluousCommandWorksForCustomRulesWorks() throws {
func testSuperfluousCommandWorksForCustomRules() throws {
let customRules = getForbiddenCustomRules()
let example = Example("""
// swiftlint:disable:next custom_rules
Expand All @@ -318,7 +318,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertEqual(violations.count, 1)
}

func someOtherTest2() throws {
func testSuperfluousCommandWorksForSpecificCustomRules() throws {
let customRules = getForbiddenCustomRules()
let example = Example("""
// swiftlint:disable:next forbidden forbidden2
Expand All @@ -329,7 +329,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertEqual(violations.count, 2)
}

func someOtherTest3() throws {
func testSuperfluousCommandWorksForSpecificCustomRulesWhenOneCustomRuleIsViolated() throws {
let customRules = getForbiddenCustomRules()
let example = Example("""
// swiftlint:disable:next forbidden forbidden2
Expand All @@ -340,7 +340,7 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertEqual(violations.count, 1)
}

func someOtherTest4() throws {
func testSuperfluousCommandWorksForSpecificAndGeneralCustomRulesWhenOneCustomRuleIsViolated() throws {
let customRules = getForbiddenCustomRules()
let example = Example("""
// swiftlint:disable:next forbidden forbidden2 custom_rules
Expand Down Expand Up @@ -432,6 +432,19 @@ final class CustomRulesTests: SwiftLintTestCase {
XCTAssertTrue(try violations(forExample: example, customRules: customRules).isEmpty)
}

func testDisableAllAndASpecificCustomRule() throws {
let customRules: [String: Any] = [
"dont_print": [
"regex": "print\\("
],
]
let example = Example("""
// swiftlint:disable:next all dont_print
print("Hello, world")
""")
XCTAssertTrue(try violations(forExample: example, customRules: customRules).isEmpty)
}

func testRegionsForCustomRules() {
let file = SwiftLintFile(contents: "// swiftlint:disable custom_rules\n")
XCTAssertFalse(file.regions().first?.isRuleEnabled(CustomRules()) ?? true)
Expand Down

0 comments on commit cb3a854

Please # to comment.