Example

public struct Example : Sendable
extension Example: Hashable
extension Example: Comparable

Captures code and context information for an example of a triggering or non-triggering style

  • The contents of the example

    Declaration

    Swift

    public private(set) var code: String { get }
  • The untyped configuration to apply to the rule, if deviating from the default configuration. The structure should match what is expected as a configuration value for the rule being tested.

    For example, if the following YAML would be used to configure the rule:

    severity: warning
    

    Then the equivalent configuration value would be ["severity": "warning"].

    Declaration

    Swift

    public private(set) var configuration: [String : any Sendable]? { get }
  • Whether the example should be tested by prepending multibyte grapheme clusters

    See also

    addEmoji(_:)

    Declaration

    Swift

    public private(set) var testMultiByteOffsets: Bool { get }
  • Whether the example should be tested on Linux

    Declaration

    Swift

    public private(set) var testOnLinux: Bool { get }
  • The path to the file where the example was created

    Declaration

    Swift

    public private(set) var file: StaticString { get }
  • The line in the file where the example was created

    Declaration

    Swift

    public var line: UInt
  • Create a new Example with the specified code, file, and line.

    Declaration

    Swift

    init(_ code: String, configuration: [String: any Sendable]? = nil, testMultiByteOffsets: Bool = true,
         testWrappingInComment: Bool = true, testWrappingInString: Bool = true, testDisableCommand: Bool = true,
         testOnLinux: Bool = true, file: StaticString = #file, line: UInt = #line,
         excludeFromDocumentation: Bool = false)

    Parameters

    code

    The contents of the example.

    configuration

    The untyped configuration to apply to the rule, if deviating from the default configuration.

    testMultibyteOffsets

    Whether the example should be tested by prepending multibyte grapheme clusters.

    testWrappingInComment

    Whether test shall verify that the example wrapped in a comment doesn’t trigger.

    testWrappingInString

    Whether tests shall verify that the example wrapped into a string doesn’t trigger.

    testDisableCommand

    Whether tests shall verify that the disabled rule (comment in the example) doesn’t trigger.

    testOnLinux

    Whether the example should be tested on Linux.

    file

    The path to the file where the example is located. Defaults to the file where this initializer is called.

    line

    The line in the file where the example is located. Defaults to the line where this initializer is called.

  • Returns the same example, but with the code that is passed in

    Declaration

    Swift

    func with(code: String) -> Example

    Parameters

    code

    the new code to use in the modified example

  • Returns a copy of the Example with all instances of the “↓” character removed.

    Declaration

    Swift

    func removingViolationMarkers() -> Example
  • Makes the current example focused. This is for debugging purposes only.

    Declaration

    Swift

    public func focused() -> Example
  • Declaration

    Swift

    public static func == (lhs: Example, rhs: Example) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)
  • Declaration

    Swift

    public static func < (lhs: Example, rhs: Example) -> Bool