diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdb4b2552..53a9c61443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRule.swift b/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRule.swift index c74ed699fa..dd4552c79a 100644 --- a/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRule.swift +++ b/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRule.swift @@ -177,7 +177,7 @@ private final class SyntacticSugarRuleVisitor: SyntaxVisitor { // Skip checks for 'self' or \T Dictionary.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 } diff --git a/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRuleExamples.swift b/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRuleExamples.swift index 861fd880e1..2c84760e79 100644 --- a/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRuleExamples.swift +++ b/Source/SwiftLintFramework/Rules/Idiomatic/SyntacticSugarRuleExamples.swift @@ -27,7 +27,8 @@ internal enum SyntacticSugarRuleExamples { Example("let x: Foo.Optional"), Example("let x = case Optional.none = obj"), - Example("let a = Swift.Optional.none") + Example("let a = Swift.Optional.none"), + Example("func f() -> [Array.Index] { [Array.Index]() }", excludeFromDocumentation: true) ] static let triggering = [