realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.65k stars 2.22k forks source link

Warnings for deprecated rules that are implicitly enabled using the `all` rule #4989

Closed sdc-78 closed 1 year ago

sdc-78 commented 1 year ago

New Issue Checklist

Describe the bug

SwiftLint gives warnings for deprecated rules that are implicitly enabled using the all rule :

warning: The `anyobject_protocol` rule is now deprecated and will be completely removed in a future release.
warning: The `inert_defer` rule is now deprecated and will be completely removed in a future release due to an equivalent warning issued by the Swift compiler.
warning: The `unused_capture_list` rule is now deprecated and will be completely removed in a future release due to an equivalent warning issued by the Swift compiler.

Environment

opt_in_rules:
  - all
SimplyDanny commented 1 year ago

While they are deprecated they are still valid rules. So I would expect them to be enabled by the all key. Thus, I wouldn't change this behavior.

If you don't want the rules to be enabled, explicitly disable them. The warning appears no matter how the rules were enabled. If you like the rules, you enable them but you have to live with the warning. That's independent from the all key.

sdc-78 commented 1 year ago

I agree that deprecated rules should remain enabled by all, as long as they still exist. I'm only suggesting that they not be reported as deprecated, as they haven't been explicitly enabled.

SimplyDanny commented 1 year ago

Well, with all a user has explicitly enabled them. That they are deprecated doesn't play a role. For a set of users they might still be useful.

sdc-78 commented 1 year ago

For a set of users they might still be useful.

I actually hadn't thought of that. What type of use/users are you thinking of?

SimplyDanny commented 1 year ago

inert_defer for example has been deprecated because the Swift compiler reports the same violation natively in recent versions. For people relying on an older Swift version, the rule still has it's benefit.

mildm8nnered commented 1 year ago

I don't think it would be too outrageous to have a command line argument that suppressed the deprecated rule warnings though.

In a private experimental branch I've got an implementation of a configuration "wizard" for SwiftLint, and there I marked all the deprecated rules with a DeprecatedRule protocol, so that I can offer the user the option of disabling any deprecated rules.

A similar mechanism could be extended to support a command line argument to suppress the deprecation warnings ...

sdc-78 commented 1 year ago

inert_defer for example has been deprecated because the Swift compiler reports the same violation natively in recent versions. For people relying on an older Swift version, the rule still has it's benefit.

I agree that deprecated rules still may be useful and I never asked to stop enabling them!

N-ihad commented 4 months ago

what's the reason behind deprecating 'unused_capture_list'? Swift compiler doesn't seem to be reporting about that, so what's the catch?

SimplyDanny commented 4 months ago

Which version of the Swift compiler are you using and on which example?

Compiling

func f(x: Int) {
    { [x] in }()
}

prints out

main.swift:2:8: warning: capture 'x' was never used
    { [x] in }()
       ^

which unused_capture_list is supposed to report as well and which thus draws the rule deprecated.

I'm using Swift 5.10. But as the rule got deprecated 18 months ago already, I assume that at least 5.8 should be complaining too.