Files
SwiftLint/Source/SwiftLintCore/Protocols/RuleConfiguration.swift
2023-10-03 18:05:31 +02:00

41 lines
1.5 KiB
Swift

/// A configuration value for a rule to allow users to modify its behavior.
public protocol RuleConfiguration: InlinableOptionType, Equatable {
/// The type of the rule that's using this configuration.
associatedtype Parent: Rule
/// A description for this configuration's parameters. It can be built using the annotated result builder.
@RuleConfigurationDescriptionBuilder
var parameterDescription: RuleConfigurationDescription? { 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
}
/// 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 {
var parameterDescription: RuleConfigurationDescription? { nil }
}
public extension RuleConfiguration {
/// All keys supported by this configuration.
var supportedKeys: Set<String> {
Set(RuleConfigurationDescription.from(configuration: self).allowedKeys())
}
}