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(),
},
nil,
)
).WithLoadMode(goanalysis.LoadModeSyntax)
}

View File

@ -203,6 +203,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()).
@ -306,6 +307,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).
@ -333,6 +335,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).
@ -344,6 +347,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).

View File

@ -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
}

View File

@ -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(),
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}