mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
82cad0bfff
This allows to infer names of options from their names in a configuration. CamelCase is translated into snake_case automatically when `apply` is triggered. * Don't have all `RuleConfiguration`s conform to `InlinableOptionType`. Mark types that must have this capability explicitly. Same for `AcceptableByConfigurationElement`. * A type being an `InlinableOptionType` doesn't mean it's automatically inlined. This also doesn't depend on the fact of having a name for its key configured any longer. Instead, an `inline` attribute must explicitly be set to `true` in `@ConfigurationElement`. * Key name inference is optional and can be overwritten by specifying a key name in the attribute. * Inlined configurations only fail in `apply` when they are really sure that something is odd. Otherwise, they accept to not being updated.
41 lines
1.4 KiB
Swift
41 lines
1.4 KiB
Swift
/// A configuration value for a rule to allow users to modify its behavior.
|
|
public protocol RuleConfiguration: 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())
|
|
}
|
|
}
|