Skip to content

False positive: let_var_whitespace with Swift 5.1 property wrappers #2980

Closed
@schayes04

Description

@schayes04

New Issue Checklist

  • Updated SwiftLint to the latest version
    I searched for existing GitHub issues

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

Activity

added
bugUnexpected and reproducible misbehavior.
on Jan 2, 2020
akwilliamson

akwilliamson commented on Mar 23, 2020

@akwilliamson

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

jshier

jshier commented on Mar 30, 2020

@jshier
Contributor

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

bdrelling

bdrelling commented on May 14, 2020

@bdrelling

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

Tayphoon

Tayphoon commented on Jun 27, 2020

@Tayphoon

+++

DimaZava

DimaZava commented on Aug 3, 2020

@DimaZava

The same

fidmor89

fidmor89 commented on Aug 20, 2020

@fidmor89

+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

jpsim

jpsim commented on Nov 7, 2020

@jpsim
Collaborator

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.

stale

stale commented on Jan 6, 2021

@stale

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

added
wontfixIssues that became stale and were auto-closed by a bot.
on Jan 6, 2021
Igor-Palaguta

Igor-Palaguta commented on Jan 7, 2021

@Igor-Palaguta

+1

removed
wontfixIssues that became stale and were auto-closed by a bot.
on Jan 7, 2021
Tayphoon

Tayphoon commented on Jan 13, 2021

@Tayphoon
MarshalGeazipp

MarshalGeazipp commented on Jan 22, 2021

@MarshalGeazipp

I hit this annoying bug today.
What is the status of this? Is anybody working on it?

edorphy

edorphy commented on May 15, 2021

@edorphy

+1

13 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected and reproducible misbehavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Participants

    @MarshalGeazipp@jshier@jpsim@Igor-Palaguta@marcelofabri

    Issue actions

      False positive: let_var_whitespace with Swift 5.1 property wrappers · Issue #2980 · realm/SwiftLint