Skip to content

Commit

Permalink
Add minimum_swiftlint_version as a configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-taffe committed Jul 24, 2024
1 parent b9f3843 commit c040424
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Source/SwiftLintCore/Extensions/Configuration+Parsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion Source/SwiftLintCore/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit c040424

Please sign in to comment.