Swiftlint: False positive: let_var_whitespace with Swift 5.1 property wrappers

Created on 26 Nov 2019  路  7Comments  路  Source: realm/SwiftLint

New Issue Checklist

Describe the bug

I have adopted the new Swift 5.1 property wrapper feature. It seems to cause a false positive with the opt-in rule let_var_whitespace.

Relevant file:

import Foundation

public enum Defaults {

    @UserDefault("isFirstTimeUser", defaultValue: true)
    public static var isFirstTimeUser: Bool
}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint --config ../.swiftlint.yml 
Loading configuration from '../.swiftlint.yml'
Linting Swift files at paths 
Linting 'Defaults.swift' (1/1)
<path>/Defaults.swift:6:5: warning: Variable Declaration Whitespace Violation: Let and var should be separated from other statements by a blank line. (let_var_whitespace)
Done linting! Found 1 violation, 0 serious in 1 files.

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.37.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
opt_in_rules:
  - let_var_whitespace
  • Are you using nested configurations? No
  • Which Xcode version are you using? 11.2.1
  • Do you have a sample that shows the issue?
echo "public enum Defaults {
@UserDefault("isFirstTimeUser", defaultValue: true)
public static var isFirstTimeUser: Bool
}" | swiftlint lint --no-cache --use-stdin --enable-all-rules
bug

Most helpful comment

I've found that this can be avoided by adding a doc comment above the property wrapper. Still rather annoying.

All 7 comments

What is the status of this? Is anybody working on it?

I've found that this can be avoided by adding a doc comment above the property wrapper. Still rather annoying.

Adding a +1 here and really appreciative of the workaround @jshier !

+++

The same

+1
Also, another workaround would be to have the property wrapper in the same line as the variable definition, something like:
@Inject var foo: Foo

If anyone here has started working on this and has hit a dead end, I'm happy to help answer any questions you might have.

The CONTRIBUTING.md doc should be a good first step in looking into making changes to SwiftLint.

Was this page helpful?
0 / 5 - 0 ratings