Skip to content

Commit 1aaa131

Browse files
committed
Fix unused parameter analysis for parameters with name enclosed by backticks. Closes #973
1 parent 6a9f92f commit 1aaa131

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Fix unused import false-positive for modules that export unindexed modules.
1717
- Exclude conditionally imported modules from unused import detection, as they may provide symbols for code that was not compiled.
1818
- Fix `--retain-assign-only-property-types` for properties with trailing comments.
19+
- Fix unused parameter analysis for parameters with name enclosed by backticks.
1920

2021
## 3.2.0 (2025-06-27)
2122

Sources/SyntaxAnalysis/UnusedParameterParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ struct UnusedParameterParser {
211211
let positionSyntax: SyntaxProtocol = syntax.secondName ?? syntax.firstName
212212
let location = sourceLocation(of: positionSyntax.positionAfterSkippingLeadingTrivia)
213213

214-
return Parameter(firstName: syntax.firstName.text,
215-
secondName: syntax.secondName?.text,
214+
return Parameter(firstName: syntax.firstName.identifier?.name,
215+
secondName: syntax.secondName?.identifier?.name,
216216
metatype: metatype,
217217
location: location)
218218
}

Tests/Fixtures/Sources/UnusedParameterFixtures/testBackquote.swift

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class SyntaxFixture22 {
2+
func myFunc(class: String, func: String, `otherUsed`: String, `otherUnused`: String) {
3+
print(`class`)
4+
print(`otherUsed`)
5+
}
6+
}

Tests/PeripheryTests/Syntax/UnusedParameterTest.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,13 @@ final class UnusedParameterTest: XCTestCase {
195195
assertUsed("param", in: "myFunc(param:)")
196196
}
197197

198-
func testBackquote() {
198+
func testBackticks() {
199199
analyze()
200-
assertUsed("class", in: "myFunc(class:func:)")
201-
assertUnused("func", in: "myFunc(class:func:)")
200+
assertUsed("class", in: "myFunc(class:func:otherUsed:otherUnused:)")
201+
assertUsed("otherUsed", in: "myFunc(class:func:otherUsed:otherUnused:)")
202+
203+
assertUnused("func", in: "myFunc(class:func:otherUsed:otherUnused:)")
204+
assertUnused("otherUnused", in: "myFunc(class:func:otherUsed:otherUnused:)")
202205
}
203206

204207
// MARK: - Private

0 commit comments

Comments
 (0)