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

Add override_in_extension rule #1888

Merged
merged 3 commits into from
Oct 9, 2017
Merged

Add override_in_extension rule #1888

merged 3 commits into from
Oct 9, 2017

Conversation

marcelofabri
Copy link
Collaborator

Fixes #1884

Let's see how many violations oss-check reports.

@SwiftLintBot
Copy link

SwiftLintBot commented Oct 5, 2017

53 Warnings
⚠️ This PR introduced a violation in Firefox: /Users/distiller/SwiftLint/osscheck/Firefox/Client/Frontend/Browser/BrowserViewController/BrowserViewController+KeyCommands.swift:78:14: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Firefox: /Users/distiller/SwiftLint/osscheck/Firefox/Client/Frontend/Browser/QRCodeViewController.swift:256:19: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Kickstarter: /Users/distiller/SwiftLint/osscheck/Kickstarter/Library/DataSource/UIView-Extensions.swift:37:17: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Nimble: /Users/distiller/SwiftLint/osscheck/Nimble/Tests/NimbleTests/Helpers/XCTestCaseProvider.swift:36:19: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Quick: /Users/distiller/SwiftLint/osscheck/Quick/Tests/QuickTests/QuickTestHelpers/XCTestCaseProvider.swift:36:23: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/Sourcery/Generating/Template/Stencil/Utils/Type+Stencil.swift:12:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:9:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:18:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:29:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:38:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:50:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:60:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:70:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:82:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:96:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:125:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:139:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:147:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:155:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:165:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:174:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:183:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:214:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:225:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Description.generated.swift:233:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Diffable.generated.swift:47:14: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Diffable.generated.swift:85:14: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Diffable.generated.swift:168:14: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Diffable.generated.swift:179:14: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:9:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:18:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:29:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:39:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:46:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:57:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:67:23: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:75:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:84:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:95:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:109:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:129:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:142:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:149:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:156:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:165:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:174:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:183:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:204:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:217:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:227:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in Sourcery: /Users/distiller/SwiftLint/osscheck/Sourcery/SourceryRuntime/Sources/Equality.generated.swift:235:21: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/Extensions/StoreKit+Debug.swift:4:19: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
⚠️ This PR introduced a violation in WordPress: /Users/distiller/SwiftLint/osscheck/WordPress/WordPress/Classes/Extensions/StoreKit+Debug.swift:27:19: warning: Override in Extension Violation: Extensions shouldn't override declarations. (override_in_extension)
12 Messages
📖 Linting Aerial with this PR took 0.42s vs 0.37s on master (13% slower)
📖 Linting Alamofire with this PR took 2.56s vs 2.58s on master (0% faster)
📖 Linting Firefox with this PR took 10.49s vs 10.48s on master (0% slower)
📖 Linting Kickstarter with this PR took 16.74s vs 16.54s on master (1% slower)
📖 Linting Moya with this PR took 1.2s vs 1.22s on master (1% faster)
📖 Linting Nimble with this PR took 1.55s vs 1.55s on master (0% slower)
📖 Linting Quick with this PR took 0.49s vs 0.48s on master (2% slower)
📖 Linting Realm with this PR took 2.62s vs 2.58s on master (1% slower)
📖 Linting SourceKitten with this PR took 0.9s vs 0.9s on master (0% slower)
📖 Linting Sourcery with this PR took 3.8s vs 3.79s on master (0% slower)
📖 Linting Swift with this PR took 11.12s vs 11.15s on master (0% faster)
📖 Linting WordPress with this PR took 10.14s vs 10.26s on master (1% faster)

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Oct 6, 2017

Codecov Report

Merging #1888 into master will increase coverage by 0.02%.
The diff coverage is 92.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1888      +/-   ##
==========================================
+ Coverage   88.76%   88.78%   +0.02%     
==========================================
  Files         238      240       +2     
  Lines       11723    11748      +25     
==========================================
+ Hits        10406    10431      +25     
  Misses       1317     1317
Impacted Files Coverage Δ
...tLintFramework/Rules/NoGroupingExtensionRule.swift 100% <100%> (+10.25%) ⬆️
...tLintFramework/Rules/OverrideInExtensionRule.swift 100% <100%> (ø)
Tests/SwiftLintFrameworkTests/RulesTests.swift 100% <100%> (ø) ⬆️
...wiftLintFramework/Helpers/NamespaceCollector.swift 85.71% <85.71%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 390e5ca...a45a7da. Read the comment docs.

Copy link
Contributor

@mrcljx mrcljx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelofabri Nice PR! Got a nit with the name and this other thing:

I saw that in the linked issue you were already wondering whether this should be opt-in or not.

With people often using extensions to organize their code (e.g. a UITableViewDataSource section for a UITableViewController - can also be seen in osscheck) we should either somehow detect this situation (i.e. file also contains class) or make this opt-in.

CHANGELOG.md Outdated
@@ -10,7 +10,10 @@

##### Enhancements

* None.
* Add `override_in_extension` rule that warns against overriding declarations
in a `extension`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: an extension

public init() {}

public static let description = RuleDescription(
identifier: "override_in_extension",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds assertive (as in do this), instead of restrictive. "disallow_override_in_extensions" maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we have a super consistent naming convention. We already have force_try, force_cast, fallthrough and others that aren't restrictive.

@marcelofabri
Copy link
Collaborator Author

With people often using extensions to organize their code (e.g. a UITableViewDataSource section for a UITableViewController - can also be seen in osscheck) we should either somehow detect this situation (i.e. file also contains class) or make this opt-in.

I was thinking about this, but I was afraid of this situation:

class Foo: NSObject {
    override var description: String {
        return "1"
    }
}

extension Foo {
    override var description: String {
        return "2"
    }
}

However, the compiler already catches this:

'description' has already been overridden

So I'll work on this later 👍

Copy link
Contributor

@mrcljx mrcljx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, naming is already inconsistent across the board. So no reason to block it. :)

@marcelofabri marcelofabri merged commit 98c0fdd into realm:master Oct 9, 2017
@marcelofabri marcelofabri deleted the override-extension branch October 9, 2017 13:45
@jpsim
Copy link
Collaborator

jpsim commented Oct 9, 2017

You are right, naming is already inconsistent across the board. So no reason to block it. :)

If someone wants to audit SwiftLint's naming for related things (flags, rule names, configuration names, config params, etc), I'd be very happy to review. If we settle on a convention, we could also enforce this to some extent with unit tests. Semi-related example: every description string should read like a sentence and be terminated by a period, which we could confirm with tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants