Skip to content

Commit

Permalink
contextcheck: re-enable for go1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvia7788 committed Aug 16, 2022
1 parent 5e14049 commit aa09fc6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ require (
github.com/ssgreg/nlreturn/v2 v2.2.1
github.com/stbenjam/no-sprintf-host-port v0.1.1
github.com/stretchr/testify v1.8.0
github.com/sylvia7788/contextcheck v1.0.4
github.com/sylvia7788/contextcheck v1.0.6
github.com/tdakkota/asciicheck v0.1.1
github.com/tetafro/godot v1.4.11
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ type LintersSettings struct {
Whitespace WhitespaceSettings
Wrapcheck WrapcheckSettings
WSL WSLSettings
ContextCheck ContextCheckSettings

Custom map[string]CustomLinterSettings
}
Expand Down Expand Up @@ -656,6 +657,10 @@ type WSLSettings struct {
ForceCaseTrailingWhitespaceLimit int `mapstructure:"force-case-trailing-whitespace"`
}

type ContextCheckSettings struct {
DisableFact bool `mapstructure:"disable-fact"`
}

// CustomLinterSettings encapsulates the meta-data of a private linter.
// For example, a private linter may be added to the golangci config file as shown below.
//
Expand Down
16 changes: 13 additions & 3 deletions pkg/golinters/contextcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ import (
"github.com/sylvia7788/contextcheck"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
)

func NewContextCheck() *goanalysis.Linter {
func NewContextCheck(settings *config.ContextCheckSettings) *goanalysis.Linter {
conf := contextcheck.Configuration{}
if settings != nil {
conf.DisableFact = settings.DisableFact
}
analyzer := contextcheck.NewAnalyzer(conf)
return goanalysis.NewLinter(
"contextcheck",
"check the function whether use a non-inherited context",
[]*analysis.Analyzer{contextcheck.NewAnalyzer()},
[]*analysis.Analyzer{analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
).WithLoadMode(goanalysis.LoadModeTypesInfo).
WithContextSetter(func(lintCtx *linter.Context) {
analyzer.Run = contextcheck.NewRun(lintCtx.Packages, conf.DisableFact)
})
}
7 changes: 4 additions & 3 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
whitespaceCfg *config.WhitespaceSettings
wrapcheckCfg *config.WrapcheckSettings
wslCfg *config.WSLSettings
contextcheckCfg *config.ContextCheckSettings
)

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

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

linter.NewConfig(golinters.NewContextCheck()).
linter.NewConfig(golinters.NewContextCheck(contextcheckCfg)).
WithSince("v1.43.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/sylvia7788/contextcheck").
WithNoopFallback(m.cfg),
WithURL("https://github.com/sylvia7788/contextcheck"),

linter.NewConfig(golinters.NewCyclop(cyclopCfg)).
WithSince("v1.37.0").
Expand Down

0 comments on commit aa09fc6

Please sign in to comment.