Skip to content

Commit 4d19884

Browse files
committed
chore: refactor to uncalled
Refactor to use uncalled which is a generic version rowserr that uses a configuration to enable rules based checks instead of hard-coded for database/sql Rows.Err() checks only.
1 parent 450301f commit 4d19884

File tree

7 files changed

+42
-28
lines changed

7 files changed

+42
-28
lines changed

.golangci.reference.yml

+24-10
Original file line numberDiff line numberDiff line change
@@ -1636,14 +1636,6 @@ linters-settings:
16361636
severity: warning
16371637
disabled: false
16381638

1639-
rowserr:
1640-
# packages sets additional packages to check.
1641-
# The following know sql packages are always checked:
1642-
# - database/sql
1643-
# - github.com/jmoiron/sqlx
1644-
# Default: []
1645-
packages: []
1646-
16471639
rowserrcheck:
16481640
# database/sql is always checked
16491641
# Default: []
@@ -1754,6 +1746,28 @@ linters-settings:
17541746
# Default: true
17551747
begin: false
17561748

1749+
uncalled:
1750+
rules:
1751+
# Check for uncalled Rows.Err
1752+
- name: sql.Rows
1753+
disabled: false
1754+
severity: warning
1755+
packages:
1756+
- database/sql
1757+
- github.com/jmoiron/sqlx
1758+
call:
1759+
methods: []
1760+
results:
1761+
- type: .Rows
1762+
pointer: true
1763+
- type: error
1764+
pointer: false
1765+
expect:
1766+
method: .Err
1767+
resultIndex: 0
1768+
args: []
1769+
1770+
17571771
usestdlibvars:
17581772
# Suggest the use of http.MethodXX.
17591773
# Default: true
@@ -2047,7 +2061,6 @@ linters:
20472061
- promlinter
20482062
- reassign
20492063
- revive
2050-
- rowserr
20512064
- rowserrcheck
20522065
- scopelint
20532066
- sqlclosecheck
@@ -2061,6 +2074,7 @@ linters:
20612074
- thelper
20622075
- tparallel
20632076
- typecheck
2077+
- uncalled
20642078
- unconvert
20652079
- unparam
20662080
- unused
@@ -2155,7 +2169,6 @@ linters:
21552169
- promlinter
21562170
- reassign
21572171
- revive
2158-
- rowserr
21592172
- rowserrcheck
21602173
- scopelint
21612174
- sqlclosecheck
@@ -2169,6 +2182,7 @@ linters:
21692182
- thelper
21702183
- tparallel
21712184
- typecheck
2185+
- uncalled
21722186
- unconvert
21732187
- unparam
21742188
- unused

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/spf13/viper v1.12.0
9494
github.com/ssgreg/nlreturn/v2 v2.2.1
9595
github.com/stbenjam/no-sprintf-host-port v0.1.1
96-
github.com/stevenh/go-rowserr v0.2.0
96+
github.com/stevenh/go-uncalled v0.3.0
9797
github.com/stretchr/testify v1.8.1
9898
github.com/tdakkota/asciicheck v0.1.1
9999
github.com/tetafro/godot v1.4.11

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"runtime"
55

66
"github.com/pkg/errors"
7+
"github.com/stevenh/go-uncalled/pkg/uncalled"
78
)
89

