fix: wrong load mode (#1733)

* fix: asciicheck

* fix: exportloopref

* fix: exhaustivestruct

* fix: makezero
This commit is contained in:
Ludovic Fernandez 2021-02-14 19:11:38 +01:00 committed by GitHub
parent b0b2dc6b36
commit 1b30a171ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 11 deletions

View File

@ -15,5 +15,5 @@ func NewAsciicheck() *goanalysis.Linter {
asciicheck.NewAnalyzer(), asciicheck.NewAnalyzer(),
}, },
nil, nil,
) ).WithLoadMode(goanalysis.LoadModeSyntax)
} }

View File

@ -203,6 +203,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithURL(""), WithURL(""),
linter.NewConfig(golinters.NewAsciicheck()). linter.NewConfig(golinters.NewAsciicheck()).
WithPresets(linter.PresetBugs, linter.PresetStyle). WithPresets(linter.PresetBugs, linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/tdakkota/asciicheck"), WithURL("https://github.com/tdakkota/asciicheck"),
linter.NewConfig(golinters.NewGofmt()). linter.NewConfig(golinters.NewGofmt()).
@ -306,6 +307,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithURL("https://github.com/nakabonne/nestif"), WithURL("https://github.com/nakabonne/nestif"),
linter.NewConfig(golinters.NewExportLoopRef()). linter.NewConfig(golinters.NewExportLoopRef()).
WithPresets(linter.PresetBugs). WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/kyoh86/exportloopref"), WithURL("https://github.com/kyoh86/exportloopref"),
linter.NewConfig(golinters.NewExhaustive(exhaustiveCfg)). linter.NewConfig(golinters.NewExhaustive(exhaustiveCfg)).
WithPresets(linter.PresetBugs). WithPresets(linter.PresetBugs).
@ -333,6 +335,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithURL("https://github.com/moricho/tparallel"), WithURL("https://github.com/moricho/tparallel"),
linter.NewConfig(golinters.NewExhaustiveStruct()). linter.NewConfig(golinters.NewExhaustiveStruct()).
WithPresets(linter.PresetStyle). WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/mbilski/exhaustivestruct"), WithURL("https://github.com/mbilski/exhaustivestruct"),
linter.NewConfig(golinters.NewErrorLint(errorlintCfg)). linter.NewConfig(golinters.NewErrorLint(errorlintCfg)).
WithPresets(linter.PresetBugs). WithPresets(linter.PresetBugs).
@ -344,6 +347,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithURL("https://github.com/kunwardeep/paralleltest"), WithURL("https://github.com/kunwardeep/paralleltest"),
linter.NewConfig(golinters.NewMakezero()). linter.NewConfig(golinters.NewMakezero()).
WithPresets(linter.PresetStyle, linter.PresetBugs). WithPresets(linter.PresetStyle, linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/ashanbrown/makezero"), WithURL("https://github.com/ashanbrown/makezero"),
linter.NewConfig(golinters.NewForbidigo()). linter.NewConfig(golinters.NewForbidigo()).
WithPresets(linter.PresetStyle). WithPresets(linter.PresetStyle).

View File

@ -1,4 +1,8 @@
//args: -Easciicheck //args: -Easciicheck
package testdata 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
}

View File

@ -1,11 +1,14 @@
//args: -Eexhaustivestruct //args: -Eexhaustivestruct
package testdata package testdata
import "time"
type Test struct { type Test struct {
A string A string
B int B int
c bool // private field inside the same package are not ignored c bool // private field inside the same package are not ignored
D float64 D float64
E time.Time
} }
var pass = Test{ var pass = Test{
@ -13,21 +16,25 @@ var pass = Test{
B: 0, B: 0,
c: false, c: false,
D: 1.0, D: 1.0,
E: time.Now(),
} }
var failPrivate = Test{ // ERROR "c is missing in Test" var failPrivate = Test{ // ERROR "c is missing in Test"
A: "a", A: "a",
B: 0, B: 0,
D: 1.0, D: 1.0,
E: time.Now(),
} }
var fail = Test{ // ERROR "B is missing in Test" var fail = Test{ // ERROR "B is missing in Test"
A: "a", A: "a",
c: false, c: false,
D: 1.0, D: 1.0,
E: time.Now(),
} }
var failMultiple = Test{ // ERROR "B, D are missing in Test" var failMultiple = Test{ // ERROR "B, D are missing in Test"
A: "a", A: "a",
c: false, c: false,
E: time.Now(),
} }

View File

@ -1,13 +1,15 @@
//args: -Eexportloopref //args: -Eexportloopref
package testdata package testdata
import "fmt"
func dummyFunction() { func dummyFunction() {
var array [4]*int var array [4]*int
var slice []*int var slice []*int
var ref *int var ref *int
var str struct{ x *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} { for i, p := range []int{10, 11, 12, 13} {
printp(&p) printp(&p)
slice = append(slice, &p) // ERROR "exporting a pointer for the loop variable p" slice = append(slice, &p) // ERROR "exporting a pointer for the loop variable p"
@ -27,18 +29,18 @@ func dummyFunction() {
_ = v _ = 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 { for _, p := range slice {
printp(p) 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 { for _, p := range array {
printp(p) printp(p)
} }
println(`captured value expecting "12" but "13"`) fmt.Println(`captured value expecting "12" but "13"`)
printp(ref) printp(ref)
} }
func printp(p *int) { func printp(p *int) {
println(*p) fmt.Println(*p)
} }

View File

@ -1,12 +1,14 @@
//args: -Emakezero //args: -Emakezero
package testdata package testdata
import "math"
func Makezero() []int { 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" return append(x, 1) // ERROR "append to slice `x` with non-zero initialized length"
} }
func MakezeroNolint() []int { 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 return append(x, 1) //nolint:makezero // ok that we're appending to an uninitialized slice
} }

View File

@ -2,12 +2,14 @@
//config: linters-settings.makezero.always=true //config: linters-settings.makezero.always=true
package testdata package testdata
import "math"
func MakezeroAlways() []int { 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 return x
} }
func MakezeroAlwaysNolint() []int { 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 return x
} }