Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refinement of unneeded_override Rule to Properly Handle Swift Attributes #5753

Closed
2 tasks done
KosFM opened this issue Aug 15, 2024 · 1 comment · Fixed by #5764
Closed
2 tasks done

Refinement of unneeded_override Rule to Properly Handle Swift Attributes #5753

KosFM opened this issue Aug 15, 2024 · 1 comment · Fixed by #5764
Assignees
Labels
bug Unexpected and reproducible misbehavior. good first issue Issue to be taken up by new contributors yet unfamiliar with the project.

Comments

@KosFM
Copy link

KosFM commented Aug 15, 2024

New Issue Checklist

Feature or Enhancement Proposal

The unneeded_override rule in SwiftLint currently triggers a warning for methods that are overridden solely to add Swift attributes, such as @objc, @IBAction, and similar. Consider the following example:

class BaseClass {
    func foo() {}
}

class SubClass: BaseClass {
    <<Any Swift Function Attribute (@objc, @IBAction etc.)>> override func foo() { 
        super.foo()
    }
}

In this case, SwiftLint issues a warning on the overridden foo() method, indicating that the override is unnecessary. However, the override is intentionally used to apply a specific attribute, which is a legitimate use case.

This raises a discussion point: while attributes on overridden methods may be necessary, the current rule does not appropriately account for this scenario. The rule should be refined to differentiate between purely redundant overrides and those that serve the purpose of attribute application.

Environment

  • SwiftLint version: 0.56.1
  • Xcode version: Xcode 15.4, Build version 15F31d
  • Installation method used: Cocoapods
@KosFM KosFM changed the title Refinement of unneeded_override Rule to Properly Handle Swift Attributes Refinement of unneeded_override Rule to Properly Handle Swift Attributes Aug 15, 2024
@SimplyDanny SimplyDanny added bug Unexpected and reproducible misbehavior. good first issue Issue to be taken up by new contributors yet unfamiliar with the project. labels Aug 18, 2024
@SimplyDanny
Copy link
Collaborator

I agree that the rule should ignore overridden methods with attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior. good first issue Issue to be taken up by new contributors yet unfamiliar with the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants