Skip to content

Commit

Permalink
Feature: Add asasalint to lint pass []any as any
Browse files Browse the repository at this point in the history
update go.mod
  • Loading branch information
alingse committed Jul 10, 2022
1 parent 9317da6 commit eb910ef
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.2.0
github.com/OpenPeeDeeP/depguard v1.1.0
github.com/alexkohler/prealloc v1.0.0
github.com/alingse/asasalint v0.0.5
github.com/ashanbrown/forbidigo v1.3.0
github.com/ashanbrown/makezero v1.1.1
github.com/bkielbasa/cyclop v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum

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

7 changes: 7 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var defaultLintersSettings = LintersSettings{
}

type LintersSettings struct {
Asasalint AsasalintSettings
BiDiChk BiDiChkSettings
Cyclop Cyclop
Decorder DecorderSettings
Expand Down Expand Up @@ -184,6 +185,12 @@ type LintersSettings struct {
Custom map[string]CustomLinterSettings
}

type AsasalintSettings struct {
Exclude []string `mapstructure:"exclude"`
NoDefaultExclude bool `mapstructure:"no_default_exclude"`
IgnoreInTest bool `mapstructure:"ignore_in_test"`
}

type BiDiChkSettings struct {
LeftToRightEmbedding bool `mapstructure:"left-to-right-embedding"`
RightToLeftEmbedding bool `mapstructure:"right-to-left-embedding"`
Expand Down
26 changes: 26 additions & 0 deletions pkg/golinters/asasalint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package golinters

import (
"github.com/alingse/asasalint"
"golang.org/x/tools/go/analysis"

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

func NewAsasalint(cfg *config.AsasalintSettings) *goanalysis.Linter {
setting := asasalint.LinterSetting{}
if cfg != nil {
setting.Exclude = cfg.Exclude
setting.NoDefaultExclude = cfg.NoDefaultExclude
setting.IgnoreInTest = cfg.IgnoreInTest
}
a := asasalint.NewAnalyzer(setting)

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
8 changes: 8 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config)
//nolint:funlen
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var (
asasalintCfg *config.AsasalintSettings
bidichkCfg *config.BiDiChkSettings
cyclopCfg *config.Cyclop
decorderCfg *config.DecorderSettings
Expand Down Expand Up @@ -171,6 +172,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
)

if m.cfg != nil {
asasalintCfg = &m.cfg.LintersSettings.Asasalint
bidichkCfg = &m.cfg.LintersSettings.BiDiChk
cyclopCfg = &m.cfg.LintersSettings.Cyclop
decorderCfg = &m.cfg.LintersSettings.Decorder
Expand Down Expand Up @@ -266,6 +268,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
// The linters are sorted in the alphabetical order (case-insensitive).
// When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint.
lcs := []*linter.Config{
linter.NewConfig(golinters.NewAsasalint(asasalintCfg)).
WithSince("1.47.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/alingse/asasalint"),

linter.NewConfig(golinters.NewAsciicheck()).
WithSince("v1.26.0").
WithPresets(linter.PresetBugs, linter.PresetStyle).
Expand Down
17 changes: 17 additions & 0 deletions test/testdata/asasalint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testdata

import "fmt"

func getArgsLength(args ...any) int {
return len(args)
}

func checkArgsLength(args ...any) int {
return getArgsLength(args)
}

func someCall() {
var a = []any{1, 2, 3}
fmt.Println(checkArgsLength(a...) == getArgsLength(a))
fmt.Println(checkArgsLength(a...) == getArgsLength(a...))
}

0 comments on commit eb910ef

Please sign in to comment.