realm / realm/SwiftLint

[Feature Request] Add support for .swift-version file and older swift versions

Open
#3,934 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.