diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c18130f63..f265af61376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ #### Enhancements +* Add minimum_swiftlint_version as a configuration option. + [alex-taffe](https://github.com/alex-taffe) + [#5694](https://github.com/realm/SwiftLint/issues/5694) + * Linting got around 20% faster due to the praisworthy performance improvements done in the [SwiftSyntax](https://github.com/swiftlang/swift-syntax) library. diff --git a/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift b/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift index 7c0ed67331b..6a62e73a376 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+Parsing.swift @@ -9,6 +9,7 @@ extension Configuration { case optInRules = "opt_in_rules" case reporter = "reporter" case swiftlintVersion = "swiftlint_version" + case minimumSwiftlintVersion = "minimum_swiftlint_version" case warningThreshold = "warning_threshold" case onlyRules = "only_rules" case indentation = "indentation" @@ -101,6 +102,9 @@ extension Configuration { reporter: dict[Key.reporter.rawValue] as? String ?? XcodeReporter.identifier, cachePath: cachePath ?? dict[Key.cachePath.rawValue] as? String, pinnedVersion: dict[Key.swiftlintVersion.rawValue].map { ($0 as? String) ?? String(describing: $0) }, + minimumVersion: dict[Key.minimumSwiftlintVersion.rawValue].map { + ($0 as? String) ?? String(describing: $0) + }, allowZeroLintableFiles: dict[Key.allowZeroLintableFiles.rawValue] as? Bool ?? false, strict: dict[Key.strict.rawValue] as? Bool ?? false, baseline: dict[Key.baseline.rawValue] as? String, diff --git a/Source/SwiftLintCore/Models/Configuration.swift b/Source/SwiftLintCore/Models/Configuration.swift index 35a86abfe5e..00493749e34 100644 --- a/Source/SwiftLintCore/Models/Configuration.swift +++ b/Source/SwiftLintCore/Models/Configuration.swift @@ -124,7 +124,7 @@ public struct Configuration { /// Creates a `Configuration` by specifying its properties directly, /// except that rules are still to be synthesized from rulesMode, ruleList & allRulesWrapped - /// and a check against the pinnedVersion is performed if given. + /// and a check against the pinnedVersion/minimumVersion is performed if given. /// /// - parameter rulesMode: The `RulesMode` for this configuration. /// - parameter allRulesWrapped: The rules with their own configurations already applied. @@ -140,6 +140,7 @@ public struct Configuration { /// - parameter reporter: The identifier for the `Reporter` to use to report style violations. /// - parameter cachePath: The location of the persisted cache to use whith this configuration. /// - parameter pinnedVersion: The SwiftLint version defined in this configuration. + /// - parameter minimumVersion: The minimum SwiftLint version defined in this configuration. /// - parameter allowZeroLintableFiles: Allow SwiftLint to exit successfully when passed ignored or unlintable /// files. /// - parameter strict: Treat warnings as errors. @@ -158,6 +159,7 @@ public struct Configuration { reporter: String? = nil, cachePath: String? = nil, pinnedVersion: String? = nil, + minimumVersion: String? = nil, allowZeroLintableFiles: Bool = false, strict: Bool = false, baseline: String? = nil, @@ -171,6 +173,14 @@ public struct Configuration { ) exit(2) } + + if let minimumVersion, minimumVersion.compare(Version.current.value, options: .numeric) == .orderedDescending { + queuedPrintError( + "warning: Currently running SwiftLint \(Version.current.value) but " + + "configuration specified minimum version \(minimumVersion)." + ) + exit(2) + } self.init( rulesWrapper: RulesWrapper(