Skip to content

Commit 348eb59

Browse files
authored
feat: make rules configurable (#4)
Complete the refactor from database/sql specific rowserr to configurable uncalled.
1 parent cb701b7 commit 348eb59

28 files changed

+574
-333
lines changed

.goreleaser.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ builds:
1313
goarch:
1414
- amd64
1515
- arm64
16-
main: ./cmd/rowserr
17-
id: rowserr
18-
binary: rowserr
16+
main: ./cmd/uncalled
17+
id: uncalled
18+
binary: uncalled
1919
universal_binaries:
2020
- replace: true
21-
id: rowserr
21+
id: uncalled
2222
checksum:
2323
name_template: 'checksums.txt'
2424
snapshot:
2525
name_template: '{{ incpatch .Version }}-next'
2626
archives:
27-
- id: rowserr
27+
- id: uncalled
2828
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
2929
release:
3030
header: |
3131
<a name='{{.Tag}}'></a>
3232
### {{.Tag}} Release Notes ({{.Date}})
3333
footer: |
34-
[Full Changelog](https://github.com/stevenh/go-rowserr/cmd/rowserr/compare/{{ .PreviousTag }}...{{ .Tag }})
34+
[Full Changelog](https://github.com/stevenh/go-uncalled/cmd/uncalled/compare/{{ .PreviousTag }}...{{ .Tag }})
3535
changelog:
3636
use: github
3737
sort: asc
@@ -51,22 +51,22 @@ changelog:
5151
# Default is no groups.
5252
groups:
5353
- title: Features
54-
regexp: '^.*(feat|feature)(\([[:word:]]+\))??!?:.+$'
54+
regexp: '^.*?(feat|feature)(\([[:word:]]+\))??!?:.+$'
5555
order: 0
5656
- title: 'Bug fixes'
57-
regexp: '^.*fix(\([[:word:]]+\))??!?:.+$'
57+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
5858
order: 1
5959
- title: 'Chores'
60-
regexp: '^.*chore(\([[:word:]]+\))??!?:.+$'
60+
regexp: '^.*?chore(\([[:word:]]+\))??!?:.+$'
6161
order: 2
6262
- title: 'Quality'
63-
regexp: '^.*(qa|test|tests)(\([[:word:]]+\))??!?:.+$'
63+
regexp: '^.*?(qa|test|tests)(\([[:word:]]+\))??!?:.+$'
6464
order: 3
6565
- title: 'Documentation'
66-
regexp: '^.*(doc|docs)(\([[:word:]]+\))??!?:.+$'
66+
regexp: '^.*?(doc|docs)(\([[:word:]]+\))??!?:.+$'
6767
order: 4
6868
- title: 'Continuous Integration'
69-
regexp: '^.*ci(\([[:word:]]+\))??!?:.+$'
69+
regexp: '^.*?ci(\([[:word:]]+\))??!?:.+$'
7070
order: 5
7171
- title: Other
7272
order: 999

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
# go-rowserr
1+
# go-uncalled
22

3-
[![Reference](https://pkg.go.dev/badge/github.com/stevenh/go-rowserr.svg)](https://pkg.go.dev/github.com/stevenh/go-rowserr) [![License](https://img.shields.io/badge/License-BSD_2--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause) [![Go Report Card](https://goreportcard.com/badge/github.com/stevenh/go-rowserr)](https://goreportcard.com/report/github.com/stevenh/go-rowserr)
3+
[![Reference](https://pkg.go.dev/badge/github.com/stevenh/go-uncalled.svg)](https://pkg.go.dev/github.com/stevenh/go-uncalled) [![License](https://img.shields.io/badge/License-BSD_2--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause) [![Go Report Card](https://goreportcard.com/badge/github.com/stevenh/go-uncalled)](https://goreportcard.com/report/github.com/stevenh/go-uncalled)
44

5-
go-rowserr is a static analysis tool for golang which checks for missing [Rows.Err()](https://pkg.go.dev/database/sql#Rows.Err) calls.
5+
go-uncalled is a static analysis tool for golang which checks for missing calls.
66

77
It is compatible with both standard and generic functions as introduced by [golang](https://go.dev/) version [1.18](https://go.dev/doc/go1.18).
88

99
## Install
1010

11-
You can install `rowserr` cmd using `go install` command.
11+
You can install the `uncalled` cmd using `go install` command.
1212

1313
```bash
14-
go install github.com/stevenh/go-rowserr/cmd/rowserr@latest
14+
go install github.com/stevenh/go-uncalled/cmd/uncalled@latest
1515
```
1616

1717
## How to use
1818

19-
You run `rowserr` with [go vet](https://pkg.go.dev/cmd/vet).
19+
You run `uncalled` with [go vet](https://pkg.go.dev/cmd/vet).
2020

2121
```bash
22-
go vet -vettool=$(which rowserr) ./...
23-
# github.com/stevenh/go-rowserr/test
24-
test/bad.go:10:2: rows.Err() must be checked
22+
go vet -vettool=$(which uncalled) ./...
23+
# github.com/stevenh/go-uncalled/test
24+
test/bad.go:10:2: rows.Err() must be called
2525
```
2626

27-
You can also run it directly:
27+
Or run it directly.
2828
```bash
29-
rowserr ./...
30-
# github.com/stevenh/go-rowserr/test
31-
test/bad.go:10:2: rows.Err() must be checked
29+
uncalled ./...
30+
# github.com/stevenh/go-uncalled/test
31+
test/bad.go:10:2: rows.Err() must be called
3232
```
3333

34-
Additional package to check can be added using `-packages <pk1,pkg2...pkgN>`.
34+
A custom configuration can be loaded using `-config <filename>`.
3535

3636
The version can be checked with `-version`.
3737

38-
By default this checks the following packages:
39-
40-
- [database/sql](https://pkg.go.dev/database/sql)
41-
- [github.com/jmoiron/sqlx](https://pkg.go.dev/github.com/jmoiron/sqlx)
38+
By default it includes the rules in:
39+
[pkg/uncalled/.uncalled.yaml](pkg/uncalled/.uncalled.yaml)
4240

4341
## Analyzer
4442

45-
`rowserr` validates that code which uses [database/sql](https://pkg.go.dev/database/sql) and similar packages, to obtain [Rows](https://pkg.go.dev/database/sql#Rows) calls [Rows.Err()](https://pkg.go.dev/database/sql#Rows.Err) as described by
43+
`uncalled` validates that code to ensure expected calls are made.
44+
45+
Its default config checks calls to [database/sql](https://pkg.go.dev/database/sql) and similar packages, that obtain [Rows](https://pkg.go.dev/database/sql#Rows) calls [Rows.Err()](https://pkg.go.dev/database/sql#Rows.Err) as described by
4646

4747
- [sql.Rows.Next](https://pkg.go.dev/database/sql#Rows.Next)
4848
- [sql.Rows.NextResultSet](https://pkg.go.dev/database/sql#Rows.NextResultSet)
@@ -76,7 +76,7 @@ if err = rows.Err(); err != nil {
7676
}
7777
```
7878

79-
`rowserr` helps uncover such errors which will result in incomplete data if an error is triggered while processing rows.
79+
`uncalled` helps uncover such errors which will result in incomplete data if an error is triggered while processing rows.
8080
This can happen when a connection becomes invalid, this causes [Rows.Next()](https://pkg.go.dev/database/sql#Rows.Next) or [sql.Rows.NextResultSet](https://pkg.go.dev/database/sql#Rows.NextResultSet) to return false without processing all rows.
8181

8282
## Inspired by

cmd/rowserr/main.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

cmd/uncalled/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build !plugin
2+
3+
// Command uncalled checks for missing calls.
4+
package main
5+
6+
import (
7+
"github.com/stevenh/go-uncalled/pkg/uncalled"
8+
"golang.org/x/tools/go/analysis/singlechecker"
9+
)
10+
11+
func main() {
12+
singlechecker.Main(uncalled.NewAnalyzer())
13+
}

cmd/rowserr/plugin.go renamed to cmd/uncalled/plugin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//go:build plugin
22

3-
// Command rowserr is a plugin which checks for missing database/sql.Rows.Err() calls.
3+
// Command uncalled is a plugin which checks for missing calls.
44
package main
55

66
import (
7-
"github.com/stevenh/go-rowserr/pkg/rowserr"
7+
"github.com/stevenh/go-uncalled/pkg/uncalled"
88
"golang.org/x/tools/go/analysis"
99
)
1010

1111
type analyzerPlugin struct{}
1212

13-
// GetAnalyzers returns rowserr Analyzer.
13+
// GetAnalyzers returns uncalled Analyzer.
1414
func (analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {
1515
return []*analysis.Analyzer{
16-
rowserr.Analyzer,
16+
uncalled.NewAnalyzer(),
1717
}
1818
}
1919

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
module github.com/stevenh/go-rowserr
1+
module github.com/stevenh/go-uncalled
22

33
go 1.19
44

5-
require golang.org/x/tools v0.2.0
5+
require (
6+
golang.org/x/tools v0.2.0
7+
gopkg.in/yaml.v3 v3.0.1
8+
)
69

710
require (
811
golang.org/x/mod v0.6.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
44
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
55
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
66
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)