diff --git a/pkg/golinters/asciicheck.go b/pkg/golinters/asciicheck.go index 7700c33e7035..1bf8c7b7da19 100644 --- a/pkg/golinters/asciicheck.go +++ b/pkg/golinters/asciicheck.go @@ -15,5 +15,5 @@ func NewAsciicheck() *goanalysis.Linter { asciicheck.NewAnalyzer(), }, nil, - ) + ).WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index b8f4ed880df7..62a7c4600655 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -201,6 +201,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithURL(""), linter.NewConfig(golinters.NewAsciicheck()). WithPresets(linter.PresetBugs, linter.PresetStyle). + WithLoadForGoAnalysis(). WithURL("https://github.com/tdakkota/asciicheck"), linter.NewConfig(golinters.NewGofmt()). @@ -304,6 +305,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithURL("https://github.com/nakabonne/nestif"), linter.NewConfig(golinters.NewExportLoopRef()). WithPresets(linter.PresetBugs). + WithLoadForGoAnalysis(). WithURL("https://github.com/kyoh86/exportloopref"), linter.NewConfig(golinters.NewExhaustive(exhaustiveCfg)). WithPresets(linter.PresetBugs). @@ -331,6 +333,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithURL("https://github.com/moricho/tparallel"), linter.NewConfig(golinters.NewExhaustiveStruct()). WithPresets(linter.PresetStyle). + WithLoadForGoAnalysis(). WithURL("https://github.com/mbilski/exhaustivestruct"), linter.NewConfig(golinters.NewErrorLint(errorlintCfg)). WithPresets(linter.PresetBugs). @@ -342,6 +345,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithURL("https://github.com/kunwardeep/paralleltest"), linter.NewConfig(golinters.NewMakezero()). WithPresets(linter.PresetStyle, linter.PresetBugs). + WithLoadForGoAnalysis(). WithURL("https://github.com/ashanbrown/makezero"), linter.NewConfig(golinters.NewForbidigo()). WithPresets(linter.PresetStyle). diff --git a/test/testdata/asciicheck.go b/test/testdata/asciicheck.go index 3c6cc0c54b46..1c0a9b8efd70 100644 --- a/test/testdata/asciicheck.go +++ b/test/testdata/asciicheck.go @@ -1,4 +1,8 @@ //args: -Easciicheck package testdata -type TеstStruct struct{} // ERROR `identifier "TеstStruct" contain non-ASCII character: U\+0435 'е'` +import "time" + +type TеstStruct struct { // ERROR `identifier "TеstStruct" contain non-ASCII character: U\+0435 'е'` + Date time.Time +} diff --git a/test/testdata/exhaustivestruct.go b/test/testdata/exhaustivestruct.go index fcb01c7a99c9..49b1ea98639d 100644 --- a/test/testdata/exhaustivestruct.go +++ b/test/testdata/exhaustivestruct.go @@ -1,11 +1,14 @@ //args: -Eexhaustivestruct package testdata +import "time" + type Test struct { A string B int c bool // private field inside the same package are not ignored D float64 + E time.Time } var pass = Test{ @@ -13,21 +16,25 @@ var pass = Test{ B: 0, c: false, D: 1.0, + E: time.Now(), } var failPrivate = Test{ // ERROR "c is missing in Test" A: "a", B: 0, D: 1.0, + E: time.Now(), } var fail = Test{ // ERROR "B is missing in Test" A: "a", c: false, D: 1.0, + E: time.Now(), } var failMultiple = Test{ // ERROR "B, D are missing in Test" A: "a", c: false, + E: time.Now(), } diff --git a/test/testdata/exportloopref.go b/test/testdata/exportloopref.go index 839113ad3bc7..f71a3902be53 100644 --- a/test/testdata/exportloopref.go +++ b/test/testdata/exportloopref.go @@ -1,13 +1,15 @@ //args: -Eexportloopref package testdata +import "fmt" + func dummyFunction() { var array [4]*int var slice []*int var ref *int var str struct{ x *int } - println("loop expecting 10, 11, 12, 13") + fmt.Println("loop expecting 10, 11, 12, 13") for i, p := range []int{10, 11, 12, 13} { printp(&p) slice = append(slice, &p) // ERROR "exporting a pointer for the loop variable p" @@ -27,18 +29,18 @@ func dummyFunction() { _ = v } - println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) + fmt.Println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) for _, p := range slice { printp(p) } - println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) + fmt.Println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) for _, p := range array { printp(p) } - println(`captured value expecting "12" but "13"`) + fmt.Println(`captured value expecting "12" but "13"`) printp(ref) } func printp(p *int) { - println(*p) + fmt.Println(*p) } diff --git a/test/testdata/makezero.go b/test/testdata/makezero.go index ca32eda3ec3e..e0f47122d8df 100644 --- a/test/testdata/makezero.go +++ b/test/testdata/makezero.go @@ -1,12 +1,14 @@ //args: -Emakezero package testdata +import "math" + func Makezero() []int { - x := make([]int, 5) + x := make([]int, math.MaxInt8) return append(x, 1) // ERROR "append to slice `x` with non-zero initialized length" } func MakezeroNolint() []int { - x := make([]int, 5) + x := make([]int, math.MaxInt8) return append(x, 1) //nolint:makezero // ok that we're appending to an uninitialized slice } diff --git a/test/testdata/makezero_always.go b/test/testdata/makezero_always.go index e6bdd87d743c..633fb65c2416 100644 --- a/test/testdata/makezero_always.go +++ b/test/testdata/makezero_always.go @@ -2,12 +2,14 @@ //config: linters-settings.makezero.always=true package testdata +import "math" + func MakezeroAlways() []int { - x := make([]int, 5) // ERROR "slice `x` does not have non-zero initial length" + x := make([]int, math.MaxInt8) // ERROR "slice `x` does not have non-zero initial length" return x } func MakezeroAlwaysNolint() []int { - x := make([]int, 5) //nolint:makezero // ok that this is not initialized + x := make([]int, math.MaxInt8) //nolint:makezero // ok that this is not initialized return x }