910
var defaultLintersSettings = LintersSettings{
@@ -190,7 +191,6 @@ type LintersSettings struct {
190191
Promlinter PromlinterSettings
191192
Reassign ReassignSettings
192193
Revive ReviveSettings
193-
RowsErr RowsErrSettings
194194
RowsErrCheck RowsErrCheckSettings
195195
Staticcheck StaticCheckSettings
196196
Structcheck StructCheckSettings
@@ -199,6 +199,7 @@ type LintersSettings struct {
199199
Tenv TenvSettings
200200
Testpackage TestpackageSettings
201201
Thelper ThelperSettings
202+
Uncalled UncalledSettings
202203
Unparam UnparamSettings
203204
Unused StaticCheckSettings
204205
UseStdlibVars UseStdlibVarsSettings
@@ -601,9 +602,8 @@ type ReviveSettings struct {
601602
Severity string
602603
}
603604
}
604-
type RowsErrSettings struct {
605-
Packages []string
606-
}
605+
606+
type UncalledSettings = uncalled.Config
607607

608608
type RowsErrCheckSettings struct {
609609
Packages []string

pkg/golinters/rowserr.go renamed to pkg/golinters/uncalled.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package golinters
22

33
import (
4-
"github.com/stevenh/go-rowserr/pkg/rowserr"
4+
"github.com/stevenh/go-uncalled/pkg/uncalled"
55
"golang.org/x/tools/go/analysis"
66

77
"github.com/golangci/golangci-lint/pkg/config"
88
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
99
)
1010

11-
func NewRowsErr(settings *config.RowsErrSettings) *goanalysis.Linter {
12-
a := rowserr.NewAnalyzer(settings.Packages...)
11+
func NewUncalled(settings *config.UncalledSettings) *goanalysis.Linter {
12+
a := uncalled.NewAnalyzer(settings)
1313
return goanalysis.NewLinter(
1414
a.Name,
1515
a.Doc,

pkg/lint/lintersdb/manager.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
158158
promlinterCfg *config.PromlinterSettings
159159
reassignCfg *config.ReassignSettings
160160
reviveCfg *config.ReviveSettings
161-
rowserrCfg *config.RowsErrSettings
162161
rowserrcheckCfg *config.RowsErrCheckSettings
163162
staticcheckCfg *config.StaticCheckSettings
164163
structcheckCfg *config.StructCheckSettings
@@ -167,6 +166,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
167166
tenvCfg *config.TenvSettings
168167
testpackageCfg *config.TestpackageSettings
169168
thelperCfg *config.ThelperSettings
169+
uncalledCfg *config.UncalledSettings
170170
unparamCfg *config.UnparamSettings
171171
unusedCfg *config.StaticCheckSettings
172172
usestdlibvars *config.UseStdlibVarsSettings
@@ -235,7 +235,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
235235
promlinterCfg = &m.cfg.LintersSettings.Promlinter
236236
reassignCfg = &m.cfg.LintersSettings.Reassign
237237
reviveCfg = &m.cfg.LintersSettings.Revive
238-
rowserrCfg = &m.cfg.LintersSettings.RowsErr
239238
rowserrcheckCfg = &m.cfg.LintersSettings.RowsErrCheck
240239
staticcheckCfg = &m.cfg.LintersSettings.Staticcheck
241240
structcheckCfg = &m.cfg.LintersSettings.Structcheck
@@ -244,6 +243,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
244243
tenvCfg = &m.cfg.LintersSettings.Tenv
245244
testpackageCfg = &m.cfg.LintersSettings.Testpackage
246245
thelperCfg = &m.cfg.LintersSettings.Thelper
246+
uncalledCfg = &m.cfg.LintersSettings.Uncalled
247247
unparamCfg = &m.cfg.LintersSettings.Unparam
248248
unusedCfg = &m.cfg.LintersSettings.Unused
249249
varcheckCfg = &m.cfg.LintersSettings.Varcheck
@@ -709,12 +709,6 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
709709
ConsiderSlow().
710710
WithURL("https://github.com/mgechev/revive"),
711711

712-
linter.NewConfig(golinters.NewRowsErr(rowserrCfg)).
713-
WithSince("v1.51.0").
714-
WithLoadForGoAnalysis().
715-
WithPresets(linter.PresetBugs, linter.PresetSQL).
716-
WithURL("https://github.com/stevenh/go-rowserr"),
717-
718712
linter.NewConfig(golinters.NewRowsErrCheck(rowserrcheckCfg)).
719713
WithSince("v1.23.0").
720714
WithLoadForGoAnalysis().
@@ -795,6 +789,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
795789
WithPresets(linter.PresetBugs).
796790
WithURL(""),
797791

792+
linter.NewConfig(golinters.NewUncalled(uncalledCfg)).
793+
WithSince("v1.51.0").
794+
WithLoadForGoAnalysis().
795+
WithPresets(linter.PresetBugs, linter.PresetSQL).
796+
WithURL("https://github.com/stevenh/go-uncalled"),
797+
798798
linter.NewConfig(golinters.NewUnconvert()).
799799
WithSince("v1.0.0").
800800
WithLoadForGoAnalysis().
File renamed without changes.

0 commit comments

Comments
 (0)