Skip to content

Commit f6bd4f1

Browse files
authored
fix(inspections): fix unused inspection for _ names (#107)
Fixes #80
1 parent 9bf0ada commit f6bd4f1

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

server/src/e2e/suite/testcases/inspection/UnusedParameterInspection.test

+12-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ Unused parameter inspection
44
fun foo(param: Int) {
55
}
66
------------------------------------------------------------------------
7-
3 0:8 to 0:13 Parameter 'param: Int' is never used (tact)
7+
3 0:8 to 0:13 Parameter 'param' is never used (tact)
8+
9+
========================================================================
10+
Unused _ parameter inspection
11+
========================================================================
12+
fun foo(_: Int) {
13+
}
14+
------------------------------------------------------------------------
15+
no issues
816

917
========================================================================
1018
Used parameter
@@ -34,9 +42,9 @@ Multiple unused parameters
3442
fun foo(param: Int, other: String, isTrue: Bool) {
3543
}
3644
------------------------------------------------------------------------
37-
3 0:8 to 0:13 Parameter 'param: Int' is never used (tact)
38-
3 0:20 to 0:25 Parameter 'other: String' is never used (tact)
39-
3 0:35 to 0:41 Parameter 'isTrue: Bool' is never used (tact)
45+
3 0:8 to 0:13 Parameter 'param' is never used (tact)
46+
3 0:20 to 0:25 Parameter 'other' is never used (tact)
47+
3 0:35 to 0:41 Parameter 'isTrue' is never used (tact)
4048

4149
========================================================================
4250
Unused parameter inspection in abstract function

server/src/e2e/suite/testcases/inspection/UnusedVariableInspection.test

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ fun foo() {
77
------------------------------------------------------------------------
88
3 1:8 to 1:9 Variable 'x' is never used (tact)
99

10+
========================================================================
11+
Unused _ variable inspection
12+
========================================================================
13+
fun foo() {
14+
let _ = 1;
15+
}
16+
------------------------------------------------------------------------
17+
no issues
18+
1019
========================================================================
1120
Used variable
1221
========================================================================

server/src/inspections/UnusedInspection.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export abstract class UnusedInspection {
1515
protected abstract checkFile(file: File, diagnostics: lsp.Diagnostic[]): void
1616

1717
protected checkUnused(
18-
node: SyntaxNode,
18+
node: SyntaxNode | null,
1919
file: File,
2020
diagnostics: lsp.Diagnostic[],
2121
options: {
@@ -26,6 +26,8 @@ export abstract class UnusedInspection {
2626
skipIf?: () => boolean
2727
},
2828
) {
29+
if (!node || node.text === "_") return
30+
2931
const references = new Referent(node, file).findReferences()
3032
if (references.length === 0) {
3133
const range = asLspRange(options.rangeNode ?? node)

server/src/inspections/UnusedParameterInspection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class UnusedParameterInspection extends UnusedInspection {
3030
const nameIdent = param.nameIdentifier()
3131
if (!nameIdent) return
3232

33-
this.checkUnused(param.node, fun.file, diagnostics, {
33+
this.checkUnused(param.nameIdentifier(), fun.file, diagnostics, {
3434
kind: "Parameter",
3535
code: "unused-parameter",
3636
rangeNode: nameIdent,

0 commit comments

Comments
 (0)