Skip to content

Commit c0dbb60

Browse files
adonovangopherbot
authored andcommitted
gopls: tweak release notes
Also, move gofix command into a package so that it can be "go run" from the release branch. Change-Id: I0a75c1ec4b00d22eef6c13c5162dd02ed9ef272f Reviewed-on: https://go-review.googlesource.com/c/tools/+/649318 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 85a3833 commit c0dbb60

File tree

7 files changed

+88
-23
lines changed

7 files changed

+88
-23
lines changed

gopls/doc/analyzers.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,15 @@ existing code by using more modern features of Go, such as:
500500
- replacing Split in "for range strings.Split(...)" by go1.24's
501501
more efficient SplitSeq;
502502

503+
To apply all modernization fixes en masse, you can use the
504+
following command:
505+
506+
$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
507+
508+
If the tool warns of conflicting fixes, you may need to run it more
509+
than once until it has applied all fixes cleanly. This command is
510+
not an officially supported interface and may change in the future.
511+
503512
Default: on.
504513

505514
Package documentation: [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize)
@@ -962,12 +971,29 @@ A method is considered unused if it is unexported, not referenced
962971
that of any method of an interface type declared within the same
963972
package.
964973

965-
The tool may report a false positive for a declaration of an
966-
unexported function that is referenced from another package using
967-
the go:linkname mechanism, if the declaration's doc comment does
968-
not also have a go:linkname comment. (Such code is in any case
969-
strongly discouraged: linkname annotations, if they must be used at
970-
all, should be used on both the declaration and the alias.)
974+
The tool may report false positives in some situations, for
975+
example:
976+
977+
- For a declaration of an unexported function that is referenced
978+
from another package using the go:linkname mechanism, if the
979+
declaration's doc comment does not also have a go:linkname
980+
comment.
981+
982+
(Such code is in any case strongly discouraged: linkname
983+
annotations, if they must be used at all, should be used on both
984+
the declaration and the alias.)
985+
986+
- For compiler intrinsics in the "runtime" package that, though
987+
never referenced, are known to the compiler and are called
988+
indirectly by compiled object code.
989+
990+
- For functions called only from assembly.
991+
992+
- For functions called only from files whose build tags are not
993+
selected in the current build configuration.
994+
995+
See https://github.com/golang/go/issues/71686 for discussion of
996+
these limitations.
971997

972998
The unusedfunc algorithm is not as precise as the
973999
golang.org/x/tools/cmd/deadcode tool, but it has the advantage that

gopls/doc/release/v0.18.0.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@ details to be reported as diagnostics. For example, it indicates which
3737
variables escape to the heap, and which array accesses require bounds
3838
checks.
3939

40+
TODO: add links to the complete manual for each item.
41+
4042
## New `modernize` analyzer
4143

4244
Gopls now reports when code could be simplified or clarified by
4345
using more modern features of Go, and provides a quick fix to apply
4446
the change.
4547

46-
Examples:
48+
For example, a conditional assignment using an if/else statement may
49+
be replaced by a call to the `min` or `max` built-in functions added
50+
in Go 1.18.
4751

48-
- replacement of conditional assignment using an if/else statement by
49-
a call to the `min` or `max` built-in functions added in Go 1.18;
52+
Use this command to apply modernization fixes en masse:
53+
```
54+
$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
55+
```
5056

5157
## New `unusedfunc` analyzer
5258

