RuleDescription

public struct RuleDescription : Equatable

A detailed description for a SwiftLint rule. Used for both documentation and testing purposes.

  • The rule’s unique identifier, to be used in configuration files and SwiftLint commands. Should be short and only comprised of lowercase latin alphabet letters and underscores formatted in snake case.

    Declaration

    Swift

    public let identifier: String
  • The rule’s human-readable name. Should be short, descriptive and formatted in Title Case. May contain spaces.

    Declaration

    Swift

    public let name: String
  • The rule’s verbose description. Should read as a sentence or short paragraph. Good things to include are an explanation of the rule’s purpose and rationale.

    Declaration

    Swift

    public let description: String
  • The RuleKind that best categorizes this rule.

    Declaration

    Swift

    public let kind: RuleKind
  • Swift source examples that do not trigger a violation for this rule. Used for documentation purposes to inform users of various samples of code that are considered valid by this rule. Should be valid Swift syntax but is not required to compile.

    These examples are also used for testing purposes if the rule conforms to AutomaticTestableRule. Tests will validate that the rule does not trigger any violations for these examples.

    Declaration

    Swift

    public let nonTriggeringExamples: [Example]
  • Swift source examples that do trigger one or more violations for this rule. Used for documentation purposes to inform users of various samples of code that are considered invalid by this rule. Should be valid Swift syntax but is not required to compile.

    Violations should occur where markers are located.

    These examples are also used for testing purposes if the rule conforms to AutomaticTestableRule. Tests will validate that the rule triggers violations for these examples wherever markers are located.

    Declaration

    Swift

    public let triggeringExamples: [Example]
  • Pairs of Swift source examples, where keys are examples that trigger violations for this rule, and the values are the expected value after applying corrections with the rule.

    Rules that aren’t correctable (conforming to the CorrectableRule protocol) should leave property empty.

    These examples are used for testing purposes if the rule conforms to AutomaticTestableRule. Tests will validate that the rule corrects all keys to their corresponding values.

    Declaration

    Swift

    public let corrections: [Example : Example]
  • Any previous iteration of the rule’s identifier that was previously shipped with SwiftLint.

    Declaration

    Swift

    public let deprecatedAliases: Set<String>
  • The oldest version of the Swift compiler supported by this rule.

    Declaration

    Swift

    public let minSwiftVersion: SwiftVersion
  • Whether or not this rule can only be executed on a file physically on-disk. Typically necessary for rules conforming to AnalyzerRule.

    Declaration

    Swift

    public let requiresFileOnDisk: Bool
  • The console-printable string for this description.

    Declaration

    Swift

    public var consoleDescription: String { get }
  • All identifiers that have been used to uniquely identify this rule in past and current SwiftLint versions.

    Declaration

    Swift

    public var allIdentifiers: [String] { get }
  • Creates a RuleDescription by specifying all its properties directly.

    Declaration

    Swift

    public init(identifier: String, name: String, description: String, kind: RuleKind,
                minSwiftVersion: SwiftVersion = .three,
                nonTriggeringExamples: [Example] = [], triggeringExamples: [Example] = [],
                corrections: [Example: Example] = [:],
                deprecatedAliases: Set<String> = [],
                requiresFileOnDisk: Bool = false)

    Parameters

    identifier

    Sets the description’s identifier property.

    name

    Sets the description’s name property.

    description

    Sets the description’s description property.

    kind

    Sets the description’s kind property.

    minSwiftVersion

    Sets the description’s minSwiftVersion property.

    nonTriggeringExamples

    Sets the description’s nonTriggeringExamples property.

    triggeringExamples

    Sets the description’s triggeringExamples property.

    corrections

    Sets the description’s corrections property.

    deprecatedAliases

    Sets the description’s deprecatedAliases property.

    requiresFileOnDisk

    Sets the description’s requiresFileOnDisk property.

Equatable

  • Declaration

    Swift

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