Skip to content

Commit e1eae45

Browse files
committed
Fix unstable parameter USR
1 parent 71d8866 commit e1eae45

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Fix unused import false-positives where the only referenced declaration is generated by a macro.
1515
- Fix building with Bazel on Linux by excluding Xcode support.
1616
- Fix slow baseline filtering for large projects with many results.
17+
- Fix inconsistent unused parameter results when the function is declared in a file that is a member of multiple targets.
1718

1819
## 3.1.0 (2025-04-05)
1920

Sources/PeripheryKit/Results/CodeClimateFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ final class CodeClimateFormatter: OutputFormatter {
2828
.joined(separator: ", ")
2929

3030
let fingerprint: String = if result.declaration.kind == .varParameter,
31-
let parentFingerprint = result.declaration.parent?.usrs.joined(separator: "."),
31+
let parentFingerprint = result.declaration.parent?.usrs.sorted().joined(separator: "."),
3232
let argumentName = result.declaration.name
3333
{
3434
// As function parameters do not have a mangled name that can be used for the fingerprint
3535
// we take the mangled name of the function and append the position
3636
"\(parentFingerprint)-\(argumentName)"
3737
} else {
38-
result.declaration.usrs.joined(separator: ".")
38+
result.declaration.usrs.sorted().joined(separator: ".")
3939
}
4040

4141
let object: [AnyHashable: Any] = [

Sources/PeripheryKit/Results/CsvFormatter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ final class CsvFormatter: OutputFormatter {
6262
location: Location,
6363
hint: String?
6464
) -> String {
65-
let joinedModifiers = attributes.joined(separator: "|")
66-
let joinedAttributes = modifiers.joined(separator: "|")
67-
let joinedUsrs = usrs.joined(separator: "|")
65+
let joinedModifiers = attributes.sorted().joined(separator: "|")
66+
let joinedAttributes = modifiers.sorted().joined(separator: "|")
67+
let joinedUsrs = usrs.sorted().joined(separator: "|")
6868
let path = locationDescription(location)
6969
return "\(kind),\(name ?? ""),\(joinedModifiers),\(joinedAttributes),\(accessibility ?? ""),\(joinedUsrs),\(path),\(hint ?? "")"
7070
}

Sources/PeripheryKit/Results/JsonFormatter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ final class JsonFormatter: OutputFormatter {
1616
for result in results {
1717
let object: [AnyHashable: Any] = [
1818
"kind": result.declaration.kind.rawValue,
19-
"modules": Array(result.declaration.location.file.modules),
19+
"modules": result.declaration.location.file.modules.sorted(),
2020
"name": result.declaration.name ?? "",
21-
"modifiers": Array(result.declaration.modifiers),
22-
"attributes": Array(result.declaration.attributes),
21+
"modifiers": result.declaration.modifiers.sorted(),
22+
"attributes": result.declaration.attributes.sorted(),
2323
"accessibility": result.declaration.accessibility.value.rawValue,
24-
"ids": Array(result.declaration.usrs),
24+
"ids": result.declaration.usrs.sorted(),
2525
"hints": [describe(result.annotation)],
2626
"location": locationDescription(result.declaration.location),
2727
]

Sources/SyntaxAnalysis/UnusedParameterParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public struct Parameter: Item, Hashable {
5151
}
5252

5353
public func makeDeclaration(withParent parent: Declaration) -> Declaration {
54-
let parentUsrs = parent.usrs.joined(separator: "-")
54+
let parentUsrs = parent.usrs.sorted().joined(separator: "-")
5555
let usr = "param-\(name)-\(parent.name ?? "unknown-function")-\(parentUsrs)"
5656
let decl = Declaration(kind: .varParameter, usrs: [usr], location: location)
5757
decl.name = name

0 commit comments

Comments
 (0)