-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linter
asasalint
to lint pass []any as any (#2968)
- Loading branch information
Showing
7 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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(setting *config.AsasalintSettings) *goanalysis.Linter { | ||
cfg := asasalint.LinterSetting{} | ||
if setting != nil { | ||
cfg.Exclude = setting.Exclude | ||
cfg.NoBuiltinExclusions = !setting.UseBuiltinExclusions | ||
cfg.IgnoreTest = setting.IgnoreTest | ||
} | ||
|
||
a, err := asasalint.NewAnalyzer(cfg) | ||
if err != nil { | ||
linterLogger.Fatalf("asasalint: create analyzer: %v", err) | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
nil, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//golangcitest:args -Easasalint | ||
package testdata | ||
|
||
import "fmt" | ||
|
||
func getArgsLength(args ...interface{}) int { | ||
// this line will not report as error | ||
fmt.Println(args) | ||
return len(args) | ||
} | ||
|
||
func checkArgsLength(args ...interface{}) int { | ||
return getArgsLength(args) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` | ||
} | ||
|
||
func someCall() { | ||
var a = []interface{}{1, 2, 3} | ||
fmt.Println(checkArgsLength(a...) == getArgsLength(a)) // ERROR `pass \[\]any as any to func getArgsLength func\(args \.\.\.interface\{\}\)` | ||
fmt.Println(checkArgsLength(a...) == getArgsLength(a...)) | ||
} |