Rule

public protocol Rule

An executable value that can identify issues (violations) in Swift source code.

  • The rule’s description type.

    Declaration

    Swift

    associatedtype Description : Documentable
  • The type of the configuration used to configure this rule.

    Declaration

    Swift

    associatedtype ConfigurationType : RuleConfiguration
  • A verbose description of many of this rule’s properties.

    Declaration

    Swift

    static var description: RuleDescription { get }
  • configurationDescription Default implementation

    A description of how this rule has been configured to run. It can be built using the annotated result builder.

    Default Implementation

    Declaration

    Swift

    @RuleConfigurationDescriptionBuilder
    var configurationDescription: Description { get }
  • This rule’s configuration.

    Declaration

    Swift

    var configuration: ConfigurationType { get set }
  • shouldLintEmptyFiles Default implementation

    Whether this rule should be used on empty files. Defaults to false.

    Default Implementation

    Declaration

    Swift

    var shouldLintEmptyFiles: Bool { get }
  • A default initializer for rules. All rules need to be trivially initializable.

    Declaration

    Swift

    init()
  • init(configuration:) Default implementation

    Creates a rule by applying its configuration.

    Throws

    Throws if the configuration didn’t match the expected format.

    Default Implementation

    Declaration

    Swift

    init(configuration: Any) throws

    Parameters

    configuration

    The untyped configuration value to apply.

  • validate(file:compilerArguments:) Default implementation

    Executes the rule on a file and returns any violations to the rule’s expectations.

    Default Implementation

    Declaration

    Swift

    func validate(file: SwiftLintFile, compilerArguments: [String]) -> [StyleViolation]

    Parameters

    file

    The file for which to execute the rule.

    compilerArguments

    The compiler arguments needed to compile this file.

    Return Value

    All style violations to the rule’s expectations.

  • Executes the rule on a file and returns any violations to the rule’s expectations.

    Declaration

    Swift

    func validate(file: SwiftLintFile) -> [StyleViolation]

    Parameters

    file

    The file for which to execute the rule.

    Return Value

    All style violations to the rule’s expectations.

  • isEqualTo(_:) Default implementation

    Whether or not the specified rule is equivalent to the current rule.

    Default Implementation

    Declaration

    Swift

    func isEqualTo(_ rule: any Rule) -> Bool

    Parameters

    rule

    The rule value to compare against.

    Return Value

    Whether or not the specified rule is equivalent to the current rule.

  • Collects information for the specified file in a storage object, to be analyzed by a CollectedLinter.

    Note

    This function is called by the linter and is always implemented in extensions.

    Default Implementation

    Declaration

    Swift

    func collectInfo(for file: SwiftLintFile, into storage: RuleStorage, compilerArguments: [String])

    Parameters

    file

    The file for which to collect info.

    storage

    The storage object where collected info should be saved.

    compilerArguments

    The compiler arguments needed to compile this file.

  • Executes the rule on a file after collecting file info for all files and returns any violations to the rule’s expectations.

    Note

    This function is called by the linter and is always implemented in extensions.

    Default Implementation

    Declaration

    Swift

    func validate(file: SwiftLintFile, using storage: RuleStorage, compilerArguments: [String]) -> [StyleViolation]

    Parameters

    file

    The file for which to execute the rule.

    storage

    The storage object containing all collected info.

    compilerArguments

    The compiler arguments needed to compile this file.

    Return Value

    All style violations to the rule’s expectations.

  • cacheDescription Extension method

    The cache description which will be used to determine if a previous cached value is still valid given the new cache value.

    Declaration

    Swift

    var cacheDescription: String { get }
  • identifier Extension method

    The rule’s unique identifier which is the same as Rule.description.identifier.

    Declaration

    Swift

    static var identifier: String { get }