Skip to content

Commit

Permalink
Ignore array types if their associated Index is accessed (#3970)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored May 7, 2022
1 parent f880b66 commit ca9217d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit ca9217d

Please sign in to comment.