forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp: add suggested fix for unusedparams analysis
Suggest replacing the unused function parameter with _. Updates golang/go#36602 Change-Id: I53738e65907b8a4b4857dd8954f1477a043cf442 Reviewed-on: https://go-review.googlesource.com/c/tools/+/374254 Trust: Suzy Mueller <suzmue@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
Showing
6 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
internal/lsp/analysis/unusedparams/testdata/src/a/a.go.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package a | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type parent interface { | ||
n(f bool) | ||
} | ||
|
||
type yuh struct { | ||
a int | ||
} | ||
|
||
func (y *yuh) n(f bool) { | ||
for i := 0; i < 10; i++ { | ||
fmt.Println(i) | ||
} | ||
} | ||
|
||
func a(i1 int, _ int, i3 int) int { // want "potentially unused parameter: 'i2'" | ||
i3 += i1 | ||
_ = func(_ int) int { // want "potentially unused parameter: 'z'" | ||
_ = 1 | ||
return 1 | ||
} | ||
return i3 | ||
} | ||
|
||
func b(_ bytes.Buffer) { // want "potentially unused parameter: 'c'" | ||
_ = 1 | ||
} | ||
|
||
func z(_ http.ResponseWriter, _ *http.Request) { // want "potentially unused parameter: 'h'" | ||
fmt.Println("Before") | ||
} | ||
|
||
func l(h http.Handler) http.Handler { | ||
return http.HandlerFunc(z) | ||
} | ||
|
||
func mult(a, _ int) int { // want "potentially unused parameter: 'b'" | ||
a += 1 | ||
return a | ||
} | ||
|
||
func y(a int) { | ||
panic("yo") | ||
} |
2 changes: 1 addition & 1 deletion
2
internal/lsp/analysis/unusedparams/testdata/src/typeparams/typeparams.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
internal/lsp/analysis/unusedparams/testdata/src/typeparams/typeparams.go.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package typeparams | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type parent[T any] interface { | ||
n(f T) | ||
} | ||
|
||
type yuh[T any] struct { | ||
a T | ||
} | ||
|
||
func (y *yuh[int]) n(f bool) { | ||
for i := 0; i < 10; i++ { | ||
fmt.Println(i) | ||
} | ||
} | ||
|
||
func a[T comparable](i1 int, _ T, i3 int) int { // want "potentially unused parameter: 'i2'" | ||
i3 += i1 | ||
_ = func(_ int) int { // want "potentially unused parameter: 'z'" | ||
_ = 1 | ||
return 1 | ||
} | ||
return i3 | ||
} | ||
|
||
func b[T any](_ bytes.Buffer) { // want "potentially unused parameter: 'c'" | ||
_ = 1 | ||
} | ||
|
||
func z[T http.ResponseWriter](_ T, _ *http.Request) { // want "potentially unused parameter: 'h'" | ||
fmt.Println("Before") | ||
} | ||
|
||
func l(h http.Handler) http.Handler { | ||
return http.HandlerFunc(z[http.ResponseWriter]) | ||
} | ||
|
||
func mult(a, _ int) int { // want "potentially unused parameter: 'b'" | ||
a += 1 | ||
return a | ||
} | ||
|
||
func y[T any](a T) { | ||
panic("yo") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters