Skip to content

Commit

Permalink
simple: fix suggested fixes for S1004
Browse files Browse the repository at this point in the history
Also update x/tools to latest version, as `analysistest.RunWithSuggestedFixes` is
very recent.

Signed-off-by: Sourya Vatsyayan <[email protected]>
(cherry picked from commit a4eb707)
  • Loading branch information
sourya-deepsource authored and dominikh committed Oct 10, 2020
1 parent a95c3b5 commit caa47cc
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 10 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require (
github.com/google/renameio v0.1.0
github.com/kisielk/gotool v1.0.0
github.com/rogpeppe/go-internal v1.3.0
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d
golang.org/x/mod v0.2.0
golang.org/x/tools v0.0.0-20200410194907-79a7a3126eef
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,35 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529 h1:iMGN4xG0cnqj3t+zOM8wUB0BiPKHEwSxEZCvzcbZuvk=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e h1:JgcxKXxCjrA2tyDP/aNU9K0Ck5Czfk6C7e2tMw7+bSI=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200410194907-79a7a3126eef h1:RHORRhs540cYZYrzgU2CPUyykkwZM78hGdzocOo9P8A=
golang.org/x/tools v0.0.0-20200410194907-79a7a3126eef/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
4 changes: 2 additions & 2 deletions ir/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestObjValueLookup(t *testing.T) {
// Each note of the form @ir(x, "BinOp") in testdata/objlookup.go
// specifies an expectation that an object named x declared on the
// same line is associated with an an ir.Value of type *ir.BinOp.
notes, err := expect.Extract(conf.Fset, f)
notes, err := expect.ExtractGo(conf.Fset, f)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func testValueForExpr(t *testing.T, testfile string) {
return true
})

notes, err := expect.Extract(prog.Fset, f)
notes, err := expect.ExtractGo(prog.Fset, f)
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 8 additions & 3 deletions lint/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
)

type Test struct {
Dir string
Version string
Dir string
Version string
SuggestedFixes bool
}

func Run(t *testing.T, analyzers map[string]*analysis.Analyzer, tests map[string][]Test) {
Expand All @@ -27,7 +28,11 @@ func Run(t *testing.T, analyzers map[string]*analysis.Analyzer, tests map[string
t.Fatal(err)
}
}
analysistest.Run(t, analysistest.TestData(), a, test.Dir)
if test.SuggestedFixes {
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), a, test.Dir)
} else {
analysistest.Run(t, analysistest.TestData(), a, test.Dir)
}
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions simple/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ func CheckStringsContains(pass *analysis.Pass) (interface{}, error) {

var (
checkBytesCompareQ = pattern.MustParse(`(BinaryExpr (CallExpr (Function "bytes.Compare") args) op@(Or "==" "!=") (BasicLit "INT" "0"))`)
checkBytesCompareRn = pattern.MustParse(`(CallExpr (SelectorExpr (Ident "bytes") (Ident "Equal")) args)`)
checkBytesCompareRe = pattern.MustParse(`(UnaryExpr "!" (CallExpr (SelectorExpr (Ident "bytes") (Ident "Equal")) args))`)
checkBytesCompareRe = pattern.MustParse(`(CallExpr (SelectorExpr (Ident "bytes") (Ident "Equal")) args)`)
checkBytesCompareRn = pattern.MustParse(`(UnaryExpr "!" (CallExpr (SelectorExpr (Ident "bytes") (Ident "Equal")) args))`)
)

func CheckBytesCompare(pass *analysis.Pass) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion simple/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestAll(t *testing.T) {
"S1001": {{Dir: "copy"}},
"S1002": {{Dir: "bool-cmp"}},
"S1003": {{Dir: "contains"}},
"S1004": {{Dir: "compare"}},
"S1004": {{Dir: "compare", SuggestedFixes: true}, {Dir: "compare_windows"}},
"S1005": {{Dir: "CheckBlankOK"}, {Dir: "receive-blank"}, {Dir: "range_go13", Version: "1.3"}, {Dir: "range_go14", Version: "1.4"}},
"S1006": {{Dir: "for-true"}, {Dir: "generated"}},
"S1007": {{Dir: "regexp-raw"}},
Expand Down
2 changes: 2 additions & 0 deletions simple/testdata/src/compare/compare.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build darwin linux

package pkg

import "bytes"
Expand Down
12 changes: 12 additions & 0 deletions simple/testdata/src/compare/compare.go.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build darwin linux

package pkg

import "bytes"

func fn() {
_ = bytes.Equal(nil, nil) // want ` bytes.Equal`
_ = !bytes.Equal(nil, nil) // want `!bytes.Equal`
_ = bytes.Compare(nil, nil) > 0
_ = bytes.Compare(nil, nil) < 0
}
3 changes: 3 additions & 0 deletions simple/testdata/src/compare/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file exists just to make sure the package is still defined
// when tests DO NOT run on darwin/linux
package pkg
12 changes: 12 additions & 0 deletions simple/testdata/src/compare_windows/compare-windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build !linux,!darwin

package pkg

import "bytes"

func fn() {
_ = bytes.Compare(nil, nil) == 0 // want ` bytes.Equal`
_ = bytes.Compare(nil, nil) != 0 // want `!bytes.Equal`
_ = bytes.Compare(nil, nil) > 0
_ = bytes.Compare(nil, nil) < 0
}
3 changes: 3 additions & 0 deletions simple/testdata/src/compare_windows/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file exists just to make sure the package is still defined
// when tests run on darwin/linux
package pkg

0 comments on commit caa47cc

Please sign in to comment.