nicklockwood / SwiftFormat

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

swiftformat:disable:next is broken #1031

Closed Cyberbeni closed 3 years ago

Cyberbeni commented 3 years ago

I am currently upgrading from 0.48.11

self is removed here, causing a compiler warning that I can also use Swift.max and simd.max and if I want Sequence's max, I should explicitly use self.max

extension Array where Element == Quadrilateral {
    /// Finds the biggest rectangle within an array of `Quadrilateral` objects.
    func biggest() -> Quadrilateral? {
        guard count > 1 else {
            return first
        }

        // swiftformat:disable:next redundantSelf
        let biggestRectangle = self.max(by: { rect1, rect2 -> Bool in
            rect1.perimeter < rect2.perimeter
        })

        return biggestRectangle
    }
}

edit: using // swiftformat:disable all also doesn't seem to prevent formatting

nicklockwood commented 3 years ago

@Cyberbeni is this on 0.48.14? I'm not able to reproduce with the code sample provided. In fact the

// swiftformat:disable:next redundantSelf

Isn't even needed, since self.min, self.max, etc are now ignored by default.

nicklockwood commented 3 years ago

@Cyberbeni ah wait, I see the problem. It only happens if --swiftversion is set to 5.4 or above.

Cyberbeni commented 3 years ago

Yes, only when specifying --swiftversion 5.4 or 5.5

There is another case where there is a .swiftversion file 2 folders up (but the command has 5.5 specified because only a small part of the code needs to be 3.0 compatible) and a self. is removed causing a compilation error.

I assume this is the same issue or should I try to get a smaller code chunk that reproduces it / open a separate issue?

nicklockwood commented 3 years ago

@Cyberbeni sounds like a different issue, so it's worth having a separate snippet.

Cyberbeni commented 3 years ago

Yes, it seems like a different issue -> https://github.com/nicklockwood/SwiftFormat/issues/1032

nicklockwood commented 3 years ago

@Cyberbeni fixed in 0.48.15