[Feature Request] Add support for .swift-version file and older swift versions
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Description
We are running UI tests for our macOS app starting with macOS 10.11, meaning that the test runner has to support Swift 3.0 (The linting is always done on the latest OS with the latest Xcode)
SwiftFormat allows us to have a .swift-version file in random folders that override the swift version specified in the main config file, so we don't have to bother with manually configuring which rules are enabled where.
I noticed this because SwiftLint started complaining about the legacy_random rule which has been enabled here, along with removing the minimum swift version requirement for a bunch of rules that were below 5.0: https://github.com/realm/SwiftLint/pull/3886/files
Complete output when running SwiftLint, including the stack trace and command used
ln -s "$GIT_ROOT_DIR/.swiftlint.yml" "$SRCROOT/.swiftlint.yml"
"$($BREW --prefix)/bin/swiftlint" --path "$SRCROOT"
The .swift-version file containing 3.0 is also in SRCROOT
...
/path/to/file.swift:28:33: warning: Legacy Random Violation: Prefer using `type.random(in:)` over legacy functions. (legacy_random)
...
Example code
import Foundation
#if swift(>=4.2)
#else
public extension Array {
func randomElement() -> Element? {
guard !isEmpty else { return nil }
return self[Int(arc4random_uniform(UInt32(count)))]
}
func allSatisfy(_ predicate: (Element) throws -> Bool) rethrows -> Bool {
return try !contains {
return try !predicate($0)
}
}
}
#endif
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the .swift-version and .swiftlint.yml configuration paths and the --path command shown in the report. Trace how SwiftLint determines the Swift version and applies the legacy_random rule. Done means supporting a .swift-version file in nested folders and using it to select compatible rules for Swift 3.0 and other older versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100