Files
SwiftLint/Source/SwiftLintBuiltInRules/Rules/RuleConfigurations/TrailingWhitespaceConfiguration.swift
T
Danny MöschandGitHub 3f039f26d5 Connect configs with their referencing rules to have some context in error logging (#5017)
With the binding of configurations to their associated rule types
"unknown configuration" errors can be made more specific mentioning
also the rule's identifier in the printed message.
2023-05-19 20:58:24 +02:00

27 lines
1.0 KiB
Swift

struct TrailingWhitespaceConfiguration: SeverityBasedRuleConfiguration, Equatable {
typealias Parent = TrailingWhitespaceRule
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
private(set) var ignoresEmptyLines = false
private(set) var ignoresComments = true
var consoleDescription: String {
return "severity: \(severityConfiguration.consoleDescription)" +
", ignores_empty_lines: \(ignoresEmptyLines)" +
", ignores_comments: \(ignoresComments)"
}
mutating func apply(configuration: Any) throws {
guard let configuration = configuration as? [String: Any] else {
throw Issue.unknownConfiguration(ruleID: Parent.identifier)
}
ignoresEmptyLines = (configuration["ignores_empty_lines"] as? Bool == true)
ignoresComments = (configuration["ignores_comments"] as? Bool == true)
if let severityString = configuration["severity"] as? String {
try severityConfiguration.apply(configuration: severityString)
}
}
}