go/internal/lsp/analysis/unusedvariable
Francesco Renzi 1a4e02fee4 internal/lsp/analysis/unusedvariable: add analyzer
This analyzer suggests fixes for unused variable errors.
In declarations it will remove the whole statement if the offending
variable is the only one declared in that statement, otherwise it will
just delete the offending variable.
In assignments it will remove the whole statement if the offending
variable is the only one assigned in that statement, otherwise it will
rename the offending variable to `_`. If the assignment RHS contains a
statement that can cause a side effect (a function call or reading from
a channel), the assignment will be removed but RHS will be preserved.

Fixes golang/go#48975

Change-Id: I3850f1b0340cd5ae63249931df3a5403d8617080
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394934
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-07-15 14:27:36 +00:00
..
testdata/src internal/lsp/analysis/unusedvariable: add analyzer 2022-07-15 14:27:36 +00:00
unusedvariable.go internal/lsp/analysis/unusedvariable: add analyzer 2022-07-15 14:27:36 +00:00
unusedvariable_test.go internal/lsp/analysis/unusedvariable: add analyzer 2022-07-15 14:27:36 +00:00