Skip to content

fix: wrong load mode #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/golinters/asciicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func NewAsciicheck() *goanalysis.Linter {
asciicheck.NewAnalyzer(),
},
nil,
)
).WithLoadMode(goanalysis.LoadModeSyntax)
}
4 changes: 4 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()).
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand All @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion test/testdata/asciicheck.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions test/testdata/exhaustivestruct.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
//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{
A: "a",
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(),
}
12 changes: 7 additions & 5 deletions test/testdata/exportloopref.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
}
6 changes: 4 additions & 2 deletions test/testdata/makezero.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 4 additions & 2 deletions test/testdata/makezero_always.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}