Skip to content

Commit

Permalink
build(deps): bump github.com/go-critic/go-critic from 0.6.4 to 0.6.5 (g…
Browse files Browse the repository at this point in the history
…olangci#3150)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
2 people authored and SeigeC committed Apr 4, 2023
1 parent e387e56 commit 10070c5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 59 deletions.
12 changes: 6 additions & 6 deletions go.mod
Expand Up @@ -28,7 +28,7 @@ require (
github.com/fatih/color v1.13.0
github.com/firefart/nonamedreturns v1.0.4
github.com/fzipp/gocyclo v0.6.0
github.com/go-critic/go-critic v0.6.4
github.com/go-critic/go-critic v0.6.5
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
github.com/gofrs/flock v0.8.1
github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2
Expand Down Expand Up @@ -124,8 +124,8 @@ require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-toolsmith/astcast v1.0.0 // indirect
github.com/go-toolsmith/astcopy v1.0.1 // indirect
github.com/go-toolsmith/astequal v1.0.2 // indirect
github.com/go-toolsmith/astcopy v1.0.2 // indirect
github.com/go-toolsmith/astequal v1.0.3 // indirect
github.com/go-toolsmith/astfmt v1.0.0 // indirect
github.com/go-toolsmith/astp v1.0.0 // indirect
github.com/go-toolsmith/strparse v1.0.0 // indirect
Expand Down Expand Up @@ -156,8 +156,8 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/quasilyte/go-ruleguard v0.3.17 // indirect
github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5 // indirect
github.com/quasilyte/go-ruleguard v0.3.18 // indirect
github.com/quasilyte/gogrep v0.0.0-20220828223005-86e4605de09f // indirect
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95 // indirect
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/sivchari/nosnakecase v1.7.0
Expand All @@ -174,7 +174,7 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/exp/typeparams v0.0.0-20220827204233-334a2380cb91 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
Expand Down
27 changes: 13 additions & 14 deletions go.sum

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

74 changes: 37 additions & 37 deletions pkg/golinters/gocritic.go
Expand Up @@ -25,21 +25,18 @@ import (

const goCriticName = "gocritic"

const goCriticDebugKey = "gocritic"

var (
goCriticDebugf = logutils.Debug(goCriticDebugKey)
isGoCriticDebug = logutils.HaveDebugTag(goCriticDebugKey)
goCriticDebugf = logutils.Debug(goCriticName)
isGoCriticDebug = logutils.HaveDebugTag(goCriticName)
)

func NewGoCritic(settings *config.GoCriticSettings, cfg *config.Config) *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue

wrapper := &goCriticWrapper{
settings: settings,
cfg: cfg,
sizes: types.SizesFor("gc", runtime.GOARCH),
cfg: cfg,
sizes: types.SizesFor("gc", runtime.GOARCH),
}

analyzer := &analysis.Analyzer{
Expand Down Expand Up @@ -72,41 +69,41 @@ Dynamic rules are written declaratively with AST patterns, filters, report messa
nil,
).
WithContextSetter(func(context *linter.Context) {
wrapper.init()
wrapper.init(settings, context.Log)
}).
WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
return resIssues
}).WithLoadMode(goanalysis.LoadModeTypesInfo)
}

type goCriticWrapper struct {
settings *config.GoCriticSettings
settingsWrapper *goCriticSettingsWrapper
cfg *config.Config
sizes types.Sizes
once sync.Once
}

