ConfigurationElement
@propertyWrapper
public struct ConfigurationElement<T> : Equatable, Sendable where T : Equatable, T : Sendable, T : AcceptableByConfigurationElement
A single parameter of a rule configuration.
Apply it to a simple (e.g. boolean) property like
@ConfigurationElement
var property = true
to add a (boolean) option to a configuration. The name of the option will be inferred from the name of the property.
In this case, it’s just property. CamelCase names will translated into snake_case, i.e. myOption is going to be
translated into my_option in the .swiftlint.yml configuration file.
This mechanism may be overwritten with an explicitly set key:
@ConfigurationElement(key: "foo_bar")
var property = true
If the wrapped element is an InlinableOptionType, there are three ways to represent it in the documentation:
- It can be inlined into the parent configuration. For that, add the parameter
inline: true. E.g.swift @ConfigurationElement(inline: true) var levels = SeverityLevelsConfiguration(warning: 1, error: 2)will be documented as a linear list:warning: 1 error: 2 - It can be represented as a separate nested configuration. In this case, it must not have set the
inlineflag totrue. E.g.swift @ConfigurationElement var levels = SeverityLevelsConfiguration(warning: 1, error: 2)will have a nested configuration section:levels: warning: 1 error: 2 - As mentioned in the beginning, the implicit key inference mechanism can be overruled by specifying a
keyas in:swift @ConfigurationElement(key: "foo") var levels = SeverityLevelsConfiguration(warning: 1, error: 2)It will appear in the documentation as:foo: warning: 1 error: 2
-
A deprecation notice.
See moreDeclaration
Swift
public enum DeprecationNotice : Sendable -
Wrapped option value.
Declaration
Swift
public var wrappedValue: T { get set } -
The wrapper itself providing access to all its data. This field can only be accessed by the element’s name prefixed with a
$.Declaration
Swift
public var projectedValue: `Self` { get set } -
Name of this configuration entry.
Declaration
Swift
public var key: String -
Whether this configuration element will be inlined into its description.
Declaration
Swift
public let inline: Bool -
Default constructor.
Declaration
Swift
@preconcurrency public init(wrappedValue value: T, key: String, deprecationNotice: DeprecationNotice? = nil, postprocessor: @escaping @Sendable (inout T) -> Void = { _ in })Parameters
valueValue to be wrapped.
keyOptional name of the option. If not specified, it will be inferred from the attributed property.
deprecationNoticeAn optional deprecation notice in case an option is outdated and/or has been replaced by an alternative.
postprocessorFunction to be applied to the wrapped value after parsing to validate and modify it.
-
Constructor for optional values.
It allows to skip explicit initialization of the property with
nil.Declaration
Swift
public init<Wrapped>(key: String) where T == Wrapped?, Wrapped : Equatable, Wrapped : Sendable, Wrapped : AcceptableByConfigurationElementParameters
keyOptional name of the option. If not specified, it will be inferred from the attributed property.
-
Constructor for an
InlinableOptionTypewithout a key.Declaration
Swift
public init(wrappedValue value: T, inline: Bool) where T : InlinableOptionTypeParameters
valueValue to be wrapped.
inlineIf
true, the option will be handled as it would be part of its parent. All of its options will be inlined. Otherwise, it will be treated as a normal nested configuration with its name inferred from the name of the attributed property. -
Constructor for an
InlinableOptionTypewith a name. The configuration will explicitly not be inlined.Declaration
Swift
public init(wrappedValue value: T, key: String) where T : InlinableOptionTypeParameters
valueValue to be wrapped.
keyName of the option.
-
Declaration
Swift
public static func == (lhs: `Self`, rhs: `Self`) -> Bool
View on GitHub
Install in Dash