$ swiftlint
Protocols.swift:16:1: warning: Test Violation: Delegate protocols should be class-only so they can be weakly referenced. (class_delegate_protocol)
swiftlint version to be sure)?0.23.1
Brew
No
xcode-select -p)?9.1
echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rulesswiftlint lint --path [file here] --no-cache --enable-all-rules.// This triggers a violation:
protocol A: class {}
protocol BDelegate: A {}
In the example above this triggers a violation as expected. The suggested way to fix this would be to change the code to:
// This does not trigger a violation
protocol A: class {}
protocol BDelegate: class, A {}
However this invokes a new warning in Xcode 9.1:
warning: redundant layout constraint 'Self' : 'AnyObject'
protocol BDelegate: class, A {
So it's not possible to satisfy both the Swift requirement and the Swiftlint rule unless the dependent protocol is renamed to *Delegate. This seems more restrictive than this rule was originally intended to be.
I have the same issue with Xcode version 9.1. I had to disable the rule in order to stop getting warnings that didn't appear on Xcode 9.0.
Hope to get a solution.
Same for me, only happens on Xcode 9.1.
Same for me too, only happens for Xcode 9.1.
PRs welcome.
The only solution I could come up with would be adding an extra configuration to explicitly allow certain protocols inheritance. This is not ideal, but at least would avoid the warning.
I'm not 100% sure about this, but I feel the warning is triggered without protocol inheritance.
// This triggers a violation "Delegate protocols should be class-only so they can be weakly referenced."
protocol MyClassDelegate: class {}
class MyClass: NSObject {
weak var delegate: MyClassDelegate?
}
This might have been fixed recently, but still shows up for Danger running swiftlint (checking the version now).
@eneko That didn't trigger a warning for me.
@eneko Your case also triggers warnings for me when run from Danger on CI but not locally. I'm using the latest versions of Danger and SwiftLint on CI and locally.
Ok, so it might have been fixed recently, I would assume the danger-swiftlint gem has not been updated yet. Thanks!
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!
Most helpful comment
I'm not 100% sure about this, but I feel the warning is triggered without protocol inheritance.
This might have been fixed recently, but still shows up for Danger running swiftlint (checking the version now).