Swiftlint: Rule request: newValue ignored on var set

Created on 9 Jan 2017  路  7Comments  路  Source: realm/SwiftLint

I've seen a lot of times people using the variable name instead of newValue which leads to bugs:

var aValue: String {
    get {
        return Persister.shared.aValue
    }
    set {
        Perister.shared.aValue = aValue //should be newValue
    }
}
rule-request

Most helpful comment

Closing this as https://github.com/apple/swift/pull/11465 was merged and it'll be a compiler warning in future Swift versions 馃帀

All 7 comments

A small detail here is that you can use another name for the parameter. For example:

// shouldn't trigger
var aValue: String {
    get {
        return Persister.shared.aValue
    }
    set(persistedValue) {
        Perister.shared.aValue = persistedValue
    }
}

There's an open ticket on Swift JIRA for this as well: SR-964

Closing this as https://github.com/apple/swift/pull/11465 was merged and it'll be a compiler warning in future Swift versions 馃帀

Note that a case was missed in the resolution to SR-964, and the PR for the fix never ended up getting merged, so SwiftLint could still provide a band-aid (or anyone who's interested could pick up that PR and port it to Swift 4.2 or 5.0).

Going to revive this because we're just bitten by it, so I guess the compiler warning never really shipped on 4.2

Would it be possible to ignore properties that are marked as unavailable? This is a bit unfortunate.

screen shot 2019-01-25 at 2 23 31 pm

@jgavris please open a new issue to track this

Was this page helpful?
0 / 5 - 0 ratings