Skip to content

Commit 1b30a17

Browse files
authored
fix: wrong load mode (#1733)
* fix: asciicheck * fix: exportloopref * fix: exhaustivestruct * fix: makezero
1 parent b0b2dc6 commit 1b30a17

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

pkg/golinters/asciicheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func NewAsciicheck() *goanalysis.Linter {
1515
asciicheck.NewAnalyzer(),
1616
},
1717
nil,
18-
)
18+
).WithLoadMode(goanalysis.LoadModeSyntax)
1919
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
203203
WithURL(""),
204204
linter.NewConfig(golinters.NewAsciicheck()).
205205
WithPresets(linter.PresetBugs, linter.PresetStyle).
206+
WithLoadForGoAnalysis().
206207
WithURL("https://github.com/tdakkota/asciicheck"),
207208

208209
linter.NewConfig(golinters.NewGofmt()).
@@ -306,6 +307,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
306307
WithURL("https://github.com/nakabonne/nestif"),
307308
linter.NewConfig(golinters.NewExportLoopRef()).
308309
WithPresets(linter.PresetBugs).
310+
WithLoadForGoAnalysis().
309311
WithURL("https://github.com/kyoh86/exportloopref"),
310312
linter.NewConfig(golinters.NewExhaustive(exhaustiveCfg)).
311313
WithPresets(linter.PresetBugs).
@@ -333,6 +335,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
333335
WithURL("https://github.com/moricho/tparallel"),
334336
linter.NewConfig(golinters.NewExhaustiveStruct()).
335337
WithPresets(linter.PresetStyle).
338+
WithLoadForGoAnalysis().
336339
WithURL("https://github.com/mbilski/exhaustivestruct"),
337340
linter.NewConfig(golinters.NewErrorLint(errorlintCfg)).
338341
WithPresets(linter.PresetBugs).
@@ -344,6 +347,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
344347
WithURL("https://github.com/kunwardeep/paralleltest"),
345348
linter.NewConfig(golinters.NewMakezero()).
346349
WithPresets(linter.PresetStyle, linter.PresetBugs).
350+
WithLoadForGoAnalysis().
347351
WithURL("https://github.com/ashanbrown/makezero"),
348352
linter.NewConfig(golinters.NewForbidigo()).
349353
WithPresets(linter.PresetStyle).

test/testdata/asciicheck.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//args: -Easciicheck
22
package testdata
33

4-
type TеstStruct struct{} // ERROR `identifier "TеstStruct" contain non-ASCII character: U\+0435 'е'`
4+
import "time"
5+
6+
type TеstStruct struct { // ERROR `identifier "TеstStruct" contain non-ASCII character: U\+0435 'е'`
7+
Date time.Time
8+
}

test/testdata/exhaustivestruct.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
//args: -Eexhaustivestruct
22
package testdata
33

4+
import "time"
5+
46
type Test struct {
57
A string
68
B int
79
c bool // private field inside the same package are not ignored
810
D float64
11+
E time.Time
912
}
1013

1114
var pass = Test{
1215
A: "a",
1316
B: 0,
1417
c: false,
1518
D: 1.0,
19+
E: time.Now(),
1620
}
1721

1822
var failPrivate = Test{ // ERROR "c is missing in Test"
1923
A: "a",
2024
B: 0,
2125
D: 1.0,
26+
E: time.Now(),
2227
}
2328

2429
var fail = Test{ // ERROR "B is missing in Test"
2530
A: "a",
2631
c: false,
2732
D: 1.0,
33+
E: time.Now(),
2834
}
2935

3036
var failMultiple = Test{ // ERROR "B, D are missing in Test"
3137
A: "a",
3238
c: false,
39+
E: time.Now(),
3340
}

test/testdata/exportloopref.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//args: -Eexportloopref
22
package testdata
33

4+
import "fmt"
5+
46
func dummyFunction() {
57
var array [4]*int
68
var slice []*int
79
var ref *int
810
var str struct{ x *int }
911

10-
println("loop expecting 10, 11, 12, 13")
12+
fmt.Println("loop expecting 10, 11, 12, 13")
1113
for i, p := range []int{10, 11, 12, 13} {
1214
printp(&p)
1315
slice = append(slice, &p) // ERROR "exporting a pointer for the loop variable p"
@@ -27,18 +29,18 @@ func dummyFunction() {
2729
_ = v
2830
}
2931

30-
println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
32+
fmt.Println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
3133
for _, p := range slice {
3234
printp(p)
3335
}
34-
println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
36+
fmt.Println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
3537
for _, p := range array {
3638
printp(p)
3739
}
38-
println(`captured value expecting "12" but "13"`)
40+
fmt.Println(`captured value expecting "12" but "13"`)
3941
printp(ref)
4042
}
4143

4244
func printp(p *int) {
43-
println(*p)
45+
fmt.Println(*p)
4446
}

test/testdata/makezero.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//args: -Emakezero
22
package testdata
33

4+
import "math"
5+
46
func Makezero() []int {
5-
x := make([]int, 5)
7+
x := make([]int, math.MaxInt8)
68
return append(x, 1) // ERROR "append to slice `x` with non-zero initialized length"
79
}
810

911
func MakezeroNolint() []int {
10-
x := make([]int, 5)
12+
x := make([]int, math.MaxInt8)
1113
return append(x, 1) //nolint:makezero // ok that we're appending to an uninitialized slice
1214
}

test/testdata/makezero_always.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
//config: linters-settings.makezero.always=true
33
package testdata
44

5+
import "math"
6+
57
func MakezeroAlways() []int {
6-
x := make([]int, 5) // ERROR "slice `x` does not have non-zero initial length"
8+
x := make([]int, math.MaxInt8) // ERROR "slice `x` does not have non-zero initial length"
79
return x
810
}
911

1012
func MakezeroAlwaysNolint() []int {
11-
x := make([]int, 5) //nolint:makezero // ok that this is not initialized
13+
x := make([]int, math.MaxInt8) //nolint:makezero // ok that this is not initialized
1214
return x
1315
}

0 commit comments

Comments
 (0)