Skip to content

Commit 29a71dd

Browse files
authored
Track variables declared in tuples (#6565)
1 parent f1f735f commit 29a71dd

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
[SimplyDanny](https://github.com/SimplyDanny)
6969
[#6466](https://github.com/realm/SwiftLint/issues/6466)
7070

71+
* Track identifiers declared in tuples to avoid false positives in the
72+
`redundant_self` rule.
73+
[SimplyDanny](https://github.com/SimplyDanny)
74+
[#6553](https://github.com/realm/SwiftLint/issues/6553)
75+
7176
## 0.63.2: High-Speed Extraction
7277

7378
### Breaking

Source/SwiftLintBuiltInRules/Rules/Style/RedundantSelfRuleExamples.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ struct RedundantSelfRuleExamples {
117117
}
118118
}
119119
"""),
120+
Example("""
121+
struct S {
122+
var x = 0, y = 0
123+
init() {
124+
let (x, y) = (1, 2)
125+
self.x = x
126+
self.y = y
127+
}
128+
}
129+
""", configuration: ["only_in_closures": false]),
120130
]
121131

122132
static let triggeringExamples = [

Source/SwiftLintCore/Visitors/DeclaredIdentifiersTrackingVisitor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ open class DeclaredIdentifiersTrackingVisitor<Configuration: RuleConfiguration>:
205205
private func collectIdentifiers(from pattern: PatternSyntax) {
206206
if let id = pattern.as(IdentifierPatternSyntax.self)?.identifier {
207207
scope.addToCurrentScope(.localVariable(name: id))
208+
} else if let tuple = pattern.as(TuplePatternSyntax.self) {
209+
for element in tuple.elements {
210+
collectIdentifiers(from: element.pattern)
211+
}
208212
}
209213
}
210214
}

0 commit comments

Comments
 (0)