Skip to content

Commit

Permalink
Verify that severity can be configured per rule (#5985)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Jan 31, 2025
1 parent 6ba231a commit a4893f6
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Tests/TestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ public extension XCTestCase {
testMultiByteOffsets: testMultiByteOffsets)
}

// swiftlint:disable:next function_body_length
func verifyLint(_ ruleDescription: RuleDescription,
config: Configuration,
commentDoesntViolate: Bool = true,
Expand All @@ -376,8 +377,11 @@ public extension XCTestCase {
violations(example, config: config, requiresFileOnDisk: ruleDescription.requiresFileOnDisk)
}

let ruleDescription = ruleDescription.focused()
let (triggers, nonTriggers) = (ruleDescription.triggeringExamples, ruleDescription.nonTriggeringExamples)
let focusedRuleDescription = ruleDescription.focused()
let (triggers, nonTriggers) = (
focusedRuleDescription.triggeringExamples,
focusedRuleDescription.nonTriggeringExamples
)
verify(triggers: triggers, nonTriggers: nonTriggers)

if testMultiByteOffsets {
Expand Down Expand Up @@ -432,6 +436,27 @@ public extension XCTestCase {
line: trigger.line)
}
}

// Severity can be changed
let ruleType = RuleRegistry.shared.rule(forID: ruleDescription.identifier)
if ruleType?.init().configuration is (any SeverityBasedRuleConfiguration),
let example = triggers.first(where: { $0.configuration == nil }) {
let withWarning = Example(example.code, configuration: ["severity": "warning"])
XCTAssert(
violations(withWarning, config: config).allSatisfy { $0.severity == .warning },
"Violation severity cannot be changed to warning",
file: example.file,
line: 1
)

let withError = Example(example.code, configuration: ["severity": "error"])
XCTAssert(
violations(withError, config: config).allSatisfy { $0.severity == .error },
"Violation severity cannot be changed to error",
file: example.file,
line: 1
)
}
}

func verifyCorrections(_ ruleDescription: RuleDescription,
Expand Down

0 comments on commit a4893f6

Please sign in to comment.