Configuration

public struct Configuration
extension Configuration: Hashable
extension Configuration: CustomStringConvertible

The configuration struct for SwiftLint. User-defined in the .swiftlint.yml file, drives the behavior of SwiftLint.

Properties: Static

  • The default Configuration resulting from an empty configuration file.

    Declaration

    Swift

    public static var `default`: Configuration { get }
  • The default file name to look for user-defined configurations.

    Declaration

    Swift

    public static let defaultFileName: String

Public Instance

  • The paths that should be included when linting

    Declaration

    Swift

    public private(set) var includedPaths: [String] { get }
  • The paths that should be excluded when linting

    Declaration

    Swift

    public private(set) var excludedPaths: [String] { get }
  • The style to use when indenting Swift source code.

    Declaration

    Swift

    public let indentation: IndentationStyle
  • The threshold for the number of warnings to tolerate before treating the lint as having failed.

    Declaration

    Swift

    public let warningThreshold: Int?
  • The identifier for the Reporter to use to report style violations.

    Declaration

    Swift

    public let reporter: String
  • The location of the persisted cache to use with this configuration.

    Declaration

    Swift

    public let cachePath: String?
  • Allow or disallow SwiftLint to exit successfully when passed only ignored or unlintable files.

    Declaration

    Swift

    public let allowZeroLintableFiles: Bool
  • This value is true iff the --config parameter was used to specify (a) configuration file(s) In particular, this means that the value is also true if the --config parameter was used to explicitly specify the default .swiftlint.yml as the configuration file

    Declaration

    Swift

    public private(set) var basedOnCustomConfigurationFiles: Bool { get }

Public Computed

  • All rules enabled in this configuration

    Declaration

    Swift

    public var rules: [Rule] { get }
  • The root directory is the directory that included & excluded paths relate to. By default, the root directory is the current working directory, but during some merging algorithms it may be used differently. The rootDirectory also serves as the stopping point when searching for nested configs along the file hierarchy.

    Declaration

    Swift

    public var rootDirectory: String { get }
  • The rules mode used for this configuration.

    Declaration

    Swift

    public var rulesMode: RulesMode { get }

Public

  • Creates a Configuration with convenience parameters.

    Declaration

    Swift

    public init(
        configurationFiles: [String], // No default value here to avoid ambiguous Configuration() initializer
        enableAllRules: Bool = false,
        cachePath: String? = nil,
        ignoreParentAndChildConfigs: Bool = false,
        mockedNetworkResults: [String: String] = [:],
        useDefaultConfigOnFailure: Bool? = nil
    )

    Parameters

    configurationFiles

    The path on disk to one or multiple configuration files. If this array is empty, the default .swiftlint.yml file will be used.

    enableAllRules

    Enable all available rules.

    cachePath

    The location of the persisted cache to use whith this configuration.

    ignoreParentAndChildConfigs

    If true, child and parent config references will be ignored.

    mockedNetworkResults

    For testing purposes only. Instead of loading the specified urls, the mocked value will be used. Example: [“http://mock.com”: “content”]

    useDefaultConfigOnFailure

    If this value is specified, it will override the normal behavior. This is only intended for tests checking whether invalid configs fail.

Caching Configurations By Identifier (In-Memory)

  • Returns a copy of the current Configuration with its computedCacheDescription property set to the value of cacheDescription, which is expensive to compute.

    Declaration

    Swift

    public func withPrecomputedCacheDescription() -> Configuration

    Return Value

    A new Configuration value.

  • The style of indentation used in a Swift project.

    See more

    Declaration

    Swift

    enum IndentationStyle : Hashable

Lintable Paths

  • Returns the files that can be linted by SwiftLint in the specified parent path.

    Declaration

    Swift

    public func lintableFiles(inPath path: String, forceExclude: Bool,
                              excludeByPrefix: Bool = false) -> [SwiftLintFile]

    Parameters

    path

    The parent path in which to search for lintable files. Can be a directory or a file.

    forceExclude

    Whether or not excludes defined in this configuration should be applied even if path is an exact match.

    excludeByPrefix

    Whether or not uses excluding by prefix algorithm.

    Return Value

    Files to lint.

  • Returns an array of file paths after removing the excluded paths as defined by this configuration.

    Declaration

    Swift

    public func filterExcludedPaths(
        fileManager: LintableFileManager = FileManager.default,
        in paths: [String]...
    ) -> [String]

    Parameters

    fileManager

    The lintable file manager to use to expand the excluded paths into all matching paths.

    paths

    The input paths to filter.

    Return Value

    The input paths after removing the excluded paths.

  • Returns the file paths that are excluded by this configuration using filtering by absolute path prefix.

    For cases when excluded directories contain many lintable files (e. g. Pods) it works faster than default algorithm filterExcludedPaths.

    Declaration

    Swift

    public func filterExcludedPathsByPrefix(in paths: [String]...) -> [String]

    Return Value

    The input paths after removing the excluded paths.

Accessing File Configurations

  • Returns a new configuration that applies to the specified file by merging the current configuration with any nested configurations in the directory inheritance graph present until the level of the specified file.

    Declaration

    Swift

    public func configuration(for file: SwiftLintFile) -> Configuration

    Parameters

    file

    The file for which to obtain a configuration value.

    Return Value

    A new configuration.

Initializers

  • Creates a Configuration value based on the specified parameters.

    Declaration

    Swift

    public init(
        dict: [String: Any],
        ruleList: RuleList = primaryRuleList,
        enableAllRules: Bool = false,
        cachePath: String? = nil
    ) throws

    Parameters

    dict

    The untyped dictionary to serve as the input for this typed configuration. Typically generated from a YAML-formatted file.

    ruleList

    The list of rules to be available to this configuration.

    enableAllRules

    Whether all rules from ruleList should be enabled, regardless of the settings in dict.

    cachePath

    The location of the persisted cache on disk.

  • Represents how a Configuration object can be configured with regards to rules.

    See more

    Declaration

    Swift

    enum RulesMode

Hashable

CustomStringConvertible