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

Recursively call extractCallsToSuper(methodName:) #1556

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#1508](https://github.com/realm/SwiftLint/issues/1508)

* Fix false positives in `prohibited_super_call` & `overridden_super_call` rules
where calls to `super` were done in nested scopes such as `defer` blocks.
[JP Simard](https://github.com/jpsim)
[#1301](https://github.com/realm/SwiftLint/issues/1301)

## 0.18.1: Misaligned Drum

##### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ extension Dictionary where Key: ExpressibleByStringLiteral {

internal func extractCallsToSuper(methodName: String) -> [String] {
let superCall = "super.\(methodName)"
return substructure.flatMap { elems in
return substructure.flatMap { elems -> [String] in
guard let type = elems.kind.flatMap({ SwiftExpressionKind(rawValue: $0) }),
let name = elems.name,
type == .call && superCall.contains(name)
else { return nil }
return name
type == .call && superCall.contains(name) else {
return elems.extractCallsToSuper(methodName: methodName)
}
return [name]
}
}
}
7 changes: 7 additions & 0 deletions Source/SwiftLintFramework/Rules/OverriddenSuperCallRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public struct OverriddenSuperCallRule: ConfigurationProviderRule, ASTRule, OptIn
"class Some {\n" +
"\tfunc viewWillAppear(_ animated: Bool) {\n" +
"\t}\n" +
"}\n",
"class VC: UIViewController {\n" +
"\toverride func viewDidLoad() {\n" +
"\t\tdefer {\n" +
"\t\t\tsuper.viewDidLoad()\n" +
"\t\t}\n" +
"\t}\n" +
"}\n"
],
triggeringExamples: [
Expand Down
7 changes: 7 additions & 0 deletions Source/SwiftLintFramework/Rules/ProhibitedSuperRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public struct ProhibitedSuperRule: ConfigurationProviderRule, ASTRule, OptInRule
"\t\tsuper.updateLayer()\n" +
"\t\tself.method2()\n" +
"\t}\n" +
"}\n",
"class VC: NSView {\n" +
"\toverride func updateLayer() {↓\n" +
"\t\tdefer {\n" +
"\t\t\tsuper.updateLayer()\n" +
"\t\t}\n" +
"\t}\n" +
"}\n"
]
)
Expand Down