From 42c57a673542fe0ebb884f6ace336ad89de7dc4c Mon Sep 17 00:00:00 2001 From: tenntenn Date: Fri, 11 Sep 2020 21:29:29 +0900 Subject: [PATCH 1/3] Release v0.5.2 --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index d2b8329..8497008 100644 --- a/version.go +++ b/version.go @@ -7,7 +7,7 @@ import ( ) // version of zagane -const version = "v0.5.1" +const version = "v0.5.2" func printVersion() bool { if len(os.Args) != 2 { From 838ae2e04f89bc6eaabb055c7afe6c491000918e Mon Sep 17 00:00:00 2001 From: tenntenn Date: Sat, 12 Sep 2020 00:02:36 +0900 Subject: [PATCH 2/3] Update analysisutil --- go.mod | 6 +++--- go.sum | 16 +++++++++++++++ passes/unclosetx/testdata/src/a/a.go | 13 +++++++++---- passes/unclosetx/unclosetx.go | 29 ++++++++++++---------------- passes/unstopiter/unstopiter.go | 27 +++++++++++--------------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/go.mod b/go.mod index 2329212..cc9b903 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/gcpug/zagane -go 1.12 +go 1.15 require ( - github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635 + github.com/gostaticanalysis/analysisutil v0.2.1 github.com/gostaticanalysis/comment v1.4.1 github.com/gostaticanalysis/testutil v0.3.0 - golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112 + golang.org/x/tools v0.0.0-20200911120008-d49a6cb6ca90 ) diff --git a/go.sum b/go.sum index f5a848a..36f0dda 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,13 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635 h1:I/ckdXlVHde3unRCAcN/Tcpu7LFwgvyHqnFTeklC9oA= github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE= +github.com/gostaticanalysis/analysisutil v0.1.1 h1:JBG5yLBMUWT3TD6r/5907oXI7ERiEq6kOEvVJigj5VI= +github.com/gostaticanalysis/analysisutil v0.1.1/go.mod h1:dMhHRU9KTiDcuLGdy87/2gTR8WruwYZrKdRq9m1O6uw= +github.com/gostaticanalysis/analysisutil v0.2.0 h1:bjd5aJg4jqoJDFSeNAIg8jagScR8twqdFpHcEwcdm38= +github.com/gostaticanalysis/analysisutil v0.2.0/go.mod h1:18U/DLpRgIUd459wGxVHE0fRgmo1UgHDcbw7F5idXu0= +github.com/gostaticanalysis/analysisutil v0.2.1 h1:OfNeM+FV1AOdvwfQY8Iuq2XTQrsc2isCVXw+l3SftP0= +github.com/gostaticanalysis/analysisutil v0.2.1/go.mod h1:18U/DLpRgIUd459wGxVHE0fRgmo1UgHDcbw7F5idXu0= +github.com/gostaticanalysis/comment v1.3.0/go.mod h1:xMicKDx7XRXYdVwY9f9wQpDJVnqWxw9wCauCMKp+IBI= github.com/gostaticanalysis/comment v1.4.1 h1:xHopR5L2lRz6OsjH4R2HG5wRhW9ySl3FsHIvi5pcXwc= github.com/gostaticanalysis/comment v1.4.1/go.mod h1:ih6ZxzTHLdadaiSnF5WY3dxUoXfXAlTaRzuaNDlSado= github.com/gostaticanalysis/testutil v0.2.0 h1:1rP6ZZEEgb6QOncl8R6sfx43X5+sBeEbzb0+K+aUoU0= @@ -23,20 +30,25 @@ github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/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-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 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/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 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/sync v0.0.0-20200625203802-6e8e738ad208/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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -45,12 +57,16 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190307163923-6a08e3108db3/go.mod h1:25r3+/G6/xytQM8iWZKq3Hn0kr0rgFKPUNVEL/dr3z4= golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200624225443-88f3c62a19ff/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200820010801-b793a1359eac h1:DugppSxw0LSF8lcjaODPJZoDzq0ElTGskTst3ZaBkHI= golang.org/x/tools v0.0.0-20200820010801-b793a1359eac/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112 h1:DmrRJy1qn9VDMf4+GSpRlwfZ51muIF7r96MFBFP4bPM= golang.org/x/tools v0.0.0-20200908211811-12e1bf57a112/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20200911120008-d49a6cb6ca90 h1:zlLcykpnpnE893YGqGmdnnw8jVbtzqJKuXEQN1fj4uw= +golang.org/x/tools v0.0.0-20200911120008-d49a6cb6ca90/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= 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= diff --git a/passes/unclosetx/testdata/src/a/a.go b/passes/unclosetx/testdata/src/a/a.go index 448c631..ece2870 100644 --- a/passes/unclosetx/testdata/src/a/a.go +++ b/passes/unclosetx/testdata/src/a/a.go @@ -11,9 +11,9 @@ func f1(ctx context.Context, client *spanner.Client) { client.ReadOnlyTransaction().Close() // OK tx := client.ReadOnlyTransaction() // OK tx.Close() - client.Single() // OK - client.ReadOnlyTransaction() //lint:ignore zagane OK - client.ReadOnlyTransaction() //lint:ignore unclosetx OK + client.Single() // OK + client.ReadOnlyTransaction() //lint:ignore zagane OK + client.ReadOnlyTransaction() //lint:ignore unclosetx OK } func f2(ctx context.Context, client *spanner.Client) { @@ -32,7 +32,7 @@ func f2(ctx context.Context, client *spanner.Client) { } func f3(ctx context.Context, client *spanner.Client) interface{} { - tx := client.ReadOnlyTransaction() // want "transaction must be closed" + tx := client.ReadOnlyTransaction() // OK return struct { tx *spanner.ReadOnlyTransaction }{ @@ -49,3 +49,8 @@ func f4(ctx context.Context, client *spanner.Client) interface{} { tx: tx, } } + +func f5(ctx context.Context, client *spanner.Client) { + tx, _ := client.BatchReadOnlyTransaction(ctx, spanner.StrongRead()) // want "transaction must be closed" + _ = tx +} diff --git a/passes/unclosetx/unclosetx.go b/passes/unclosetx/unclosetx.go index e8bd51e..72b7d41 100644 --- a/passes/unclosetx/unclosetx.go +++ b/passes/unclosetx/unclosetx.go @@ -2,6 +2,7 @@ package unclosetx import ( "go/ast" + "go/token" "go/types" "strings" @@ -58,23 +59,17 @@ func run(pass *analysis.Pass) (interface{}, error) { // skip this continue } - - for _, b := range f.Blocks { - for i := range b.Instrs { - pos := b.Instrs[i].Pos() - line := pass.Fset.File(pos).Line(pos) - - // skip - if cmaps.IgnoreLine(pass.Fset, line, "zagane") || - cmaps.IgnoreLine(pass.Fset, line, "unclosetx") || - isSingle(b.Instrs[i], single) { - continue - } - - called, ok := analysisutil.CalledFrom(b, i, txTyp, methods...) - if ok && !called { - pass.Reportf(pos, "transaction must be closed") - } + instrs := analysisutil.NotCalledIn(f, txTyp, methods...) + for _, instr := range instrs { + pos := instr.Pos() + if pos == token.NoPos { + continue + } + line := pass.Fset.File(pos).Line(pos) + if !cmaps.IgnoreLine(pass.Fset, line, "zagane") && + !cmaps.IgnoreLine(pass.Fset, line, "unclosetx") && + !isSingle(instr, single) { + pass.Reportf(pos, "transaction must be closed") } } } diff --git a/passes/unstopiter/unstopiter.go b/passes/unstopiter/unstopiter.go index 6fd3067..b337ab0 100644 --- a/passes/unstopiter/unstopiter.go +++ b/passes/unstopiter/unstopiter.go @@ -2,6 +2,7 @@ package unstopiter import ( "go/ast" + "go/token" "go/types" "strings" @@ -54,22 +55,16 @@ func run(pass *analysis.Pass) (interface{}, error) { // skip this continue } - - for _, b := range f.Blocks { - for i := range b.Instrs { - pos := b.Instrs[i].Pos() - line := pass.Fset.File(pos).Line(pos) - - // skip - if cmaps.IgnoreLine(pass.Fset, line, "zagane") || - cmaps.IgnoreLine(pass.Fset, line, "unstopiter") { - continue - } - - called, ok := analysisutil.CalledFrom(b, i, iterTyp, methods...) - if ok && !called { - pass.Reportf(pos, "iterator must be stopped") - } + instrs := analysisutil.NotCalledIn(f, iterTyp, methods...) + for _, instr := range instrs { + pos := instr.Pos() + if pos == token.NoPos { + continue + } + line := pass.Fset.File(pos).Line(pos) + if !cmaps.IgnoreLine(pass.Fset, line, "zagane") && + !cmaps.IgnoreLine(pass.Fset, line, "unstopiter") { + pass.Reportf(pos, "iterator must be stopped") } } } From 83eeec51e85ec84c326d4517fd9696079da5e60b Mon Sep 17 00:00:00 2001 From: tenntenn Date: Sat, 12 Sep 2020 00:10:06 +0900 Subject: [PATCH 3/3] Add tests for issue32 --- passes/unclosetx/testdata/src/a/a.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/passes/unclosetx/testdata/src/a/a.go b/passes/unclosetx/testdata/src/a/a.go index ece2870..bd4d2a8 100644 --- a/passes/unclosetx/testdata/src/a/a.go +++ b/passes/unclosetx/testdata/src/a/a.go @@ -4,6 +4,7 @@ import ( "context" "cloud.google.com/go/spanner" + "golang.org/x/sync/errgroup" ) func f1(ctx context.Context, client *spanner.Client) { @@ -54,3 +55,21 @@ func f5(ctx context.Context, client *spanner.Client) { tx, _ := client.BatchReadOnlyTransaction(ctx, spanner.StrongRead()) // want "transaction must be closed" _ = tx } + +// see https://github.com/gcpug/zagane/issues/32 +func f6(ctx context.Context, client *spanner.Client) error { + tx := client.ReadOnlyTransaction() // OK + defer tx.Close() + + var eg errgroup.Group + + eg.Go(func() error { + _ = tx // use tx + return nil + }) + + if err := eg.Wait(); err != nil { + return err + } + return nil +}