mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
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.
42 lines
1.6 KiB
Swift
42 lines
1.6 KiB
Swift
/// A configuration value for a rule to allow users to modify its behavior.
|
|
public protocol RuleConfiguration<Parent> {
|
|
/// The type of the rule that's using this configuration.
|
|
associatedtype Parent: Rule
|
|
|
|
/// A human-readable description for this configuration and its applied values.
|
|
var consoleDescription: String { get }
|
|
|
|
/// Apply an untyped configuration to the current value.
|
|
///
|
|
/// - parameter configuration: The untyped configuration value to apply.
|
|
///
|
|
/// - throws: Throws if the configuration is not in the expected format.
|
|
mutating func apply(configuration: Any) throws
|
|
|
|
/// Whether the specified configuration is equivalent to the current value.
|
|
///
|
|
/// - parameter ruleConfiguration: The rule configuration to compare against.
|
|
///
|
|
/// - returns: Whether the specified configuration is equivalent to the current value.
|
|
func isEqualTo(_ ruleConfiguration: some RuleConfiguration) -> Bool
|
|
}
|
|
|
|
/// A configuration for a rule that allows to configure at least the severity.
|
|
public protocol SeverityBasedRuleConfiguration: RuleConfiguration {
|
|
/// The configuration of a rule's severity.
|
|
var severityConfiguration: SeverityConfiguration<Parent> { get }
|
|
}
|
|
|
|
public extension SeverityBasedRuleConfiguration {
|
|
/// The severity of a rule.
|
|
var severity: ViolationSeverity {
|
|
severityConfiguration.severity
|
|
}
|
|
}
|
|
|
|
public extension RuleConfiguration where Self: Equatable {
|
|
func isEqualTo(_ ruleConfiguration: some RuleConfiguration) -> Bool {
|
|
return self == ruleConfiguration as? Self
|
|
}
|
|
}
|