Skip to content

Commit 4f1c1f6

Browse files
committed
Add minimum_swiftlint_version as a configuration option
1 parent b9f3843 commit 4f1c1f6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Source/SwiftLintCore/Extensions/Configuration+Parsing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extension Configuration {
99
case optInRules = "opt_in_rules"
1010
case reporter = "reporter"
1111
case swiftlintVersion = "swiftlint_version"
12+
case minimumSwiftlintVersion = "minimum_swiftlint_version"
1213
case warningThreshold = "warning_threshold"
1314
case onlyRules = "only_rules"
1415
case indentation = "indentation"
@@ -101,6 +102,7 @@ extension Configuration {
101102
reporter: dict[Key.reporter.rawValue] as? String ?? XcodeReporter.identifier,
102103
cachePath: cachePath ?? dict[Key.cachePath.rawValue] as? String,
103104
pinnedVersion: dict[Key.swiftlintVersion.rawValue].map { ($0 as? String) ?? String(describing: $0) },
105+
minimumVersion: dict[Key.minimumSwiftlintVersion.rawValue].map { ($0 as? String) ?? String(describing: $0) },
104106
allowZeroLintableFiles: dict[Key.allowZeroLintableFiles.rawValue] as? Bool ?? false,
105107
strict: dict[Key.strict.rawValue] as? Bool ?? false,
106108
baseline: dict[Key.baseline.rawValue] as? String,

Source/SwiftLintCore/Models/Configuration.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public struct Configuration {
124124

125125
/// Creates a `Configuration` by specifying its properties directly,
126126
/// except that rules are still to be synthesized from rulesMode, ruleList & allRulesWrapped
127-
/// and a check against the pinnedVersion is performed if given.
127+
/// and a check against the pinnedVersion/minimumVersion is performed if given.
128128
///
129129
/// - parameter rulesMode: The `RulesMode` for this configuration.
130130
/// - parameter allRulesWrapped: The rules with their own configurations already applied.
@@ -140,6 +140,7 @@ public struct Configuration {
140140
/// - parameter reporter: The identifier for the `Reporter` to use to report style violations.
141141
/// - parameter cachePath: The location of the persisted cache to use whith this configuration.
142142
/// - parameter pinnedVersion: The SwiftLint version defined in this configuration.
143+
/// - parameter minimumVersion: The minimum SwiftLint version defined in this configuration.
143144
/// - parameter allowZeroLintableFiles: Allow SwiftLint to exit successfully when passed ignored or unlintable
144145
/// files.
145146
/// - parameter strict: Treat warnings as errors.
@@ -158,6 +159,7 @@ public struct Configuration {
158159
reporter: String? = nil,
159160
cachePath: String? = nil,
160161
pinnedVersion: String? = nil,
162+
minimumVersion: String? = nil,
161163
allowZeroLintableFiles: Bool = false,
162164
strict: Bool = false,
163165
baseline: String? = nil,
@@ -171,6 +173,14 @@ public struct Configuration {
171173
)
172174
exit(2)
173175
}
176+
177+
if let minimumVersion, minimumVersion.compare(Version.current.value, options: .numeric) == .orderedDescending {
178+
queuedPrintError(
179+
"warning: Currently running SwiftLint \(Version.current.value) but " +
180+
"configuration specified minimum version \(minimumVersion)."
181+
)
182+
exit(2)
183+
}
174184

175185
self.init(
176186
rulesWrapper: RulesWrapper(

0 commit comments

Comments
 (0)