Rule

public protocol Rule

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

  • A verbose description of many of this rule’s properties.

    Declaration

    Swift

    static var description: RuleDescription { get }
  • A description of how this rule has been configured to run.

    Declaration

    Swift

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

    Declaration

    Swift

    init()
  • Creates a rule by applying its configuration.

    Throws

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

    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: 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.