Skip to content

Commit

Permalink
cmd: add a new analyzer for check missing values after append
Browse files Browse the repository at this point in the history
If there is no second parameter added during append, there will be no prompt when executing go vet. Add an analyzer to detect this situation

Update #60448

Change-Id: If9848835424f310c54e3e9377aaaad4a1516871a
Reviewed-on: https://go-review.googlesource.com/c/go/+/498416
Run-TryBot: shuang cui <imcusg@gmail.com>
Run-TryBot: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
  • Loading branch information
cuishuang authored and timothy-king committed Oct 3, 2023
1 parent e9379a8 commit dc523c8
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cmd/go/internal/test/flagdefs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/cmd/vendor/modules.txt
Expand Up @@ -52,6 +52,7 @@ golang.org/x/tools/cmd/bisect
golang.org/x/tools/cover
golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/internal/analysisflags
golang.org/x/tools/go/analysis/passes/appends
golang.org/x/tools/go/analysis/passes/asmdecl
golang.org/x/tools/go/analysis/passes/assign
golang.org/x/tools/go/analysis/passes/atomic
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/vet/main.go
Expand Up @@ -9,6 +9,7 @@ import (

"golang.org/x/tools/go/analysis/unitchecker"

"golang.org/x/tools/go/analysis/passes/appends"
"golang.org/x/tools/go/analysis/passes/asmdecl"
"golang.org/x/tools/go/analysis/passes/assign"
"golang.org/x/tools/go/analysis/passes/atomic"
Expand Down Expand Up @@ -46,6 +47,7 @@ func main() {
objabi.AddVersionFlag()

unitchecker.Main(
appends.Analyzer,
asmdecl.Analyzer,
assign.Analyzer,
atomic.Analyzer,
Expand Down
12 changes: 12 additions & 0 deletions src/cmd/vet/testdata/appends/appends.go
@@ -0,0 +1,12 @@
// Copyright 2023 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.

// This file contains tests for the appends checker.

package appends

func AppendsTest() {
sli := []string{"a", "b", "c"}
sli = append(sli) // ERROR "append with no values"
}
1 change: 1 addition & 0 deletions src/cmd/vet/vet_test.go
Expand Up @@ -62,6 +62,7 @@ func vetCmd(t *testing.T, arg, pkg string) *exec.Cmd {
func TestVet(t *testing.T) {
t.Parallel()
for _, pkg := range []string{
"appends",
"asm",
"assign",
"atomic",
Expand Down

0 comments on commit dc523c8

Please sign in to comment.