Ignore array types if their associated Index is accessed (#3970)

This commit is contained in:
Danny Mösch
2022-05-08 01:11:53 +02:00
committed by GitHub
parent f880b66cbf
commit ca9217d5e1
3 changed files with 7 additions and 3 deletions
+4 -1
View File
@@ -21,7 +21,10 @@
#### Bug Fixes
* None.
* Ignore array types in `syntactic_sugar` rule if their associated `Index` is
accessed.
[SimplyDanny](https://github.com/SimplyDanny)
[#3502](https://github.com/realm/SwiftLint/issues/3502)
## 0.47.1: Smarter Appliance
@@ -177,7 +177,7 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor {
// Skip checks for 'self' or \T Dictionary<Key, Value>.self
if let parent = node.parent?.as(MemberAccessExprSyntax.self),
let lastToken = Array(parent.tokens).last?.tokenKind,
lastToken == .selfKeyword || lastToken == .identifier("Type") || lastToken == .identifier("none") {
[.selfKeyword, .identifier("Type"), .identifier("none"), .identifier("Index")].contains(lastToken) {
return
}
@@ -27,7 +27,8 @@ internal enum SyntacticSugarRuleExamples {
Example("let x: Foo.Optional<String>"),
Example("let x = case Optional<Any>.none = obj"),
Example("let a = Swift.Optional<String?>.none")
Example("let a = Swift.Optional<String?>.none"),
Example("func f() -> [Array<Int>.Index] { [Array<Int>.Index]() }", excludeFromDocumentation: true)
]
static let triggering = [