Skip to content

Commit

Permalink
Merge pull request #1556 from realm/jp-recursive-super
Browse files Browse the repository at this point in the history
Recursively call extractCallsToSuper(methodName:)
  • Loading branch information
jpsim authored May 23, 2017
2 parents 14407ec + 201a74e commit 118c73c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
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

0 comments on commit 118c73c

Please sign in to comment.