ConfigurationElement

@propertyWrapper
public struct ConfigurationElement<T> : Equatable where T : Equatable, 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:

  1. 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
  2. It can be represented as a separate nested configuration. In this case, it must not have set the inline flag to true. E.g. swift @ConfigurationElement var levels = SeverityLevelsConfiguration(warning: 1, error: 2) will have a nested configuration section: levels: warning: 1 error: 2
  3. As mentioned in the beginning, the implicit key inference mechanism can be overruled by specifying a key as 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 more

    Declaration

    Swift

    public enum DeprecationNotice
  • 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 }
  • key

    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

    public init(wrappedValue value: T,
                key: String,
                deprecationNotice: DeprecationNotice? = nil,
                postprocessor: @escaping (inout T) -> Void = { _ in })

    Parameters

    value

    Value to be wrapped.

    key

    Optional name of the option. If not specified, it will be inferred from the attributed property.

    deprecationNotice

    An optional deprecation notice in case an option is outdated and/or has been replaced by an alternative.

    postprocessor

    Function 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 : AcceptableByConfigurationElement

    Parameters

    key

    Optional name of the option. If not specified, it will be inferred from the attributed property.

  • Constructor for an InlinableOptionType without a key.

    Declaration

    Swift

    public init(wrappedValue value: T, inline: Bool) where T : InlinableOptionType

    Parameters

    value

    Value to be wrapped.

    inline

    If 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 InlinableOptionType with a name. The configuration will explicitly not be inlined.

    Declaration

    Swift

    public init(wrappedValue value: T, key: String) where T : InlinableOptionType

    Parameters

    value

    Value to be wrapped.

    key

    Name of the option.

  • Declaration

    Swift

    public static func == (lhs: `Self`, rhs: `Self`) -> Bool