Fix redundant objc attribute false alarms
Fixes some false alarms in the redundant_objc_attribute that seem to have come in around 0.50.1
Resolves https://github.com/realm/SwiftLint/issues/4633
We've seen a few of these in our own codebase.
I picked this up and fixed most of it, when I noticed @Cyberbeni 's branch. My final solution is a mix of my original, and some stuff I cribbed from his fixes at https://github.com/realm/SwiftLint/pull/4642
I also patched up some of the examples that weren't valid Swift code or didn't make sense.
These are the examples that were triggering false alarms:
@objcMembers
public class Foo: NSObject {
@objc
private func handler(_ notification: Notification) {
}
func registerForNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(handler(_:)), name: nil, object: nil)
}
}
class Foo: NSObject { }
@objc extension Foo {
@objc enum Bar: Int {
case bar
}
var bar: Bar { .bar }
}
class Foo: NSObject { }
@objc extension Foo {
@objc private enum Baz: Int {
case baz
}
private var baz: Baz { .baz }
}
@objcMembers
internal class Foo: NSObject {
@objc
private var baz: Int = 1
var x: Any? {
value(forKey: "baz")
}
}
@objcMembers
class Foo: NSObject {
@objc enum Bar: Int {
case bar
}
}
| 1 Warning | |
|---|---|
| :warning: | This PR may need tests. |
| 18 Messages | |
|---|---|
| :book: | Linting Aerial with this PR took 1.1s vs 1.1s on main (0% slower) |
| :book: | Linting Alamofire with this PR took 1.43s vs 1.43s on main (0% slower) |
| :book: | Linting Brave with this PR took 7.69s vs 7.73s on main (0% faster) |
| :book: | Linting DuckDuckGo with this PR took 3.75s vs 3.72s on main (0% slower) |
| :book: | Linting Firefox with this PR took 9.75s vs 9.74s on main (0% slower) |
| :book: | Linting Kickstarter with this PR took 10.37s vs 10.37s on main (0% slower) |
| :book: | Linting Moya with this PR took 0.59s vs 0.58s on main (1% slower) |
| :book: | Linting NetNewsWire with this PR took 3.18s vs 3.19s on main (0% faster) |
| :book: | Linting Nimble with this PR took 0.66s vs 0.66s on main (0% slower) |
| :book: | Linting PocketCasts with this PR took 7.7s vs 7.68s on main (0% slower) |
| :book: | Linting Quick with this PR took 0.34s vs 0.34s on main (0% slower) |
| :book: | Linting Realm with this PR took 11.91s vs 11.91s on main (0% slower) |
| :book: | Linting Sourcery with this PR took 2.27s vs 2.3s on main (1% faster) |
| :book: | Linting Swift with this PR took 4.83s vs 4.83s on main (0% slower) |
| :book: | Linting VLC with this PR took 1.37s vs 1.37s on main (0% slower) |
| :book: | Linting Wire with this PR took 8.47s vs 8.47s on main (0% slower) |
| :book: | Linting WordPress with this PR took 11.93s vs 11.94s on main (0% faster) |
| :book: | This PR fixed a violation in VLC: /Sources/Playback/Player/VideoPlayer-iOS/Subviews/MediaNavigationBar.swift:190:5: warning: Redundant @objc Attribute Violation: Objective-C attribute (@objc) is redundant in declaration (redundant_objc_attribute) |
Generated by :no_entry_sign: Danger
See also https://github.com/apple/swift/issues/63442
Thank you and sorry for letting you wait for so long! 😶