Don’t trigger redundant_void_return when using subscripts

This commit is contained in:
Marcelo Fabri
2019-04-29 09:47:00 -07:00
parent 27bd825e05
commit d14d79d2c4
3 changed files with 21 additions and 3 deletions
+3 -1
View File
@@ -14,7 +14,9 @@
#### Bug Fixes
* None.
* Don't trigger `redundant_void_return` violations when using `subscript` as the
return type is required.
[Marcelo Fabri](https://github.com/marcelofabri)
## 0.32.0: Wash-N-Fold-N-Reduce
+8
View File
@@ -17070,6 +17070,14 @@ func foo() -> Void!
```
```swift
struct A {
subscript(key: String) {
print(key)
}
}
```
</details>
<details>
<summary>Triggering Examples</summary>
@@ -23,7 +23,14 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
"func foo() -> ()?\n",
"func foo() -> ()!\n",
"func foo() -> Void?\n",
"func foo() -> Void!\n"
"func foo() -> Void!\n",
"""
struct A {
subscript(key: String) {
print(key)
}
}
"""
],
triggeringExamples: [
"func foo()↓ -> Void {}\n",
@@ -51,6 +58,7 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
private let pattern = "\\s*->\\s*(?:Void\\b|\\(\\s*\\))(?![?!])"
private let excludingKinds = SyntaxKind.allKinds.subtracting([.typeidentifier])
private let functionKinds = SwiftDeclarationKind.functionKinds.subtracting([.functionSubscript])
public func validate(file: File, kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [StyleViolation] {
@@ -63,7 +71,7 @@ public struct RedundantVoidReturnRule: ConfigurationProviderRule, SubstitutionCo
public func violationRanges(in file: File, kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) -> [NSRange] {
guard SwiftDeclarationKind.functionKinds.contains(kind),
guard functionKinds.contains(kind),
let nameOffset = dictionary.nameOffset,
let nameLength = dictionary.nameLength,
let length = dictionary.length,