+
Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/testandvet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ jobs:
- name: Test and vet
run: |
go vet ./...
go vet -vettool=$(pwd)/tennvet ./...
go vet -vettool=$(pwd)/tennvet -notest=false ./...
go test -v -race ./...
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,31 @@

* `unstopiter`: it finds iterators which did not stop.
* `unclosetx`: it finds transactions which does not close
* `wraperr`: it finds [(*spanner.Client).ReadWriteTransaction](https://godoc.org/cloud.google.com/go/spanner#Client.ReadWriteTransaction) calls which returns wrapped errors
* `wraperr`: it finds [(*spanner.Client).ReadWriteTransaction](https://pkg.go.dev/cloud.google.com/go/spanner#Client.ReadWriteTransaction) calls which returns wrapped errors

## Install

You can get `zagane` by `go get` command.
You can get `zagane` by `go install` command.

```bash
$ go get -u github.com/gcpug/zagane
$ go install github.com/gcpug/zagane@latest
```

## How to use

`zagane` run with `go vet` as below when Go is 1.12 and higher.
`zagane` run with `go vet` as below.

```bash
$ go vet -vettool=$(which zagane) github.com/gcpug/spshovel/...
# github.com/gcpug/spshovel/spanner
spanner/spanner_service.go:29:29: iterator must be stop
```

When Go is lower than 1.12, just run `zagane` command with the package name (import path).
But it cannot accept some options such as `--tags`.

```bash
$ zagane github.com/gcpug/spshovel/...
~/go/src/github.com/gcpug/spshovel/spanner/spanner_service.go:29:29: iterator must be stop
```

## Analyzers

### unstopiter

`unstopiter` finds spanner.RowIterator which is not calling [Stop](https://godoc.org/cloud.google.com/go/spanner#RowIterator.Stop) method or [Do](https://godoc.org/cloud.google.com/go/spanner#RowIterator.Do) method such as below code.
`unstopiter` finds spanner.RowIterator which is not calling [Stop](https://pkg.go.dev/cloud.google.com/go/spanner#RowIterator.Stop) method or [Do](https://pkg.go.dev/cloud.google.com/go/spanner#RowIterator.Do) method such as below code.

```go
iter := client.Single().Query(ctx, stmt)
Expand All @@ -62,7 +54,7 @@ for {

### unclosetx

`unclosetx` finds spanner.ReadOnlyTransaction which is not calling [Close](https://godoc.org/cloud.google.com/go/spanner#ReadOnlyTransaction.Close) method such as below code.
`unclosetx` finds spanner.ReadOnlyTransaction which is not calling [Close](https://pkg.go.dev/cloud.google.com/go/spanner#ReadOnlyTransaction.Close) method such as below code.

```go
tx := client.ReadOnlyTransaction()
Expand All @@ -77,7 +69,7 @@ defer tx.Close()
// ...
```

When a transaction is created by [`(*spanner.Client).Single`](https://godoc.org/cloud.google.com/go/spanner#ReadOnlyTransaction), `unclosetx` ignore it.
When a transaction is created by [`(*spanner.Client).Single`](https://pkg.go.dev/cloud.google.com/go/spanner#ReadOnlyTransaction), `unclosetx` ignore it.

### wraperr

Expand Down Expand Up @@ -127,7 +119,7 @@ _, _ = client.Single().Query(ctx, stmt).Next()

## Analyze with golang.org/x/tools/go/analysis

You can get analyzers of zagane from [zagane.Analyzers](https://godoc.org/github.com/gcpug/zagane/zagane/#Analyzers).
You can get analyzers of zagane from [zagane.Analyzers](https://pkg.go.dev/github.com/gcpug/zagane/zagane/#Analyzers).
And you can use them with [unitchecker](https://golang.org/x/tools/go/analysis/unitchecker).

## Why name is "zagane"?
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ go 1.23.10
require (
github.com/gostaticanalysis/analysisutil v0.6.2
github.com/gostaticanalysis/comment v1.4.2
github.com/gostaticanalysis/testutil v0.3.1
github.com/gostaticanalysis/testutil v0.6.1
golang.org/x/tools v0.34.0
)

require (
github.com/hashicorp/go-version v1.2.1 // indirect
github.com/otiai10/copy v1.2.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/otiai10/copy v1.14.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/tenntenn/modver v1.0.1 // indirect
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 // indirect
github.com/tenntenn/text/transform v0.0.0-20250402111347-ba836492e880 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/sync v0.15.0 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.26.0 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ github.com/gostaticanalysis/comment v1.4.2/go.mod h1:KLUTGDv6HOCotCH8h2erHKmpci2
github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M=
github.com/gostaticanalysis/testutil v0.3.1 h1:n/8lK4dC+fMcTs7YTBKJfWxEPQctfuF7DPQfusk/fO4=
github.com/gostaticanalysis/testutil v0.3.1/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M=
github.com/gostaticanalysis/testutil v0.6.1 h1:DeKCG96QlhtNAz+/z2jjO3gIHFV+lHEwELddAsLohxg=
github.com/gostaticanalysis/testutil v0.6.1/go.mod h1:XfUs9IH5sPfXbPIq+kHR64fCpB6pBf5mYeaZQdaTBpw=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
github.com/otiai10/copy v1.14.1/go.mod h1:oQwrEDDOci3IM8dJF0d8+jnbfPDllW6vUjNc3DoZm9I=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.1 h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc=
github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
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/tenntenn/text/transform v0.0.0-20250402111347-ba836492e880 h1:hAkmx/iqQVHL6cWVkmEe7rsqdepWsU7m3yDh/P7faig=
github.com/tenntenn/text/transform v0.0.0-20250402111347-ba836492e880/go.mod h1:gHKdSzW72+xrCRfwqH2NCHKK2Mrh9Zf+sU5fzzGeTUw=
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=
Expand All @@ -40,10 +50,14 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU=
Expand Down
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// +build !go1.12

package main

import (
"github.com/gcpug/zagane/passes/unstopiter"
"golang.org/x/tools/go/analysis/singlechecker"
"golang.org/x/tools/go/analysis/unitchecker"

"github.com/gcpug/zagane/zagane"
)

func main() {
if printVersion() {
return
}
singlechecker.Main(unstopiter.Analyzer)
unitchecker.Main(zagane.Analyzers()...)
}
15 changes: 0 additions & 15 deletions main_go112.go

This file was deleted.

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载