-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
#2079 - Implemented the new sublclass rule. #2081
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2081 +/- ##
==========================================
+ Coverage 89.68% 89.71% +0.03%
==========================================
Files 259 261 +2
Lines 15020 15066 +46
Branches 977 980 +3
==========================================
+ Hits 13471 13517 +46
Misses 1532 1532
Partials 17 17
Continue to review full report at Codecov.
|
@@ -0,0 +1,5 @@ | |||
<component name="ProjectCodeStyleConfiguration"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't be commited
identifier: "subclass", | ||
name: "Subclass", | ||
description: "Subclassing is prohibited.", | ||
kind: .style |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should provide triggeringExamples
and nonTriggeringExamples
identifier: "subclass", | ||
name: "Subclass", | ||
description: "Subclassing is prohibited.", | ||
kind: .style |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be probably .idiomatic
kind and not .style
import SourceKittenFramework | ||
|
||
public struct SubClassRule: ASTRule, ConfigurationProviderRule, OptInRule { | ||
public var configuration = SeverityLevelsConfiguration(warning: 0, error: 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use SeverityConfiguration
return [] | ||
} | ||
|
||
if contentsNSString.contains("super.") || contentsNSString.contains("super()") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not the right way of doing this since you can have subclasses that don't call super
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelofabri What would be the right way in your opinion? The SourceKit
does not distinguish the inheritance between the interfaces and superclasses. It only shows that the class inherits from something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we should have a rule that triggers if you don't add final
to a class, as @SDGGiesbrecht suggested.
There's not a lot of value (and in fact I'd argue that it's worst) to trigger a violation on cases where you don't have an alternative, usually dealing with dependencies (either system frameworks like UIKit or 3rd party ones).
As per #2079
I have implemented a new rule that prohibits subclassing.