Skip to content

Commit d82420d

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 5d32857 commit d82420d

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
@@ -1632,14 +1632,6 @@ linters-settings:
16321632
severity: warning
16331633
disabled: false
16341634

1635-
rowserr:
1636-
# packages sets additional packages to check.
1637-
# The following know sql packages are always checked:
1638-
# - database/sql
1639-
# - github.com/jmoiron/sqlx
1640-
# Default: []
1641-
packages: []
1642-
16431635
rowserrcheck:
16441636
# database/sql is always checked
16451637
# Default: []
@@ -1750,6 +1742,28 @@ linters-settings:
17501742
# Default: true
17511743
begin: false
17521744

1745+
uncalled:
1746+
rules:
1747+
# Check for uncalled Rows.Err
1748+
- name: sql.Rows
1749+
disabled: false
1750+
severity: warning
1751+
packages:
1752+
- database/sql
1753+
- github.com/jmoiron/sqlx
1754+
call:
1755+
methods: []
1756+
results:
1757+
- type: .Rows
1758+
pointer: true
1759+
- type: error
1760+
pointer: false
1761+
expect:
1762+
method: .Err
1763+
resultIndex: 0
1764+
args: []
1765+
1766+
17531767
usestdlibvars:
17541768
# Suggest the use of http.MethodXX.
17551769
# Default: true
@@ -2043,7 +2057,6 @@ linters:
20432057
- promlinter
20442058
- reassign
20452059
- revive
2046-
- rowserr
20472060
- rowserrcheck
20482061
- scopelint
20492062
- sqlclosecheck
@@ -2057,6 +2070,7 @@ linters:
20572070
- thelper
20582071
- tparallel
20592072
- typecheck
2073+
- uncalled
20602074
- unconvert
20612075
- unparam
20622076
- unused
@@ -2151,7 +2165,6 @@ linters:
21512165
- promlinter
21522166
- reassign
21532167
- revive
2154-
- rowserr
21552168
- rowserrcheck
21562169
- scopelint
21572170
- sqlclosecheck
@@ -2165,6 +2178,7 @@ linters:
21652178
- thelper
21662179
- tparallel
21672180
- typecheck
2181+
- uncalled
21682182
- unconvert
21692183
- unparam
21702184
- 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
@@ -600,9 +601,8 @@ type ReviveSettings struct {
600601
Severity string
601602
}
602603
}
603-
type RowsErrSettings struct {
604-
Packages []string
605-
}
604+
605+
type UncalledSettings = uncalled.Config
606606

607607
type RowsErrCheckSettings struct {
608608
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)