-
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
Implemented super call rule (#803) #809
Conversation
Current predefined list of included methods:
|
Current coverage is 84.08% (diff: 86.99%)@@ master #809 diff @@
==========================================
Files 102 104 +2
Lines 4105 4228 +123
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 3448 3555 +107
- Misses 657 673 +16
Partials 0 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.
Sorry for late reviews, and thanks for doing this!
Looks mostly good other than my feedbacks.
@@ -6,6 +6,10 @@ | |||
|
|||
##### Enhancements | |||
|
|||
* Add `SuperCallRule` Opt-In rule that warns against overriden methods not calling to super in well known cases (ex: `viewWillAppear`). |
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.
Could you please wrap at 80 characters?
import Foundation | ||
|
||
public struct SuperCallConfiguration: RuleConfiguration, Equatable { | ||
var defaultIncluded = [ |
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.
Sorting this list by class+name alphabetically would be helpful.
var excluded: [String] = [] | ||
var included: [String] = ["*"] | ||
|
||
public var consoleDescription: String { |
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.
consoleDescription
is used on swiftlint rules
.
+--------------------------------+--------+-------------+------------------------+--------------------------------------------------+
| identifier | opt-in | correctable | enabled in your config | configuration |
+--------------------------------+--------+-------------+------------------------+--------------------------------------------------+
| closing_brace | no | yes | yes | warning |
…
| overridden_super_call | yes | no | yes | warning, excluded: [[]], included: [["*"]] |
The existence of defaultIncluded
is not represented here.
Are there any idea for that?
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 expect to see all the method list? It will pollute the table but I think it can be done easily. I am using *
to reference the default list, so I can just return the evaluated list on:
public var consoleDescription: String {
return severityConfiguration.consoleDescription +
", excluded: [\(excluded)]" +
", included: [\(included)]"
}
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.
Ok, never mind. 👍
"invalidateLayoutWithContext(_:)", | ||
//XCTestCase | ||
"tearDown()", | ||
"setUp()" |
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.
Are there any documentation XCTestCase .tearDown()
and XCTestCase .setUp()
require calling 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.
I haven't seen anywhere explicitly, but the default template includes calling super: https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html#//apple_ref/doc/uid/TP40014132-CH4-SW2
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.
It is indeed not mentioned for XCTestCase
but as @marcelofabri comments, it is just there in the templates and assumed in all Apple test example code I have seen so far. We could remove it if you want, although I think since this is an Opt-In rule and it is configurable, I would leave it there as a good practice.
"\t\tself.method()\n" + | ||
"\t}\n" + | ||
"}\n", | ||
] |
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.
Could you please add multiple calling to super triggering example?
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.
I guess the false negative pattern needs to be fixed.
var excluded: [String] = [] | ||
var included: [String] = ["*"] | ||
|
||
public var consoleDescription: String { |
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.
Ok, never mind. 👍
return severityConfiguration.severity | ||
} | ||
|
||
public var resolvedMethodNames: [String] { |
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.
I guess we would not need to re-create resolvedMethodNames
on every calling.
Can we change this to initialize once on first calling?
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.
👍
|
||
guard let offset = dictionary["key.bodyoffset"] as? Int64, | ||
let name = dictionary["key.name"] as? String, | ||
let substructure = dictionary["key.substructure"] as? [SourceKitRepresentable] |
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.
I found false negative pattern:
class ViewController: UIViewController {
override func didReceiveMemoryWarning() {
}
}
that does not have "key.substructure"
.
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.
ouch! thanks for pointing this out! I will check it out ASAP
Take a look now... 1 thing I am not sure if should be changed is that the rule id is |
👍 |
Renamed! Let's hope this now is good enough :) |
Thanks! 🙏 |
PR for issue #803
It basically looks for methods in the whitelist (and marked as
overriden
) and checks that there is exactly onesuper
call somewhere in its implementation.The rule comes with a custom provider that allows configuring the list of methods to include or exclude. The default configuration comes with the most common methods in Cocoa.
Example only checking 2 custom methods: