Skip to content

Commit

Permalink
Merge pull request #31 from gcpug/fix-ignore
Browse files Browse the repository at this point in the history
Fix ignore comment bug
  • Loading branch information
tenntenn authored Jan 30, 2020
2 parents a99e587 + 58cc707 commit 25ef1ca
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635
github.com/gostaticanalysis/comment v1.2.0
github.com/gostaticanalysis/comment v1.3.0
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c // indirect
golang.org/x/net v0.0.0-20190328230028-74de082e2cca // indirect
golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635 h1:I
github.com/gostaticanalysis/analysisutil v0.0.0-20190329151158-56bca42c7635/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
github.com/gostaticanalysis/comment v1.2.0 h1:z0tFc54SL945O+NO9/8xXs3Ii0uDxj2tEEru58Uwz6E=
github.com/gostaticanalysis/comment v1.2.0/go.mod h1:xMicKDx7XRXYdVwY9f9wQpDJVnqWxw9wCauCMKp+IBI=
github.com/gostaticanalysis/comment v1.3.0 h1:wTVgynbFu8/nz6SGgywA0TcyIoAVsYc7ai/Zp5xNGlw=
github.com/gostaticanalysis/comment v1.3.0/go.mod h1:xMicKDx7XRXYdVwY9f9wQpDJVnqWxw9wCauCMKp+IBI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
2 changes: 2 additions & 0 deletions passes/unclosetx/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func f1(ctx context.Context, client *spanner.Client) {
tx := client.ReadOnlyTransaction() // OK
tx.Close()
client.Single() // OK
client.ReadOnlyTransaction() //lint:ignore zagane OK
client.ReadOnlyTransaction() //lint:ignore unclosetx OK
}

func f2(ctx context.Context, client *spanner.Client) {
Expand Down
5 changes: 3 additions & 2 deletions passes/unclosetx/unclosetx.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
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.IgnorePos(pos, "zagane") ||
cmaps.IgnorePos(pos, "unclosetx") ||
if cmaps.IgnoreLine(pass.Fset, line, "zagane") ||
cmaps.IgnoreLine(pass.Fset, line, "unclosetx") ||
isSingle(b.Instrs[i], single) {
continue
}
Expand Down
2 changes: 2 additions & 0 deletions passes/unstopiter/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func f1(ctx context.Context, client *spanner.Client) {
_, _ = client.Single().Query(ctx, stmt).Next() // want "iterator must be stopped"
client.Single().Query(ctx, stmt).Stop() // OK
defer client.Single().Query(ctx, stmt).Stop() // OK
_, _ = client.Single().Query(ctx, stmt).Next() //lint:ignore zagane OK
_, _ = client.Single().Query(ctx, stmt).Next() //lint:ignore unstopiter OK
}

func f2(ctx context.Context, client *spanner.Client) {
Expand Down
5 changes: 3 additions & 2 deletions passes/unstopiter/unstopiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
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.IgnorePos(pos, "zagane") ||
cmaps.IgnorePos(pos, "unstopiter") {
if cmaps.IgnoreLine(pass.Fset, line, "zagane") ||
cmaps.IgnoreLine(pass.Fset, line, "unstopiter") {
continue
}

Expand Down
24 changes: 24 additions & 0 deletions passes/wraperr/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,27 @@ func f10(ctx context.Context, client *spanner.Client) {
return outsideErr
})
}

func f11(ctx context.Context, client *spanner.Client) {
client.ReadWriteTransaction(ctx, func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
stmt := spanner.Statement{SQL: `SELECT 1`}
_, err := client.Single().Query(ctx, stmt).Next()
if err != nil {
//lint:ignore zagane OK
return wrap(err)
}
return nil
})
}

func f12(ctx context.Context, client *spanner.Client) {
client.ReadWriteTransaction(ctx, func(ctx context.Context, txn *spanner.ReadWriteTransaction) error {
stmt := spanner.Statement{SQL: `SELECT 1`}
_, err := client.Single().Query(ctx, stmt).Next()
if err != nil {
//lint:ignore wraperr OK
return wrap(err)
}
return nil
})
}
7 changes: 4 additions & 3 deletions passes/wraperr/wraperr.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
continue
}

if pos := r.wrapped(instr); pos != token.NoPos {
if !cmaps.IgnorePos(pos, "zagane") &&
!cmaps.IgnorePos(pos, "wraperr") {
if pos := r.wrapped(instr); pos.IsValid() {
l := pass.Fset.File(pos).Line(pos)
if !cmaps.IgnoreLine(pass.Fset, l, "zagane") &&
!cmaps.IgnoreLine(pass.Fset, l, "wraperr") {
pass.Reportf(pos, "must not be wrapped")
}
}
Expand Down

0 comments on commit 25ef1ca

Please sign in to comment.