@@ -97,6 +103,12 @@ const Ptr = Pointer
97103
```
98104
gopls will suggest replacing `Ptr` in your code with `Pointer`.
99105

106+
Use this command to apply such fixes en masse:
107+
108+
```
109+
$ go run golang.org/x/tools/gopls/internal/analysis/gofix/cmd/gofix@latest -test ./...
110+
```
111+
100112
## "Implementations" supports generics
101113

102114
At long last, the "Go to Implementations" feature now fully supports

gopls/internal/analysis/gofix/main.go renamed to gopls/internal/analysis/gofix/cmd/gofix/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
// Copyright 2023 The Go Authors. All rights reserved.
1+
// Copyright 2025 The Go Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build ignore
6-
// +build ignore
7-
85
// The inline command applies the inliner to the specified packages of
96
// Go source code. Run with:
107
//

gopls/internal/analysis/gofix/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,9 @@ or before a group, applying to every constant in the group:
7777
)
7878
7979
The proposal https://go.dev/issue/32816 introduces the "//go:fix" directives.
80+
81+
You can use this (officially unsupported) command to apply gofix fixes en masse:
82+
83+
$ go run golang.org/x/tools/gopls/internal/analysis/gofix/cmd/gofix@latest -test ./...
8084
*/
8185
package gofix

gopls/internal/analysis/modernize/doc.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@
3232
// for i := range n {}, added in go1.22;
3333
// - replacing Split in "for range strings.Split(...)" by go1.24's
3434
// more efficient SplitSeq;
35+
//
36+
// To apply all modernization fixes en masse, you can use the
37+
// following command:
38+
//
39+
// $ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
40+
//
41+
// If the tool warns of conflicting fixes, you may need to run it more
42+
// than once until it has applied all fixes cleanly. This command is
43+
// not an officially supported interface and may change in the future.
3544
package modernize

gopls/internal/analysis/unusedfunc/doc.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,29 @@
2020
// that of any method of an interface type declared within the same
2121
// package.
2222
//
23-
// The tool may report a false positive for a declaration of an
24-
// unexported function that is referenced from another package using
25-
// the go:linkname mechanism, if the declaration's doc comment does
26-
// not also have a go:linkname comment. (Such code is in any case
27-
// strongly discouraged: linkname annotations, if they must be used at
28-
// all, should be used on both the declaration and the alias.)
23+
// The tool may report false positives in some situations, for
24+
// example:
25+
//
26+
// - For a declaration of an unexported function that is referenced
27+
// from another package using the go:linkname mechanism, if the
28+
// declaration's doc comment does not also have a go:linkname
29+
// comment.
30+
//
31+
// (Such code is in any case strongly discouraged: linkname
32+
// annotations, if they must be used at all, should be used on both
33+
// the declaration and the alias.)
34+
//
35+
// - For compiler intrinsics in the "runtime" package that, though
36+
// never referenced, are known to the compiler and are called
37+
// indirectly by compiled object code.
38+
//
39+
// - For functions called only from assembly.
40+
//
41+
// - For functions called only from files whose build tags are not
42+
// selected in the current build configuration.
43+
//
44+
// See https://github.com/golang/go/issues/71686 for discussion of
45+
// these limitations.
2946
//
3047
// The unusedfunc algorithm is not as precise as the
3148
// golang.org/x/tools/cmd/deadcode tool, but it has the advantage that

gopls/internal/doc/api.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@
510510
},
511511
{
512512
"Name": "\"modernize\"",
513-
"Doc": "simplify code by using modern constructs\n\nThis analyzer reports opportunities for simplifying and clarifying\nexisting code by using more modern features of Go, such as:\n\n - replacing an if/else conditional assignment by a call to the\n built-in min or max functions added in go1.21;\n - replacing sort.Slice(x, func(i, j int) bool) { return s[i] \u003c s[j] }\n by a call to slices.Sort(s), added in go1.21;\n - replacing interface{} by the 'any' type added in go1.18;\n - replacing append([]T(nil), s...) by slices.Clone(s) or\n slices.Concat(s), added in go1.21;\n - replacing a loop around an m[k]=v map update by a call\n to one of the Collect, Copy, Clone, or Insert functions\n from the maps package, added in go1.21;\n - replacing []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...),\n added in go1.19;\n - replacing uses of context.WithCancel in tests with t.Context, added in\n go1.24;\n - replacing omitempty by omitzero on structs, added in go1.24;\n - replacing append(s[:i], s[i+1]...) by slices.Delete(s, i, i+1),\n added in go1.21\n - replacing a 3-clause for i := 0; i \u003c n; i++ {} loop by\n for i := range n {}, added in go1.22;\n - replacing Split in \"for range strings.Split(...)\" by go1.24's\n more efficient SplitSeq;",
513+
"Doc": "simplify code by using modern constructs\n\nThis analyzer reports opportunities for simplifying and clarifying\nexisting code by using more modern features of Go, such as:\n\n - replacing an if/else conditional assignment by a call to the\n built-in min or max functions added in go1.21;\n - replacing sort.Slice(x, func(i, j int) bool) { return s[i] \u003c s[j] }\n by a call to slices.Sort(s), added in go1.21;\n - replacing interface{} by the 'any' type added in go1.18;\n - replacing append([]T(nil), s...) by slices.Clone(s) or\n slices.Concat(s), added in go1.21;\n - replacing a loop around an m[k]=v map update by a call\n to one of the Collect, Copy, Clone, or Insert functions\n from the maps package, added in go1.21;\n - replacing []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...),\n added in go1.19;\n - replacing uses of context.WithCancel in tests with t.Context, added in\n go1.24;\n - replacing omitempty by omitzero on structs, added in go1.24;\n - replacing append(s[:i], s[i+1]...) by slices.Delete(s, i, i+1),\n added in go1.21\n - replacing a 3-clause for i := 0; i \u003c n; i++ {} loop by\n for i := range n {}, added in go1.22;\n - replacing Split in \"for range strings.Split(...)\" by go1.24's\n more efficient SplitSeq;\n\nTo apply all modernization fixes en masse, you can use the\nfollowing command:\n\n\t$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...\n\nIf the tool warns of conflicting fixes, you may need to run it more\nthan once until it has applied all fixes cleanly. This command is\nnot an officially supported interface and may change in the future.",
514514
"Default": "true"
515515
},
516516
{
@@ -630,7 +630,7 @@
630630
},
631631
{
632632
"Name": "\"unusedfunc\"",
633-
"Doc": "check for unused functions and methods\n\nThe unusedfunc analyzer reports functions and methods that are\nnever referenced outside of their own declaration.\n\nA function is considered unused if it is unexported and not\nreferenced (except within its own declaration).\n\nA method is considered unused if it is unexported, not referenced\n(except within its own declaration), and its name does not match\nthat of any method of an interface type declared within the same\npackage.\n\nThe tool may report a false positive for a declaration of an\nunexported function that is referenced from another package using\nthe go:linkname mechanism, if the declaration's doc comment does\nnot also have a go:linkname comment. (Such code is in any case\nstrongly discouraged: linkname annotations, if they must be used at\nall, should be used on both the declaration and the alias.)\n\nThe unusedfunc algorithm is not as precise as the\ngolang.org/x/tools/cmd/deadcode tool, but it has the advantage that\nit runs within the modular analysis framework, enabling near\nreal-time feedback within gopls.",
633+
"Doc": "check for unused functions and methods\n\nThe unusedfunc analyzer reports functions and methods that are\nnever referenced outside of their own declaration.\n\nA function is considered unused if it is unexported and not\nreferenced (except within its own declaration).\n\nA method is considered unused if it is unexported, not referenced\n(except within its own declaration), and its name does not match\nthat of any method of an interface type declared within the same\npackage.\n\nThe tool may report false positives in some situations, for\nexample:\n\n - For a declaration of an unexported function that is referenced\n from another package using the go:linkname mechanism, if the\n declaration's doc comment does not also have a go:linkname\n comment.\n\n (Such code is in any case strongly discouraged: linkname\n annotations, if they must be used at all, should be used on both\n the declaration and the alias.)\n\n - For compiler intrinsics in the \"runtime\" package that, though\n never referenced, are known to the compiler and are called\n indirectly by compiled object code.\n\n - For functions called only from assembly.\n\n - For functions called only from files whose build tags are not\n selected in the current build configuration.\n\nSee https://github.com/golang/go/issues/71686 for discussion of\nthese limitations.\n\nThe unusedfunc algorithm is not as precise as the\ngolang.org/x/tools/cmd/deadcode tool, but it has the advantage that\nit runs within the modular analysis framework, enabling near\nreal-time feedback within gopls.",
634634
"Default": "true"
635635
},
636636
{
@@ -1189,7 +1189,7 @@
11891189
},
11901190
{
11911191
"Name": "modernize",
1192-
"Doc": "simplify code by using modern constructs\n\nThis analyzer reports opportunities for simplifying and clarifying\nexisting code by using more modern features of Go, such as:\n\n - replacing an if/else conditional assignment by a call to the\n built-in min or max functions added in go1.21;\n - replacing sort.Slice(x, func(i, j int) bool) { return s[i] \u003c s[j] }\n by a call to slices.Sort(s), added in go1.21;\n - replacing interface{} by the 'any' type added in go1.18;\n - replacing append([]T(nil), s...) by slices.Clone(s) or\n slices.Concat(s), added in go1.21;\n - replacing a loop around an m[k]=v map update by a call\n to one of the Collect, Copy, Clone, or Insert functions\n from the maps package, added in go1.21;\n - replacing []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...),\n added in go1.19;\n - replacing uses of context.WithCancel in tests with t.Context, added in\n go1.24;\n - replacing omitempty by omitzero on structs, added in go1.24;\n - replacing append(s[:i], s[i+1]...) by slices.Delete(s, i, i+1),\n added in go1.21\n - replacing a 3-clause for i := 0; i \u003c n; i++ {} loop by\n for i := range n {}, added in go1.22;\n - replacing Split in \"for range strings.Split(...)\" by go1.24's\n more efficient SplitSeq;",
1192+
"Doc": "simplify code by using modern constructs\n\nThis analyzer reports opportunities for simplifying and clarifying\nexisting code by using more modern features of Go, such as:\n\n - replacing an if/else conditional assignment by a call to the\n built-in min or max functions added in go1.21;\n - replacing sort.Slice(x, func(i, j int) bool) { return s[i] \u003c s[j] }\n by a call to slices.Sort(s), added in go1.21;\n - replacing interface{} by the 'any' type added in go1.18;\n - replacing append([]T(nil), s...) by slices.Clone(s) or\n slices.Concat(s), added in go1.21;\n - replacing a loop around an m[k]=v map update by a call\n to one of the Collect, Copy, Clone, or Insert functions\n from the maps package, added in go1.21;\n - replacing []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...),\n added in go1.19;\n - replacing uses of context.WithCancel in tests with t.Context, added in\n go1.24;\n - replacing omitempty by omitzero on structs, added in go1.24;\n - replacing append(s[:i], s[i+1]...) by slices.Delete(s, i, i+1),\n added in go1.21\n - replacing a 3-clause for i := 0; i \u003c n; i++ {} loop by\n for i := range n {}, added in go1.22;\n - replacing Split in \"for range strings.Split(...)\" by go1.24's\n more efficient SplitSeq;\n\nTo apply all modernization fixes en masse, you can use the\nfollowing command:\n\n\t$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...\n\nIf the tool warns of conflicting fixes, you may need to run it more\nthan once until it has applied all fixes cleanly. This command is\nnot an officially supported interface and may change in the future.",
11931193
"URL": "https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize",
11941194
"Default": true
11951195
},
@@ -1333,7 +1333,7 @@
13331333
},
13341334
{
13351335
"Name": "unusedfunc",
1336-
"Doc": "check for unused functions and methods\n\nThe unusedfunc analyzer reports functions and methods that are\nnever referenced outside of their own declaration.\n\nA function is considered unused if it is unexported and not\nreferenced (except within its own declaration).\n\nA method is considered unused if it is unexported, not referenced\n(except within its own declaration), and its name does not match\nthat of any method of an interface type declared within the same\npackage.\n\nThe tool may report a false positive for a declaration of an\nunexported function that is referenced from another package using\nthe go:linkname mechanism, if the declaration's doc comment does\nnot also have a go:linkname comment. (Such code is in any case\nstrongly discouraged: linkname annotations, if they must be used at\nall, should be used on both the declaration and the alias.)\n\nThe unusedfunc algorithm is not as precise as the\ngolang.org/x/tools/cmd/deadcode tool, but it has the advantage that\nit runs within the modular analysis framework, enabling near\nreal-time feedback within gopls.",
1336+
"Doc": "check for unused functions and methods\n\nThe unusedfunc analyzer reports functions and methods that are\nnever referenced outside of their own declaration.\n\nA function is considered unused if it is unexported and not\nreferenced (except within its own declaration).\n\nA method is considered unused if it is unexported, not referenced\n(except within its own declaration), and its name does not match\nthat of any method of an interface type declared within the same\npackage.\n\nThe tool may report false positives in some situations, for\nexample:\n\n - For a declaration of an unexported function that is referenced\n from another package using the go:linkname mechanism, if the\n declaration's doc comment does not also have a go:linkname\n comment.\n\n (Such code is in any case strongly discouraged: linkname\n annotations, if they must be used at all, should be used on both\n the declaration and the alias.)\n\n - For compiler intrinsics in the \"runtime\" package that, though\n never referenced, are known to the compiler and are called\n indirectly by compiled object code.\n\n - For functions called only from assembly.\n\n - For functions called only from files whose build tags are not\n selected in the current build configuration.\n\nSee https://github.com/golang/go/issues/71686 for discussion of\nthese limitations.\n\nThe unusedfunc algorithm is not as precise as the\ngolang.org/x/tools/cmd/deadcode tool, but it has the advantage that\nit runs within the modular analysis framework, enabling near\nreal-time feedback within gopls.",
13371337
"URL": "https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedfunc",
13381338
"Default": true
13391339
},

0 commit comments

Comments
 (0)