Skip to content

Commit 0556adb

Browse files
samsalisburygopherbot
authored andcommitted
gopls: skip unusedparams for generated files
The unusedparams analyzer makes a lot of noise for some generated files, notably those generated by protoc-gen-go. Since we can't actually edit generated files to fix this issue, it seems better not to report it. Fixes golang/go#71481 Change-Id: I4e73c74312dfea6ef4ce631cc029764519d6b809 Reviewed-on: https://go-review.googlesource.com/c/tools/+/645575 Reviewed-by: Sam Salisbury <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Findley <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Hongxiang Jiang <[email protected]>
1 parent e9f7be9 commit 0556adb

File tree

9 files changed

+235
-140
lines changed

9 files changed

+235
-140
lines changed

gopls/doc/analyzers.md

+2
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,8 @@ arguments at call sites, while taking care to preserve any side
10001000
effects in the argument expressions; see
10011001
https://github.com/golang/tools/releases/tag/gopls%2Fv0.14.
10021002

1003+
This analyzer ignores generated code.
1004+
10031005
Default: on.
10041006

10051007
Package documentation: [unusedparams](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedparams)

gopls/internal/analysis/unusedparams/doc.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131
// arguments at call sites, while taking care to preserve any side
3232
// effects in the argument expressions; see
3333
// https://github.com/golang/tools/releases/tag/gopls%2Fv0.14.
34+
//
35+
// This analyzer ignores generated code.
3436
package unusedparams

gopls/internal/analysis/unusedparams/testdata/src/generatedcode/generatedcode.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Code generated with somegen DO NOT EDIT.
2+
//
3+
// Because this file is generated, there should be no diagnostics
4+
// reported for any unused parameters.
5+
6+
package generatedcode
7+
8+
// generatedInterface exists to ensure that the generated code
9+
// is considered when determining whether parameters are used
10+
// in non-generated code.
11+
type generatedInterface interface{ n(f bool) }
12+
13+
func a(x bool) { println() }
14+
15+
var v = func(x bool) { println() }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package generatedcode
2+
3+
// This file does not have the generated code comment.
4+
// It exists to ensure that generated code is considered
5+
// when determining whether or not function parameters
6+
// are used.
7+
8+
type implementsGeneratedInterface struct{}
9+
10+
// The f parameter should not be reported as unused,
11+
// because this method implements the parent interface defined
12+
// in the generated code.
13+
func (implementsGeneratedInterface) n(f bool) {
14+
// The body must not be empty, otherwise unusedparams will
15+
// not report the unused parameter regardles of the
16+
// interface.
17+
println()
18+
}
19+
20+
func b(x bool) { println() } // want "unused parameter: x"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package generatedcode
2+
3+
// This file does not have the generated code comment.
4+
// It exists to ensure that generated code is considered
5+
// when determining whether or not function parameters
6+
// are used.
7+
8+
type implementsGeneratedInterface struct{}
9+
10+
// The f parameter should not be reported as unused,
11+
// because this method implements the parent interface defined
12+
// in the generated code.
13+
func (implementsGeneratedInterface) n(f bool) {
14+
// The body must not be empty, otherwise unusedparams will
15+
// not report the unused parameter regardles of the
16+
// interface.
17+
println()
18+
}
19+
20+
func b(_ bool) { println() } // want "unused parameter: x"

0 commit comments

Comments
 (0)