Skip to content

Commit aa09fc6

Browse files
committed
contextcheck: re-enable for go1.18
1 parent 5e14049 commit aa09fc6

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ require (
8989
github.com/ssgreg/nlreturn/v2 v2.2.1
9090
github.com/stbenjam/no-sprintf-host-port v0.1.1
9191
github.com/stretchr/testify v1.8.0
92-
github.com/sylvia7788/contextcheck v1.0.4
92+
github.com/sylvia7788/contextcheck v1.0.6
9393
github.com/tdakkota/asciicheck v0.1.1
9494
github.com/tetafro/godot v1.4.11
9595
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144

go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ type LintersSettings struct {
184184
Whitespace WhitespaceSettings
185185
Wrapcheck WrapcheckSettings
186186
WSL WSLSettings
187+
ContextCheck ContextCheckSettings
187188

188189
Custom map[string]CustomLinterSettings
189190
}
@@ -656,6 +657,10 @@ type WSLSettings struct {
656657
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
657658
}
658659

660+
type ContextCheckSettings struct {
661+
DisableFact bool `mapstructure:"disable-fact"`
662+
}
663+
659664
// CustomLinterSettings encapsulates the meta-data of a private linter.
660665
// For example, a private linter may be added to the golangci config file as shown below.
661666
//

pkg/golinters/contextcheck.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ import (
44
"github.com/sylvia7788/contextcheck"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
9+
"github.com/golangci/golangci-lint/pkg/lint/linter"
810
)
911

10-
func NewContextCheck() *goanalysis.Linter {
12+
func NewContextCheck(settings *config.ContextCheckSettings) *goanalysis.Linter {
13+
conf := contextcheck.Configuration{}
14+
if settings != nil {
15+
conf.DisableFact = settings.DisableFact
16+
}
17+
analyzer := contextcheck.NewAnalyzer(conf)
1118
return goanalysis.NewLinter(
1219
"contextcheck",
1320
"check the function whether use a non-inherited context",
14-
[]*analysis.Analyzer{contextcheck.NewAnalyzer()},
21+
[]*analysis.Analyzer{analyzer},
1522
nil,
16-
).WithLoadMode(goanalysis.LoadModeTypesInfo)
23+
).WithLoadMode(goanalysis.LoadModeTypesInfo).
24+
WithContextSetter(func(lintCtx *linter.Context) {
25+
analyzer.Run = contextcheck.NewRun(lintCtx.Packages, conf.DisableFact)
26+
})
1727
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
170170
whitespaceCfg *config.WhitespaceSettings
171171
wrapcheckCfg *config.WrapcheckSettings
172172
wslCfg *config.WSLSettings
173+
contextcheckCfg *config.ContextCheckSettings
173174
)
174175

175176
if m.cfg != nil {
@@ -241,6 +242,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
241242
whitespaceCfg = &m.cfg.LintersSettings.Whitespace
242243
wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck
243244
wslCfg = &m.cfg.LintersSettings.WSL
245+
contextcheckCfg = &m.cfg.LintersSettings.ContextCheck
244246

245247
if govetCfg != nil {
246248
govetCfg.Go = m.cfg.Run.Go
@@ -296,12 +298,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
296298
WithPresets(linter.PresetStyle).
297299
WithURL("https://github.com/sivchari/containedctx"),
298300

299-
linter.NewConfig(golinters.NewContextCheck()).
301+
linter.NewConfig(golinters.NewContextCheck(contextcheckCfg)).
300302
WithSince("v1.43.0").
301303
WithPresets(linter.PresetBugs).
302304
WithLoadForGoAnalysis().
303-
WithURL("https://github.com/sylvia7788/contextcheck").
304-
WithNoopFallback(m.cfg),
305+
WithURL("https://github.com/sylvia7788/contextcheck"),
305306

306307
linter.NewConfig(golinters.NewCyclop(cyclopCfg)).
307308
WithSince("v1.37.0").

0 commit comments

Comments
 (0)