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
  • Loading branch information
alingse committed Jul 10, 2022
1 parent 9317da6 commit acf442b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -178,3 +178,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
)

require github.com/alingse/asasalint v0.0.5 // indirect
4 changes: 4 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
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
@@ -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
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
@@ -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 acf442b

Please sign in to comment.