realm / SwiftLint

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

unneeded_override breaks fixes for "Automatic Initializer Inheritance" #5571

Closed Lutzifer closed 1 month ago

Lutzifer commented 1 month ago

New Issue Checklist

Describe the bug

In some cases (as can be seen in this Stack Overflow Issue: https://stackoverflow.com/a/28187653), it is necessary to reimplement initializers.

As these reimplementations are considered "unneeded" by SwiftLint, they are deleted.

"unneeded_override" could be made optional to avoid breaking existing codebases with this when running swiftlint fix.

SimplyDanny commented 1 month ago

Hm ... so is this rule useful for initializers at all? Feels like valid findings would be rare.

Lutzifer commented 1 month ago

I think it has its uses for initializers, but the chance of breaking the build is too high. If it was an opt-in-only rule it would be more clear which rule caused the issue. Also, not-autofixing the initializers and instead showing a warning only would allow it to easily disable the rule for this very initializer if the situation outlined in the stack overflow issue occurs.

SimplyDanny commented 1 month ago

Disabling the rule for a specific initializer should work anyway. Doesn't it?

As the rule has been available for the last two releases already, changing it to opt-in would be breaking and could lead to surprises. Not sure yet if we should do that.

Lutzifer commented 1 month ago

Yeah, it works, but first you have to find out which of the rules caused your code to be deleted 🤪

The initializers have only been included with the latest release of some days ago by default as far as I can see.

marcelofabri commented 1 month ago

The problem is that the rule implementation for autocorrect is not respecting the new affect_initializers configuration (which defaults to false). This means that linting behavior didn't change with the new release, but autocorrection did.

Lutzifer commented 1 month ago

The problem is that the rule implementation for autocorrect is not respecting the new affect_initializers configuration (which defaults to false). This means that linting behavior didn't change with the new release, but autocorrection did.

that explains what we experienced

SimplyDanny commented 1 month ago

The problem is that the rule implementation for autocorrect is not respecting the new affect_initializers configuration (which defaults to false). This means that linting behavior didn't change with the new release, but autocorrection did.

Aha ... then this should be an easy fix.