Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.5.2 #42

Merged
merged 5 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down
32 changes: 28 additions & 4 deletions passes/unclosetx/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"context"

"cloud.google.com/go/spanner"
"golang.org/x/sync/errgroup"
)

func f1(ctx context.Context, client *spanner.Client) {
client.ReadOnlyTransaction() // want "transaction must be closed"
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) {
Expand All @@ -32,7 +33,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
}{
Expand All @@ -49,3 +50,26 @@ 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
}

// 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
}
29 changes: 12 additions & 17 deletions passes/unclosetx/unclosetx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package unclosetx

import (
"go/ast"
"go/token"
"go/types"
"strings"

Expand Down Expand Up @@ -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")
}
}
}
Expand Down
27 changes: 11 additions & 16 deletions passes/unstopiter/unstopiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package unstopiter

import (
"go/ast"
"go/token"
"go/types"
"strings"

Expand Down Expand Up @@ -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")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down