Skip to content

Commit eb910ef

Browse files
committed
Feature: Add asasalint to lint pass []any as any
update go.mod
1 parent 9317da6 commit eb910ef

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/GaijinEntertainment/go-exhaustruct/v2 v2.2.0
1212
github.com/OpenPeeDeeP/depguard v1.1.0
1313
github.com/alexkohler/prealloc v1.0.0
14+
github.com/alingse/asasalint v0.0.5
1415
github.com/ashanbrown/forbidigo v1.3.0
1516
github.com/ashanbrown/makezero v1.1.1
1617
github.com/bkielbasa/cyclop v1.2.0

Diff for: go.sum

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/config/linters_settings.go

+7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ var defaultLintersSettings = LintersSettings{
113113
}
114114

115115
type LintersSettings struct {
116+
Asasalint AsasalintSettings
116117
BiDiChk BiDiChkSettings
117118
Cyclop Cyclop
118119
Decorder DecorderSettings
@@ -184,6 +185,12 @@ type LintersSettings struct {
184185
Custom map[string]CustomLinterSettings
185186
}
186187

188+
type AsasalintSettings struct {
189+
Exclude []string `mapstructure:"exclude"`
190+
NoDefaultExclude bool `mapstructure:"no_default_exclude"`
191+
IgnoreInTest bool `mapstructure:"ignore_in_test"`
192+
}
193+
187194
type BiDiChkSettings struct {
188195
LeftToRightEmbedding bool `mapstructure:"left-to-right-embedding"`
189196
RightToLeftEmbedding bool `mapstructure:"right-to-left-embedding"`

Diff for: pkg/golinters/asasalint.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package golinters
2+
3+
import (
4+
"github.com/alingse/asasalint"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/config"
8+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
9+
)
10+
11+
func NewAsasalint(cfg *config.AsasalintSettings) *goanalysis.Linter {
12+
setting := asasalint.LinterSetting{}
13+
if cfg != nil {
14+
setting.Exclude = cfg.Exclude
15+
setting.NoDefaultExclude = cfg.NoDefaultExclude
16+
setting.IgnoreInTest = cfg.IgnoreInTest
17+
}
18+
a := asasalint.NewAnalyzer(setting)
19+
20+
return goanalysis.NewLinter(
21+
a.Name,
22+
a.Doc,
23+
[]*analysis.Analyzer{a},
24+
nil,
25+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
26+
}

Diff for: pkg/lint/lintersdb/manager.go

+8
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config)
101101
//nolint:funlen
102102
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
103103
var (
104+
asasalintCfg *config.AsasalintSettings
104105
bidichkCfg *config.BiDiChkSettings
105106
cyclopCfg *config.Cyclop
106107
decorderCfg *config.DecorderSettings
@@ -171,6 +172,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
171172
)
172173

173174
if m.cfg != nil {
175+
asasalintCfg = &m.cfg.LintersSettings.Asasalint
174176
bidichkCfg = &m.cfg.LintersSettings.BiDiChk
175177
cyclopCfg = &m.cfg.LintersSettings.Cyclop
176178
decorderCfg = &m.cfg.LintersSettings.Decorder
@@ -266,6 +268,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
266268
// The linters are sorted in the alphabetical order (case-insensitive).
267269
// When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint.
268270
lcs := []*linter.Config{
271+
linter.NewConfig(golinters.NewAsasalint(asasalintCfg)).
272+
WithSince("1.47.0").
273+
WithPresets(linter.PresetBugs).
274+
WithLoadForGoAnalysis().
275+
WithURL("https://github.com/alingse/asasalint"),
276+
269277
linter.NewConfig(golinters.NewAsciicheck()).
270278
WithSince("v1.26.0").
271279
WithPresets(linter.PresetBugs, linter.PresetStyle).

Diff for: test/testdata/asasalint.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testdata
2+
3+
import "fmt"
4+
5+
func getArgsLength(args ...any) int {
6+
return len(args)
7+
}
8+
9+
func checkArgsLength(args ...any) int {
10+
return getArgsLength(args)
11+
}
12+
13+
func someCall() {
14+
var a = []any{1, 2, 3}
15+
fmt.Println(checkArgsLength(a...) == getArgsLength(a))
16+
fmt.Println(checkArgsLength(a...) == getArgsLength(a...))
17+
}

0 commit comments

Comments
 (0)