Skip to content

Commit 4532eb9

Browse files
authored
fix: gochecknoinits shadow name (#4698)
1 parent 4bf574a commit 4532eb9

File tree

34 files changed

+144
-144
lines changed

34 files changed

+144
-144
lines changed

pkg/golinters/dogsled/dogsled.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/result"
1515
)
1616

17-
const name = "dogsled"
17+
const linterName = "dogsled"
1818

1919
func New(settings *config.DogsledSettings) *goanalysis.Linter {
2020
var mu sync.Mutex
2121
var resIssues []goanalysis.Issue
2222

2323
analyzer := &analysis.Analyzer{
24-
Name: name,
24+
Name: linterName,
2525
Doc: goanalysis.TheOnlyanalyzerDoc,
2626
Run: func(pass *analysis.Pass) (any, error) {
2727
issues := runDogsled(pass, settings)
@@ -39,7 +39,7 @@ func New(settings *config.DogsledSettings) *goanalysis.Linter {
3939
}
4040

4141
return goanalysis.NewLinter(
42-
name,
42+
linterName,
4343
"Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())",
4444
[]*analysis.Analyzer{analyzer},
4545
nil,
@@ -100,7 +100,7 @@ func (v *returnsVisitor) Visit(node ast.Node) ast.Visitor {
100100

101101
if numBlank > v.maxBlanks {
102102
v.issues = append(v.issues, result.Issue{
103-
FromLinter: name,
103+
FromLinter: linterName,
104104
Text: fmt.Sprintf("declaration has %v blank identifiers", numBlank),
105105
Pos: v.f.Position(assgnStmt.Pos()),
106106
})

pkg/golinters/dupl/dupl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import (
1616
"github.com/golangci/golangci-lint/pkg/result"
1717
)
1818

19-
const name = "dupl"
19+
const linterName = "dupl"
2020

2121
func New(settings *config.DuplSettings) *goanalysis.Linter {
2222
var mu sync.Mutex
2323
var resIssues []goanalysis.Issue
2424

2525
analyzer := &analysis.Analyzer{
26-
Name: name,
26+
Name: linterName,
2727
Doc: goanalysis.TheOnlyanalyzerDoc,
2828
Run: func(pass *analysis.Pass) (any, error) {
2929
issues, err := runDupl(pass, settings)
@@ -44,7 +44,7 @@ func New(settings *config.DuplSettings) *goanalysis.Linter {
4444
}
4545

4646
return goanalysis.NewLinter(
47-
name,
47+
linterName,
4848
"Tool for code clone detection",
4949
[]*analysis.Analyzer{analyzer},
5050
nil,
@@ -88,7 +88,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I
8888
To: i.From.LineEnd(),
8989
},
9090
Text: text,
91-
FromLinter: name,
91+
FromLinter: linterName,
9292
}, pass))
9393
}
9494

pkg/golinters/errcheck/errcheck.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ import (
2222
"github.com/golangci/golangci-lint/pkg/result"
2323
)
2424

25-
const name = "errcheck"
25+
const linterName = "errcheck"
2626

2727
func New(settings *config.ErrcheckSettings) *goanalysis.Linter {
2828
var mu sync.Mutex
2929
var resIssues []goanalysis.Issue
3030

3131
analyzer := &analysis.Analyzer{
32-
Name: name,
32+
Name: linterName,
3333
Doc: goanalysis.TheOnlyanalyzerDoc,
3434
Run: goanalysis.DummyRun,
3535
}
3636

3737
return goanalysis.NewLinter(
38-
name,
38+
linterName,
3939
"errcheck is a program for checking for unchecked errors in Go code. "+
4040
"These unchecked errors can be critical bugs in some cases",
4141
[]*analysis.Analyzer{analyzer},
@@ -100,7 +100,7 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck
100100

101101
issues[i] = goanalysis.NewIssue(
102102
&result.Issue{
103-
FromLinter: name,
103+
FromLinter: linterName,
104104
Text: text,
105105
Pos: err.Pos,
106106
},

pkg/golinters/forbidigo/forbidigo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/result"
1515
)
1616

17-
const name = "forbidigo"
17+
const linterName = "forbidigo"
1818

1919
func New(settings *config.ForbidigoSettings) *goanalysis.Linter {
2020
var mu sync.Mutex
2121
var resIssues []goanalysis.Issue
2222

2323
analyzer := &analysis.Analyzer{
24-
Name: name,
24+
Name: linterName,
2525
Doc: goanalysis.TheOnlyanalyzerDoc,
2626
Run: func(pass *analysis.Pass) (any, error) {
2727
issues, err := runForbidigo(pass, settings)
@@ -44,7 +44,7 @@ func New(settings *config.ForbidigoSettings) *goanalysis.Linter {
4444
// But we cannot make this depend on the settings and have to mirror the mode chosen in GetAllSupportedLinterConfigs,
4545
// therefore we have to use LoadModeTypesInfo in all cases.
4646
return goanalysis.NewLinter(
47-
name,
47+
linterName,
4848
"Forbids identifiers",
4949
[]*analysis.Analyzer{analyzer},
5050
nil,
@@ -73,7 +73,7 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
7373

7474
forbid, err := forbidigo.NewLinter(patterns, options...)
7575
if err != nil {
76-
return nil, fmt.Errorf("failed to create linter %q: %w", name, err)
76+
return nil, fmt.Errorf("failed to create linter %q: %w", linterName, err)
7777
}
7878

7979
var issues []goanalysis.Issue
@@ -94,7 +94,7 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
9494
issues = append(issues, goanalysis.NewIssue(&result.Issue{
9595
Pos: hint.Position(),
9696
Text: hint.Details(),
97-
FromLinter: name,
97+
FromLinter: linterName,
9898
}, pass))
9999
}
100100
}

pkg/golinters/funlen/funlen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/result"
1515
)
1616

17-
const name = "funlen"
17+
const linterName = "funlen"
1818

1919
func New(settings *config.FunlenSettings) *goanalysis.Linter {
2020
var mu sync.Mutex
2121
var resIssues []goanalysis.Issue
2222

2323
analyzer := &analysis.Analyzer{
24-
Name: name,
24+
Name: linterName,
2525
Doc: goanalysis.TheOnlyanalyzerDoc,
2626
Run: func(pass *analysis.Pass) (any, error) {
2727
issues := runFunlen(pass, settings)
@@ -39,7 +39,7 @@ func New(settings *config.FunlenSettings) *goanalysis.Linter {
3939
}
4040

4141
return goanalysis.NewLinter(
42-
name,
42+
linterName,
4343
"Tool for detection of long functions",
4444
[]*analysis.Analyzer{analyzer},
4545
nil,
@@ -67,7 +67,7 @@ func runFunlen(pass *analysis.Pass, settings *config.FunlenSettings) []goanalysi
6767
Line: i.Pos.Line,
6868
},
6969
Text: strings.TrimRight(i.Message, "\n"),
70-
FromLinter: name,
70+
FromLinter: linterName,
7171
}, pass)
7272
}
7373

pkg/golinters/gci/gci.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import (
2323
"github.com/golangci/golangci-lint/pkg/lint/linter"
2424
)
2525

26-
const name = "gci"
26+
const linterName = "gci"
2727

2828
func New(settings *config.GciSettings) *goanalysis.Linter {
2929
var mu sync.Mutex
3030
var resIssues []goanalysis.Issue
3131

3232
analyzer := &analysis.Analyzer{
33-
Name: name,
33+
Name: linterName,
3434
Doc: goanalysis.TheOnlyanalyzerDoc,
3535
Run: goanalysis.DummyRun,
3636
Requires: []*analysis.Analyzer{
@@ -63,7 +63,7 @@ func New(settings *config.GciSettings) *goanalysis.Linter {
6363
var lock sync.Mutex
6464

6565
return goanalysis.NewLinter(
66-
name,
66+
linterName,
6767
"Gci controls Go package import order and makes it always deterministic.",
6868
[]*analysis.Analyzer{analyzer},
6969
nil,
@@ -111,7 +111,7 @@ func runGci(pass *analysis.Pass, lintCtx *linter.Context, cfg *gcicfg.Config, lo
111111
continue
112112
}
113113

114-
is, err := internal.ExtractIssuesFromPatch(diff, lintCtx, name, getIssuedTextGci)
114+
is, err := internal.ExtractIssuesFromPatch(diff, lintCtx, linterName, getIssuedTextGci)
115115
if err != nil {
116116
return nil, fmt.Errorf("can't extract issues from gci diff output %s: %w", diff, err)
117117
}

pkg/golinters/gochecknoinits/gochecknoinits.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/result"
1515
)
1616

17-
const name = "gochecknoinits"
17+
const linterName = "gochecknoinits"
1818

1919
func New() *goanalysis.Linter {
2020
var mu sync.Mutex
2121
var resIssues []goanalysis.Issue
2222

2323
analyzer := &analysis.Analyzer{
24-
Name: name,
24+
Name: linterName,
2525
Doc: goanalysis.TheOnlyanalyzerDoc,
2626
Run: func(pass *analysis.Pass) (any, error) {
2727
var res []goanalysis.Issue
@@ -44,7 +44,7 @@ func New() *goanalysis.Linter {
4444
}
4545

4646
return goanalysis.NewLinter(
47-
name,
47+
linterName,
4848
"Checks that no init functions are present in Go code",
4949
[]*analysis.Analyzer{analyzer},
5050
nil,
@@ -61,12 +61,12 @@ func checkFileForInits(f *ast.File, fset *token.FileSet) []result.Issue {
6161
continue
6262
}
6363

64-
name := funcDecl.Name.Name
65-
if name == "init" && funcDecl.Recv.NumFields() == 0 {
64+
fnName := funcDecl.Name.Name
65+
if fnName == "init" && funcDecl.Recv.NumFields() == 0 {
6666
res = append(res, result.Issue{
6767
Pos: fset.Position(funcDecl.Pos()),
68-
Text: fmt.Sprintf("don't use %s function", internal.FormatCode(name, nil)),
69-
FromLinter: name,
68+
Text: fmt.Sprintf("don't use %s function", internal.FormatCode(fnName, nil)),
69+
FromLinter: linterName,
7070
})
7171
}
7272
}

pkg/golinters/gochecksumtype/gochecksumtype.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import (
1313
"github.com/golangci/golangci-lint/pkg/result"
1414
)
1515

16-
const name = "gochecksumtype"
16+
const linterName = "gochecksumtype"
1717

1818
func New() *goanalysis.Linter {
1919
var mu sync.Mutex
2020
var resIssues []goanalysis.Issue
2121

2222
analyzer := &analysis.Analyzer{
23-
Name: name,
23+
Name: linterName,
2424
Doc: goanalysis.TheOnlyanalyzerDoc,
2525
Run: func(pass *analysis.Pass) (any, error) {
2626
issues, err := runGoCheckSumType(pass)
@@ -41,7 +41,7 @@ func New() *goanalysis.Linter {
4141
}
4242

4343
return goanalysis.NewLinter(
44-
name,
44+
linterName,
4545
`Run exhaustiveness checks on Go "sum types"`,
4646
[]*analysis.Analyzer{analyzer},
4747
nil,
@@ -70,7 +70,7 @@ func runGoCheckSumType(pass *analysis.Pass) ([]goanalysis.Issue, error) {
7070
}
7171

7272
resIssues = append(resIssues, goanalysis.NewIssue(&result.Issue{
73-
FromLinter: name,
73+
FromLinter: linterName,
7474
Text: strings.TrimPrefix(err.Error(), err.Pos().String()+": "),
7575
Pos: err.Pos(),
7676
}, pass))

pkg/golinters/gocognit/gocognit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/golangci/golangci-lint/pkg/result"
1616
)
1717

18-
const name = "gocognit"
18+
const linterName = "gocognit"
1919

2020
func New(settings *config.GocognitSettings) *goanalysis.Linter {
2121
var mu sync.Mutex
@@ -40,7 +40,7 @@ func New(settings *config.GocognitSettings) *goanalysis.Linter {
4040
}
4141

4242
return goanalysis.NewLinter(
43-
name,
43+
linterName,
4444
"Computes and checks the cognitive complexity of functions",
4545
[]*analysis.Analyzer{analyzer},
4646
nil,
@@ -72,7 +72,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana
7272
Pos: s.Pos,
7373
Text: fmt.Sprintf("cognitive complexity %d of func %s is high (> %d)",
7474
s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity),
75-
FromLinter: name,
75+
FromLinter: linterName,
7676
}, pass))
7777
}
7878

pkg/golinters/goconst/goconst.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/result"
1515
)
1616

17-
const name = "goconst"
17+
const linterName = "goconst"
1818

1919
func New(settings *config.GoConstSettings) *goanalysis.Linter {
2020
var mu sync.Mutex
2121
var resIssues []goanalysis.Issue
2222

2323
analyzer := &analysis.Analyzer{
24-
Name: name,
24+
Name: linterName,
2525
Doc: goanalysis.TheOnlyanalyzerDoc,
2626
Run: func(pass *analysis.Pass) (any, error) {
2727
issues, err := runGoconst(pass, settings)
@@ -42,7 +42,7 @@ func New(settings *config.GoConstSettings) *goanalysis.Linter {
4242
}
4343

4444
return goanalysis.NewLinter(
45-
name,
45+
linterName,
4646
"Finds repeated strings that could be replaced by a constant",
4747
[]*analysis.Analyzer{analyzer},
4848
nil,
@@ -90,7 +90,7 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal
9090
res = append(res, goanalysis.NewIssue(&result.Issue{
9191
Pos: i.Pos,
9292
Text: text,
93-
FromLinter: name,
93+
FromLinter: linterName,
9494
}, pass))
9595
}
9696

0 commit comments

Comments
 (0)