Skip to content

Commit ce020c6

Browse files
alexandearldez
andauthored
dev: use analyzer fields for name, doc instead of hardcoded strings (#4214)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 4384969 commit ce020c6

18 files changed

+61
-54
lines changed

pkg/golinters/asciicheck.go

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

1010
func NewAsciicheck() *goanalysis.Linter {
11+
a := asciicheck.NewAnalyzer()
12+
1113
return goanalysis.NewLinter(
12-
"asciicheck",
13-
"Simple linter to check that your code does not contain non-ASCII identifiers",
14-
[]*analysis.Analyzer{asciicheck.NewAnalyzer()},
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
1517
nil,
1618
).WithLoadMode(goanalysis.LoadModeSyntax)
1719
}

pkg/golinters/bidichk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewBiDiChkFuncName(cfg *config.BiDiChkSettings) *goanalysis.Linter {
5151
}
5252

5353
return goanalysis.NewLinter(
54-
"bidichk",
54+
a.Name,
5555
"Checks for dangerous unicode character sequences",
5656
[]*analysis.Analyzer{a},
5757
cfgMap,

pkg/golinters/cyclop.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
99
)
1010

11-
const cyclopName = "cyclop"
12-
1311
func NewCyclop(settings *config.Cyclop) *goanalysis.Linter {
1412
a := analyzer.NewAnalyzer()
1513

@@ -31,7 +29,7 @@ func NewCyclop(settings *config.Cyclop) *goanalysis.Linter {
3129
}
3230

3331
return goanalysis.NewLinter(
34-
cyclopName,
32+
a.Name,
3533
"checks function and package cyclomatic complexity",
3634
[]*analysis.Analyzer{a},
3735
cfg,

pkg/golinters/errchkjson.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ func NewErrChkJSONFuncName(cfg *config.ErrChkJSONSettings) *goanalysis.Linter {
2323
}
2424

2525
return goanalysis.NewLinter(
26-
"errchkjson",
27-
"Checks types passed to the json encoding functions. "+
28-
"Reports unsupported types and optionally reports occasions, "+
29-
"where the check for the returned error can be omitted.",
26+
a.Name,
27+
a.Doc,
3028
[]*analysis.Analyzer{a},
3129
cfgMap,
3230
).WithLoadMode(goanalysis.LoadModeTypesInfo)

pkg/golinters/errname.go

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

1010
func NewErrName() *goanalysis.Linter {
11+
a := analyzer.New()
12+
1113
return goanalysis.NewLinter(
12-
"errname",
13-
"Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.",
14-
[]*analysis.Analyzer{analyzer.New()},
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
1517
nil,
1618
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1719
}

pkg/golinters/goprintffuncname.go

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

1010
func NewGoPrintfFuncName() *goanalysis.Linter {
11+
a := analyzer.Analyzer
12+
1113
return goanalysis.NewLinter(
12-
"goprintffuncname",
13-
"Checks that printf-like functions are named with `f` at the end",
14-
[]*analysis.Analyzer{analyzer.Analyzer},
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
1517
nil,
1618
).WithLoadMode(goanalysis.LoadModeSyntax)
1719
}

pkg/golinters/grouper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewGrouper(settings *config.GrouperSettings) *goanalysis.Linter {
2525

2626
return goanalysis.NewLinter(
2727
"grouper",
28-
"An analyzer to analyze expression groups.",
28+
"Analyze expression groups.",
2929
[]*analysis.Analyzer{grouper.New()},
3030
linterCfg,
3131
).WithLoadMode(goanalysis.LoadModeSyntax)

pkg/golinters/ifshort.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ func NewIfshort(settings *config.IfshortSettings) *goanalysis.Linter {
1919
}
2020
}
2121

22+
a := analyzer.Analyzer
23+
2224
return goanalysis.NewLinter(
23-
"ifshort",
24-
"Checks that your code uses short syntax for if-statements whenever possible",
25-
[]*analysis.Analyzer{analyzer.Analyzer},
25+
a.Name,
26+
a.Doc,
27+
[]*analysis.Analyzer{a},
2628
cfg,
2729
).WithLoadMode(goanalysis.LoadModeSyntax)
2830
}

pkg/golinters/ineffassign.go

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

1010
func NewIneffassign() *goanalysis.Linter {
11+
a := ineffassign.Analyzer
12+
1113
return goanalysis.NewLinter(
12-
"ineffassign",
14+
a.Name,
1315
"Detects when assignments to existing variables are not used",
14-
[]*analysis.Analyzer{ineffassign.Analyzer},
16+
[]*analysis.Analyzer{a},
1517
nil,
1618
).WithLoadMode(goanalysis.LoadModeSyntax)
1719
}

pkg/golinters/nakedret.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ import (
88
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
99
)
1010

11-
const nakedretName = "nakedret"
12-
1311
func NewNakedret(settings *config.NakedretSettings) *goanalysis.Linter {
1412
var maxLines int
1513
if settings != nil {
1614
maxLines = settings.MaxFuncLines
1715
}
1816

19-
analyzer := nakedret.NakedReturnAnalyzer(uint(maxLines))
17+
a := nakedret.NakedReturnAnalyzer(uint(maxLines))
2018

2119
return goanalysis.NewLinter(
22-
nakedretName,
23-
"Finds naked returns in functions greater than a specified function length",
24-
[]*analysis.Analyzer{analyzer},
20+
a.Name,
21+
a.Doc,
22+
[]*analysis.Analyzer{a},
2523
nil,
2624
).WithLoadMode(goanalysis.LoadModeSyntax)
2725
}

pkg/golinters/noctx.go

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

1010
func NewNoctx() *goanalysis.Linter {
11+
a := noctx.Analyzer
12+
1113
return goanalysis.NewLinter(
12-
"noctx",
13-
"noctx finds sending http request without context.Context",
14-
[]*analysis.Analyzer{noctx.Analyzer},
14+
a.Name,
15+
"Detects test helpers which is not start with t.Helper() method",
16+
[]*analysis.Analyzer{a},
1517
nil,
1618
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1719
}

pkg/golinters/paralleltest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func NewParallelTest(settings *config.ParallelTestSettings) *goanalysis.Linter {
2222
}
2323

2424
return goanalysis.NewLinter(
25-
"paralleltest",
26-
"paralleltest detects missing usage of t.Parallel() method in your Go test",
25+
a.Name,
26+
"Detects missing usage of t.Parallel() method in your Go test",
2727
[]*analysis.Analyzer{a},
2828
cfg,
2929
).WithLoadMode(goanalysis.LoadModeTypesInfo)

pkg/golinters/rowserrcheck.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ func NewRowsErrCheck(settings *config.RowsErrCheckSettings) *goanalysis.Linter {
1414
pkgs = settings.Packages
1515
}
1616

17-
analyzer := rowserr.NewAnalyzer(pkgs...)
17+
a := rowserr.NewAnalyzer(pkgs...)
1818

1919
return goanalysis.NewLinter(
20-
"rowserrcheck",
21-
"checks whether Err of rows is checked successfully",
22-
[]*analysis.Analyzer{analyzer},
20+
a.Name,
21+
"checks whether Rows.Err of rows is checked successfully",
22+
[]*analysis.Analyzer{a},
2323
nil,
2424
).WithLoadMode(goanalysis.LoadModeTypesInfo)
2525
}

pkg/golinters/sqlclosecheck.go

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

1010
func NewSQLCloseCheck() *goanalysis.Linter {
11+
a := analyzer.NewAnalyzer()
12+
1113
return goanalysis.NewLinter(
12-
"sqlclosecheck",
13-
"Checks that sql.Rows and sql.Stmt are closed.",
14-
[]*analysis.Analyzer{
15-
analyzer.NewAnalyzer(),
16-
},
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
1717
nil,
1818
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1919
}

pkg/golinters/thelper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter {
5454
}
5555

5656
return goanalysis.NewLinter(
57-
"thelper",
58-
"thelper detects Go test helpers without t.Helper() call and checks the consistency of test helpers",
57+
a.Name,
58+
a.Doc,
5959
[]*analysis.Analyzer{a},
6060
cfgMap,
6161
).WithLoadMode(goanalysis.LoadModeTypesInfo)

pkg/golinters/tparallel.go

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

1010
func NewTparallel() *goanalysis.Linter {
11+
a := tparallel.Analyzer
1112
return goanalysis.NewLinter(
12-
"tparallel",
13-
"tparallel detects inappropriate usage of t.Parallel() method in your Go test codes",
14-
[]*analysis.Analyzer{tparallel.Analyzer},
13+
a.Name,
14+
a.Doc,
15+
[]*analysis.Analyzer{a},
1516
nil,
1617
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1718
}

pkg/golinters/wastedassign.go

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

1010
func NewWastedAssign() *goanalysis.Linter {
11+
a := wastedassign.Analyzer
12+
1113
return goanalysis.NewLinter(
12-
"wastedassign",
13-
"wastedassign finds wasted assignment statements.",
14-
[]*analysis.Analyzer{wastedassign.Analyzer},
14+
a.Name,
15+
"Finds wasted assignment statements",
16+
[]*analysis.Analyzer{a},
1517
nil,
1618
).WithLoadMode(goanalysis.LoadModeTypesInfo)
1719
}

pkg/golinters/wrapcheck.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
99
)
1010

11-
const wrapcheckName = "wrapcheck"
12-
1311
func NewWrapcheck(settings *config.WrapcheckSettings) *goanalysis.Linter {
1412
cfg := wrapcheck.NewDefaultConfig()
1513
if settings != nil {
@@ -30,7 +28,7 @@ func NewWrapcheck(settings *config.WrapcheckSettings) *goanalysis.Linter {
3028
a := wrapcheck.NewAnalyzer(cfg)
3129

3230
return goanalysis.NewLinter(
33-
wrapcheckName,
31+
a.Name,
3432
a.Doc,
3533
[]*analysis.Analyzer{a},
3634
nil,

0 commit comments

Comments
 (0)