Skip to content

Commit 244554b

Browse files
ldezSeigeC
authored andcommitted
bump golang.org/x/tools to HEAD (golangci#2875)
* bump golang.org/x/tools to HEAD * fix: adapt linters to the new validation system.
1 parent 36a5c1e commit 244554b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2222
-1649
lines changed

go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ require (
9999
github.com/yagipy/maintidx v1.0.0
100100
github.com/yeya24/promlinter v0.2.0
101101
gitlab.com/bosi/decorder v0.2.1
102-
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a
102+
golang.org/x/tools v0.1.11-0.20220518213611-904e24e9fcf9
103103
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
104104
honnef.co/go/tools v0.3.1
105105
mvdan.cc/gofumpt v0.3.1
@@ -165,11 +165,10 @@ require (
165165
github.com/valyala/bytebufferpool v1.0.0 // indirect
166166
github.com/yusufpapurcu/wmi v1.2.2 // indirect
167167
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
168-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
168+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
169169
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
170170
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
171171
golang.org/x/text v0.3.7 // indirect
172-
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
173172
google.golang.org/protobuf v1.28.0 // indirect
174173
gopkg.in/ini.v1 v1.66.4 // indirect
175174
gopkg.in/yaml.v2 v2.4.0 // indirect

go.sum

+4-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/asciicheck.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ func NewAsciicheck() *goanalysis.Linter {
1111
return goanalysis.NewLinter(
1212
"asciicheck",
1313
"Simple linter to check that your code does not contain non-ASCII identifiers",
14-
[]*analysis.Analyzer{
15-
asciicheck.NewAnalyzer(),
16-
},
14+
[]*analysis.Analyzer{asciicheck.NewAnalyzer()},
1715
nil,
1816
).WithLoadMode(goanalysis.LoadModeSyntax)
1917
}

pkg/golinters/bodyclose.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import (
88
)
99

1010
func NewBodyclose() *goanalysis.Linter {
11-
analyzers := []*analysis.Analyzer{
12-
bodyclose.Analyzer,
13-
}
14-
1511
return goanalysis.NewLinter(
1612
"bodyclose",
1713
"checks whether HTTP response body is closed successfully",
18-
analyzers,
14+
[]*analysis.Analyzer{bodyclose.Analyzer},
1915
nil,
2016
).WithLoadMode(goanalysis.LoadModeTypesInfo)
2117
}

pkg/golinters/contextcheck.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import (
88
)
99

1010
func NewContextCheck() *goanalysis.Linter {
11-
analyzer := contextcheck.NewAnalyzer()
1211
return goanalysis.NewLinter(
1312
"contextcheck",
1413
"check the function whether use a non-inherited context",
15-
[]*analysis.Analyzer{analyzer},
14+
[]*analysis.Analyzer{contextcheck.NewAnalyzer()},
1615
nil,
1716
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1817
}

pkg/golinters/deadcode.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,46 @@ import (
1212
"github.com/golangci/golangci-lint/pkg/result"
1313
)
1414

15+
const deadcodeName = "deadcode"
16+
1517
func NewDeadcode() *goanalysis.Linter {
16-
const linterName = "deadcode"
1718
var mu sync.Mutex
1819
var resIssues []goanalysis.Issue
1920

2021
analyzer := &analysis.Analyzer{
21-
Name: linterName,
22+
Name: deadcodeName,
2223
Doc: goanalysis.TheOnlyanalyzerDoc,
2324
Run: func(pass *analysis.Pass) (interface{}, error) {
2425
prog := goanalysis.MakeFakeLoaderProgram(pass)
26+
2527
issues, err := deadcodeAPI.Run(prog)
2628
if err != nil {
2729
return nil, err
2830
}
31+
2932
res := make([]goanalysis.Issue, 0, len(issues))
3033
for _, i := range issues {
3134
res = append(res, goanalysis.NewIssue(&result.Issue{
3235
Pos: i.Pos,
3336
Text: fmt.Sprintf("%s is unused", formatCode(i.UnusedIdentName, nil)),
34-
FromLinter: linterName,
37+
FromLinter: deadcodeName,
3538
}, pass))
3639
}
40+
41+
if len(issues) == 0 {
42+
return nil, nil
43+
}
44+
3745
mu.Lock()
3846
resIssues = append(resIssues, res...)
3947
mu.Unlock()
4048

4149
return nil, nil
4250
},
4351
}
52+
4453
return goanalysis.NewLinter(
45-
linterName,
54+
deadcodeName,
4655
"Finds unused code",
4756
[]*analysis.Analyzer{analyzer},
4857
nil,

pkg/golinters/decorder.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
func NewDecorder(settings *config.DecorderSettings) *goanalysis.Linter {
1414
a := decorder.Analyzer
1515

16-
analyzers := []*analysis.Analyzer{a}
17-
1816
// disable all rules/checks by default
1917
cfg := map[string]interface{}{
2018
"disable-dec-num-check": true,
@@ -32,7 +30,7 @@ func NewDecorder(settings *config.DecorderSettings) *goanalysis.Linter {
3230
return goanalysis.NewLinter(
3331
a.Name,
3432
a.Doc,
35-
analyzers,
33+
[]*analysis.Analyzer{a},
3634
map[string]map[string]interface{}{a.Name: cfg},
3735
).WithLoadMode(goanalysis.LoadModeSyntax)
3836
}

pkg/golinters/depguard.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,25 @@ import (
1515
"github.com/golangci/golangci-lint/pkg/result"
1616
)
1717

18-
const depguardLinterName = "depguard"
18+
const depguardName = "depguard"
1919

20-
func NewDepguard() *goanalysis.Linter {
20+
func NewDepguard(settings *config.DepGuardSettings) *goanalysis.Linter {
2121
var mu sync.Mutex
2222
var resIssues []goanalysis.Issue
2323

2424
analyzer := &analysis.Analyzer{
25-
Name: depguardLinterName,
25+
Name: depguardName,
2626
Doc: goanalysis.TheOnlyanalyzerDoc,
27+
Run: goanalysis.DummyRun,
2728
}
29+
2830
return goanalysis.NewLinter(
29-
depguardLinterName,
31+
depguardName,
3032
"Go linter that checks if package imports are in a list of acceptable packages",
3133
[]*analysis.Analyzer{analyzer},
3234
nil,
3335
).WithContextSetter(func(lintCtx *linter.Context) {
34-
dg, err := newDepGuard(&lintCtx.Settings().Depguard)
36+
dg, err := newDepGuard(settings)
3537

3638
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
3739
if err != nil {
@@ -153,7 +155,7 @@ func (g guardian) run(loadConfig *loader.Config, prog *loader.Program, pass *ana
153155
goanalysis.NewIssue(&result.Issue{
154156
Pos: issue.Position,
155157
Text: g.createMsg(issue.PackageName),
156-
FromLinter: depguardLinterName,
158+
FromLinter: depguardName,
157159
}, pass),
158160
)
159161
}

pkg/golinters/dogsled.go

+39-25
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,65 @@ import (
88

99
"golang.org/x/tools/go/analysis"
1010

11+
"github.com/golangci/golangci-lint/pkg/config"
1112
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
1213
"github.com/golangci/golangci-lint/pkg/lint/linter"
1314
"github.com/golangci/golangci-lint/pkg/result"
1415
)
1516

16-
const dogsledLinterName = "dogsled"
17+
const dogsledName = "dogsled"
1718

18-
func NewDogsled() *goanalysis.Linter {
19+
//nolint:dupl
20+
func NewDogsled(settings *config.DogsledSettings) *goanalysis.Linter {
1921
var mu sync.Mutex
2022
var resIssues []goanalysis.Issue
2123

2224
analyzer := &analysis.Analyzer{
23-
Name: dogsledLinterName,
25+
Name: dogsledName,
2426
Doc: goanalysis.TheOnlyanalyzerDoc,
25-
}
26-
return goanalysis.NewLinter(
27-
dogsledLinterName,
28-
"Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())",
29-
[]*analysis.Analyzer{analyzer},
30-
nil,
31-
).WithContextSetter(func(lintCtx *linter.Context) {
32-
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
33-
var pkgIssues []goanalysis.Issue
34-
for _, f := range pass.Files {
35-
v := returnsVisitor{
36-
maxBlanks: lintCtx.Settings().Dogsled.MaxBlankIdentifiers,
37-
f: pass.Fset,
38-
}
39-
ast.Walk(&v, f)
40-
for i := range v.issues {
41-
pkgIssues = append(pkgIssues, goanalysis.NewIssue(&v.issues[i], pass))
42-
}
27+
Run: func(pass *analysis.Pass) (interface{}, error) {
28+
issues := runDogsled(pass, settings)
29+
30+
if len(issues) == 0 {
31+
return nil, nil
4332
}
4433

4534
mu.Lock()
46-
resIssues = append(resIssues, pkgIssues...)
35+
resIssues = append(resIssues, issues...)
4736
mu.Unlock()
4837

4938
return nil, nil
50-
}
51-
}).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
39+
},
40+
}
41+
42+
return goanalysis.NewLinter(
43+
dogsledName,
44+
"Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())",
45+
[]*analysis.Analyzer{analyzer},
46+
nil,
47+
).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
5248
return resIssues
5349
}).WithLoadMode(goanalysis.LoadModeSyntax)
5450
}
5551

52+
func runDogsled(pass *analysis.Pass, settings *config.DogsledSettings) []goanalysis.Issue {
53+
var reports []goanalysis.Issue
54+
for _, f := range pass.Files {
55+
v := &returnsVisitor{
56+
maxBlanks: settings.MaxBlankIdentifiers,
57+
f: pass.Fset,
58+
}
59+
60+
ast.Walk(v, f)
61+
62+
for i := range v.issues {
63+
reports = append(reports, goanalysis.NewIssue(&v.issues[i], pass))
64+
}
65+
}
66+
67+
return reports
68+
}
69+
5670
type returnsVisitor struct {
5771
f *token.FileSet
5872
maxBlanks int
@@ -87,7 +101,7 @@ func (v *returnsVisitor) Visit(node ast.Node) ast.Visitor {
87101

88102
if numBlank > v.maxBlanks {
89103
v.issues = append(v.issues, result.Issue{
90-
FromLinter: dogsledLinterName,
104+
FromLinter: dogsledName,
91105
Text: fmt.Sprintf("declaration has %v blank identifiers", numBlank),
92106
Pos: v.f.Position(assgnStmt.Pos()),
93107
})

0 commit comments

Comments
 (0)