func (w *goCriticWrapper) init() {
if w.settings != nil {
// the 'defer' is here to catch the panic from checkers.InitEmbeddedRules()
defer func() {
if err := recover(); err != nil {
linterLogger.Fatalf("%s: %v: setting an explicit GOROOT can fix this problem.", goCriticName, err)
return
}
}()
w.once.Do(checkers.InitEmbeddedRules)

settingsWrapper := newGoCriticSettingsWrapper(w.settings)
func (w *goCriticWrapper) init(settings *config.GoCriticSettings, logger logutils.Log) {
if settings == nil {
return
}

settingsWrapper.inferEnabledChecks(linterLogger)
if err := settingsWrapper.validate(linterLogger); err != nil {
linterLogger.Fatalf("%s: invalid settings: %s", goCriticName, err)
w.once.Do(func() {
err := checkers.InitEmbeddedRules()
if err != nil {
logger.Fatalf("%s: %v: setting an explicit GOROOT can fix this problem.", goCriticName, err)
}
})

settingsWrapper := newGoCriticSettingsWrapper(settings, logger)

settingsWrapper.inferEnabledChecks()

w.settingsWrapper = settingsWrapper
if err := settingsWrapper.validate(); err != nil {
logger.Fatalf("%s: invalid settings: %s", goCriticName, err)
}

w.settingsWrapper = settingsWrapper
}

func (w *goCriticWrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) {
Expand Down Expand Up @@ -268,13 +265,15 @@ func (w *goCriticWrapper) normalizeCheckerParamsValue(p interface{}) interface{}
type goCriticSettingsWrapper struct {
*config.GoCriticSettings

logger logutils.Log

allCheckers []*gocriticlinter.CheckerInfo
allCheckerMap map[string]*gocriticlinter.CheckerInfo

inferredEnabledChecks map[string]bool
}

func newGoCriticSettingsWrapper(settings *config.GoCriticSettings) *goCriticSettingsWrapper {
func newGoCriticSettingsWrapper(settings *config.GoCriticSettings, logger logutils.Log) *goCriticSettingsWrapper {
allCheckers := gocriticlinter.GetCheckersInfo()

allCheckerMap := make(map[string]*gocriticlinter.CheckerInfo)
Expand All @@ -284,6 +283,7 @@ func newGoCriticSettingsWrapper(settings *config.GoCriticSettings) *goCriticSett

return &goCriticSettingsWrapper{
GoCriticSettings: settings,
logger: logger,
allCheckers: allCheckers,
allCheckerMap: allCheckerMap,
inferredEnabledChecks: map[string]bool{},
Expand Down Expand Up @@ -343,7 +343,7 @@ func (s *goCriticSettingsWrapper) disabledCheckersDebugf() {
}
}

func (s *goCriticSettingsWrapper) inferEnabledChecks(log logutils.Log) {
func (s *goCriticSettingsWrapper) inferEnabledChecks() {
s.checkerTagsDebugf()

enabledByDefaultChecks := s.getDefaultEnabledCheckersNames()
Expand Down Expand Up @@ -371,7 +371,7 @@ func (s *goCriticSettingsWrapper) inferEnabledChecks(log logutils.Log) {

// DisabledTags
if len(s.DisabledTags) != 0 {
enabledChecks = s.filterByDisableTags(enabledChecks, s.DisabledTags, log)
enabledChecks = s.filterByDisableTags(enabledChecks, s.DisabledTags)
}

// EnabledChecks
Expand All @@ -381,7 +381,7 @@ func (s *goCriticSettingsWrapper) inferEnabledChecks(log logutils.Log) {
alreadyEnabledChecksSet := stringsSliceToSet(enabledChecks)
for _, enabledCheck := range s.EnabledChecks {
if alreadyEnabledChecksSet[enabledCheck] {
log.Warnf("No need to enable check %q: it's already enabled", enabledCheck)
s.logger.Warnf("%s: no need to enable check %q: it's already enabled", goCriticName, enabledCheck)
continue
}
enabledChecks = append(enabledChecks, enabledCheck)
Expand All @@ -395,8 +395,8 @@ func (s *goCriticSettingsWrapper) inferEnabledChecks(log logutils.Log) {
enabledChecksSet := stringsSliceToSet(enabledChecks)
for _, disabledCheck := range s.DisabledChecks {
if !enabledChecksSet[disabledCheck] {
log.Warnf("Gocritic check %q was explicitly disabled via config. However, as this check "+
"is disabled by default, there is no need to explicitly disable it via config.", disabledCheck)
s.logger.Warnf("%s: check %q was explicitly disabled via config. However, as this check "+
"is disabled by default, there is no need to explicitly disable it via config.", goCriticName, disabledCheck)
continue
}
delete(enabledChecksSet, disabledCheck)
Expand All @@ -418,7 +418,7 @@ func (s *goCriticSettingsWrapper) inferEnabledChecks(log logutils.Log) {
s.disabledCheckersDebugf()
}

func (s *goCriticSettingsWrapper) validate(log logutils.Log) error {
func (s *goCriticSettingsWrapper) validate() error {
if len(s.EnabledTags) == 0 {
if len(s.EnabledChecks) != 0 && len(s.DisabledChecks) != 0 {
return errors.New("both enabled and disabled check aren't allowed for gocritic")
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *goCriticSettingsWrapper) validate(log logutils.Log) error {
return errors.Wrap(err, "validate disabled checks")
}

if err := s.validateCheckerNames(log); err != nil {
if err := s.validateCheckerNames(); err != nil {
return errors.Wrap(err, "validation failed")
}

Expand Down Expand Up @@ -502,7 +502,7 @@ func (s *goCriticSettingsWrapper) getDefaultDisabledCheckersNames() []string {
return disabled
}

func (s *goCriticSettingsWrapper) validateCheckerNames(log logutils.Log) error {
func (s *goCriticSettingsWrapper) validateCheckerNames() error {
allowedNames := s.getAllCheckerNames()

for _, name := range s.EnabledChecks {
Expand All @@ -526,7 +526,7 @@ func (s *goCriticSettingsWrapper) validateCheckerNames(log logutils.Log) error {
}

if !s.isCheckEnabled(checkName) {
log.Warnf("%s: settings were provided for not enabled check %q", goCriticName, checkName)
s.logger.Warnf("%s: settings were provided for not enabled check %q", goCriticName, checkName)
}
}

Expand All @@ -543,13 +543,13 @@ func (s *goCriticSettingsWrapper) getLowerCasedParams() map[string]config.GoCrit
return ret
}

func (s *goCriticSettingsWrapper) filterByDisableTags(enabledChecks, disableTags []string, log logutils.Log) []string {
func (s *goCriticSettingsWrapper) filterByDisableTags(enabledChecks, disableTags []string) []string {
enabledChecksSet := stringsSliceToSet(enabledChecks)

for _, enabledCheck := range enabledChecks {
checkInfo, checkInfoExists := s.allCheckerMap[enabledCheck]
if !checkInfoExists {
log.Warnf("%s: check %q was not exists via filtering disabled tags", goCriticName, enabledCheck)
s.logger.Warnf("%s: check %q was not exists via filtering disabled tags", goCriticName, enabledCheck)
continue
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/golinters/gocritic_test.go
Expand Up @@ -25,9 +25,9 @@ func Test_filterByDisableTags(t *testing.T) {
disabledTags := []string{"experimental", "opinionated"}
enabledChecks := []string{"appendAssign", "sortSlice", "caseOrder", "dupImport"}

settingsWrapper := newGoCriticSettingsWrapper(nil)
settingsWrapper := newGoCriticSettingsWrapper(nil, &tLog{})

filterEnabledChecks := settingsWrapper.filterByDisableTags(enabledChecks, disabledTags, &tLog{})
filterEnabledChecks := settingsWrapper.filterByDisableTags(enabledChecks, disabledTags)

sort.Strings(filterEnabledChecks)

Expand Down

0 comments on commit 10070c5

Please sign in to comment.