realm / SwiftLint

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

The `overridden_super_call` rule does not detect missing super call in `updateTrackingAreas()` #2616

Open sindresorhus opened 5 years ago

sindresorhus commented 5 years ago

New Issue Checklist

Describe the bug

The rule does not detect that the following is missing a super call:

class Button: NSButton {
    override func updateTrackingAreas() {
        // …
    }
}

It should be:

class Button: NSButton {
    override func updateTrackingAreas() {
        super.updateTrackingAreas()
    }
}

From Apple docs:

You should override this method to remove out of date tracking areas and add recomputed tracking areas; your implementation should call super. - https://developer.apple.com/documentation/appkit/nsview/1483719-updatetrackingareas#

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Environment

opt_in_rules:
  - overridden_super_call
echo "class Button: NSButton { override func updateTrackingAreas() {} }" | swiftlint lint --no-cache --use-stdin --enable-all-rules
marcelofabri commented 5 years ago

overridden_super_call manually checks against a set of methods.

You can add a custom method via the configuration:

overridden_super_call:
  included:
    - '*'
    - updateTrackingAreas()
sindresorhus commented 5 years ago

That is not documented anywhere from what I could find.

sindresorhus commented 5 years ago

What does * mean?

sindresorhus commented 5 years ago

I think updateTrackingAreas() should be included in the default list: https://github.com/realm/SwiftLint/blob/d1dbc31aa9269364d6d7f43d2f99c82e12ceca6f/Source/SwiftLintFramework/Rules/RuleConfigurations/OverridenSuperCallConfiguration.swift#L2

marcelofabri commented 5 years ago

@sindresorhus You're right, currently rule configurations are not very well documented - I had to look at the source code.

* means that the default list of methods checked will be kept. If you don't add it, the list will be overwritten by the configuration.

Here's the list of methods currently checked:

let defaultIncluded = [
        //NSObject
        "awakeFromNib()",
        "prepareForInterfaceBuilder()",
        //UICollectionViewLayout
        "invalidateLayout()",
        "invalidateLayout(with:)",
        "invalidateLayoutWithContext(_:)",
        //UIView
        "prepareForReuse()",
        "updateConstraints()",
        //UIViewController
        "addChildViewController(_:)",
        "decodeRestorableState(with:)",
        "decodeRestorableStateWithCoder(_:)",
        "didReceiveMemoryWarning()",
        "encodeRestorableState(with:)",
        "encodeRestorableStateWithCoder(_:)",
        "removeFromParentViewController()",
        "setEditing(_:animated:)",
        "transition(from:to:duration:options:animations:completion:)",
        "transitionCoordinator()",
        "transitionFromViewController(_:toViewController:duration:options:animations:completion:)",
        "viewDidAppear(_:)",
        "viewDidDisappear(_:)",
        "viewDidLoad()",
        "viewWillAppear(_:)",
        "viewWillDisappear(_:)",
        //XCTestCase
        "setUp()",
        "tearDown()"
    ]
stale[bot] commented 3 years ago

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!

sindresorhus commented 3 years ago

Please keep it open.

stale[bot] commented 3 years ago

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!

sindresorhus commented 3 years ago

Please keep it open.