Skip to content
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

fix: gochecknoinits shadow name #4698

Merged
merged 2 commits into from
May 5, 2024
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
8 changes: 4 additions & 4 deletions pkg/golinters/dogsled/dogsled.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "dogsled"
const linterName = "dogsled"

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

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

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

if numBlank > v.maxBlanks {
v.issues = append(v.issues, result.Issue{
FromLinter: name,
FromLinter: linterName,
Text: fmt.Sprintf("declaration has %v blank identifiers", numBlank),
Pos: v.f.Position(assgnStmt.Pos()),
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/dupl/dupl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "dupl"
const linterName = "dupl"

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

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

return goanalysis.NewLinter(
name,
linterName,
"Tool for code clone detection",
[]*analysis.Analyzer{analyzer},
nil,
Expand Down Expand Up @@ -88,7 +88,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I
To: i.From.LineEnd(),
},
Text: text,
FromLinter: name,
FromLinter: linterName,
}, pass))
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/errcheck/errcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "errcheck"
const linterName = "errcheck"

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

analyzer := &analysis.Analyzer{
Name: name,
Name: linterName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: goanalysis.DummyRun,
}

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

issues[i] = goanalysis.NewIssue(
&result.Issue{
FromLinter: name,
FromLinter: linterName,
Text: text,
Pos: err.Pos,
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/golinters/forbidigo/forbidigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "forbidigo"
const linterName = "forbidigo"

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

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

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

var issues []goanalysis.Issue
Expand All @@ -94,7 +94,7 @@ func runForbidigo(pass *analysis.Pass, settings *config.ForbidigoSettings) ([]go
issues = append(issues, goanalysis.NewIssue(&result.Issue{
Pos: hint.Position(),
Text: hint.Details(),
FromLinter: name,
FromLinter: linterName,
}, pass))
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/funlen/funlen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "funlen"
const linterName = "funlen"

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

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

return goanalysis.NewLinter(
name,
linterName,
"Tool for detection of long functions",
[]*analysis.Analyzer{analyzer},
nil,
Expand Down Expand Up @@ -67,7 +67,7 @@ func runFunlen(pass *analysis.Pass, settings *config.FunlenSettings) []goanalysi
Line: i.Pos.Line,
},
Text: strings.TrimRight(i.Message, "\n"),
FromLinter: name,
FromLinter: linterName,
}, pass)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/gci/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"github.com/golangci/golangci-lint/pkg/lint/linter"
)

const name = "gci"
const linterName = "gci"

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

analyzer := &analysis.Analyzer{
Name: name,
Name: linterName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: goanalysis.DummyRun,
Requires: []*analysis.Analyzer{
Expand Down Expand Up @@ -63,7 +63,7 @@ func New(settings *config.GciSettings) *goanalysis.Linter {
var lock sync.Mutex

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

is, err := internal.ExtractIssuesFromPatch(diff, lintCtx, name, getIssuedTextGci)
is, err := internal.ExtractIssuesFromPatch(diff, lintCtx, linterName, getIssuedTextGci)
if err != nil {
return nil, fmt.Errorf("can't extract issues from gci diff output %s: %w", diff, err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/golinters/gochecknoinits/gochecknoinits.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "gochecknoinits"
const linterName = "gochecknoinits"

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

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

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

name := funcDecl.Name.Name
if name == "init" && funcDecl.Recv.NumFields() == 0 {
fnName := funcDecl.Name.Name
if fnName == "init" && funcDecl.Recv.NumFields() == 0 {
res = append(res, result.Issue{
Pos: fset.Position(funcDecl.Pos()),
Text: fmt.Sprintf("don't use %s function", internal.FormatCode(name, nil)),
FromLinter: name,
Text: fmt.Sprintf("don't use %s function", internal.FormatCode(fnName, nil)),
FromLinter: linterName,
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/gochecksumtype/gochecksumtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "gochecksumtype"
const linterName = "gochecksumtype"

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

analyzer := &analysis.Analyzer{
Name: name,
Name: linterName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: func(pass *analysis.Pass) (any, error) {
issues, err := runGoCheckSumType(pass)
Expand All @@ -41,7 +41,7 @@ func New() *goanalysis.Linter {
}

return goanalysis.NewLinter(
name,
linterName,
`Run exhaustiveness checks on Go "sum types"`,
[]*analysis.Analyzer{analyzer},
nil,
Expand Down Expand Up @@ -70,7 +70,7 @@ func runGoCheckSumType(pass *analysis.Pass) ([]goanalysis.Issue, error) {
}

resIssues = append(resIssues, goanalysis.NewIssue(&result.Issue{
FromLinter: name,
FromLinter: linterName,
Text: strings.TrimPrefix(err.Error(), err.Pos().String()+": "),
Pos: err.Pos(),
}, pass))
Expand Down
6 changes: 3 additions & 3 deletions pkg/golinters/gocognit/gocognit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "gocognit"
const linterName = "gocognit"

func New(settings *config.GocognitSettings) *goanalysis.Linter {
var mu sync.Mutex
Expand All @@ -40,7 +40,7 @@ func New(settings *config.GocognitSettings) *goanalysis.Linter {
}

return goanalysis.NewLinter(
name,
linterName,
"Computes and checks the cognitive complexity of functions",
[]*analysis.Analyzer{analyzer},
nil,
Expand Down Expand Up @@ -72,7 +72,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana
Pos: s.Pos,
Text: fmt.Sprintf("cognitive complexity %d of func %s is high (> %d)",
s.Complexity, internal.FormatCode(s.FuncName, nil), settings.MinComplexity),
FromLinter: name,
FromLinter: linterName,
}, pass))
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/golinters/goconst/goconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const name = "goconst"
const linterName = "goconst"

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

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

return goanalysis.NewLinter(
name,
linterName,
"Finds repeated strings that could be replaced by a constant",
[]*analysis.Analyzer{analyzer},
nil,
Expand Down Expand Up @@ -90,7 +90,7 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal
res = append(res, goanalysis.NewIssue(&result.Issue{
Pos: i.Pos,
Text: text,
FromLinter: name,
FromLinter: linterName,
}, pass))
}

Expand Down
Loading
Loading