Skip to content

Commit

Permalink
Fix false positives on explicit_type_interface rule (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut authored and jpsim committed Nov 28, 2018
1 parent 9d47c34 commit 38b0114
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
[Marcelo Fabri](https://github.com/marcelofabri)
[#2489](https://github.com/realm/SwiftLint/issues/2489)

* Fix false positives on `explicit_type_interface` rule when
configured with option `allowRedundancy` set to `true`.
[Cihat Gündüz](https://github.com/Dschee)
[#2425](https://github.com/realm/SwiftLint/issues/2425)

## 0.29.0: A Laundry List of Changes

#### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public struct ExplicitTypeInterfaceRule: ASTRule, OptInRule, ConfigurationProvid
}

let contentAfterName = file.contents.bridge().substring(from: afterNameRange.location)
let initCallRegex = regex("^\\s*=\\s*\\p{Lu}[^\\(\\s<]*(?:<[^\\>]*>)?\\(")
let initCallRegex = regex(
"^\\s*=\\s*(?:try[!?]?\\s+)?\\[?\\p{Lu}[^\\(\\s<]*(?:<[^\\>]*>)?(?::\\s*[^\\(\\n]+)?\\]?\\("
)

return initCallRegex.firstMatch(in: contentAfterName, options: [], range: contentAfterName.fullNSRange) != nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ class ExplicitTypeInterfaceRuleTests: XCTestCase {
"class Foo {\n class var myVar: Int? = 0\n}\n",
"class Foo {\n static let shared = Foo()\n}\n",
"class Foo {\n let myVar = Int(0)\n}\n",
"class Foo {\n let myVar = Set<Int>(0)\n}\n"
"class Foo {\n let myVar = Set<Int>(0)\n}\n",
"class Foo {\n let regex = try! NSRegularExpression(pattern: \".*\")\n}\n",
"class Foo {\n let regex = try? NSRegularExpression(pattern: \".*\")\n}\n",
"class Foo {\n let array = [String]()\n}\n",
"class Foo {\n let dict = [String: String]()\n}\n",
"class Foo {\n let dict = [String: [String: Array<String>]]()\n}\n"
]
let triggeringExamples = [
"class Foo {\n ↓var myVar = 0\n\n}\n",
"class Foo {\n ↓let mylet = 0\n\n}\n",
"class Foo {\n ↓static var myStaticVar = 0\n}\n",
"class Foo {\n ↓class var myClassVar = 0\n}\n"
"class Foo {\n ↓class var myClassVar = 0\n}\n",
"class Foo {\n ↓let array = [\"foo\", \"bar\"]\n}\n",
"class Foo {\n ↓let dict = [\"foo\": \"bar\"]\n}\n"
]
let description = ExplicitTypeInterfaceRule.description
.with(triggeringExamples: triggeringExamples)
Expand Down

0 comments on commit 38b0114

Please sign in to comment.