mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Don’t trigger redundant_void_return when using subscripts
This commit is contained in:
+3
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user