nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 640 forks source link

redundantSelf incorrectly removes self for instance variables after local variables. #1070

Closed CraigSiemens closed 2 years ago

CraigSiemens commented 2 years ago

If I have this file

// Foo.swift
import Foundation

extension MyStruct {
    init() {
        self.id = UUID()

        let someValue = 1234
        self.amount = someValue
    }
}

When I run the following command, I'd expect there to be no lint warnings.

swiftformat --lint foo.swift --self init-only --swiftversion 5.4

Instead it gets a warning only for the second property that it shouldn't use self.

Running SwiftFormat...
(lint mode - no files will be changed.)
.../foo.swift:9:1: warning: (redundantSelf) Insert/remove explicit self where applicable.
SwiftFormat completed in 0.93s.

Also

nicklockwood commented 2 years ago

@CraigSiemens thanks for reporting. Seems to only happen with --swiftversion set to 5.4 or higher.

nicklockwood commented 2 years ago

@CraigSiemens fixed in 0.49.1