Skip to content

Commit ea82373

Browse files
authored
dev: reformat code with gofumpt (#4500)
1 parent 51a963f commit ea82373

File tree

16 files changed

+146
-76
lines changed

16 files changed

+146
-76
lines changed

pkg/fsutils/fsutils.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ func IsDir(filename string) bool {
1212
return err == nil && fi.IsDir()
1313
}
1414

15-
var cachedWd string
16-
var cachedWdError error
17-
var getWdOnce sync.Once
18-
var useCache = true
15+
var (
16+
cachedWd string
17+
cachedWdError error
18+
getWdOnce sync.Once
19+
useCache = true
20+
)
1921

2022
func UseWdCache(use bool) {
2123
useCache = use

pkg/golinters/goanalysis/runner.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ type runner struct {
6161
}
6262

6363
func newRunner(prefix string, logger logutils.Log, pkgCache *pkgcache.Cache, loadGuard *load.Guard,
64-
loadMode LoadMode, sw *timeutils.Stopwatch) *runner {
64+
loadMode LoadMode, sw *timeutils.Stopwatch,
65+
) *runner {
6566
return &runner{
6667
prefix: prefix,
6768
log: logger,
@@ -80,7 +81,8 @@ func newRunner(prefix string, logger logutils.Log, pkgCache *pkgcache.Cache, loa
8081
// singlechecker and the multi-analysis commands.
8182
// It returns the appropriate exit code.
8283
func (r *runner) run(analyzers []*analysis.Analyzer, initialPackages []*packages.Package) ([]Diagnostic,
83-
[]error, map[*analysis.Pass]*packages.Package) {
84+
[]error, map[*analysis.Pass]*packages.Package,
85+
) {
8486
debugf("Analyzing %d packages on load mode %s", len(initialPackages), r.loadMode)
8587
defer r.pkgCache.Trim()
8688

@@ -116,7 +118,8 @@ func (r *runner) markAllActions(a *analysis.Analyzer, pkg *packages.Package, mar
116118
}
117119

118120
func (r *runner) makeAction(a *analysis.Analyzer, pkg *packages.Package,
119-
initialPkgs map[*packages.Package]bool, actions map[actKey]*action, actAlloc *actionAllocator) *action {
121+
initialPkgs map[*packages.Package]bool, actions map[actKey]*action, actAlloc *actionAllocator,
122+
) *action {
120123
k := actKey{a, pkg}
121124
act, ok := actions[k]
122125
if ok {
@@ -150,7 +153,8 @@ func (r *runner) makeAction(a *analysis.Analyzer, pkg *packages.Package,
150153
}
151154

152155
func (r *runner) buildActionFactDeps(act *action, a *analysis.Analyzer, pkg *packages.Package,
153-
initialPkgs map[*packages.Package]bool, actions map[actKey]*action, actAlloc *actionAllocator) {
156+
initialPkgs map[*packages.Package]bool, actions map[actKey]*action, actAlloc *actionAllocator,
157+
) {
154158
// An analysis that consumes/produces facts
155159
// must run on the package's dependencies too.
156160
if len(a.FactTypes) == 0 {
@@ -175,7 +179,8 @@ func (r *runner) buildActionFactDeps(act *action, a *analysis.Analyzer, pkg *pac
175179

176180
//nolint:gocritic
177181
func (r *runner) prepareAnalysis(pkgs []*packages.Package,
178-
analyzers []*analysis.Analyzer) (map[*packages.Package]bool, []*action, []*action) {
182+
analyzers []*analysis.Analyzer,
183+
) (map[*packages.Package]bool, []*action, []*action) {
179184
// Construct the action graph.
180185

181186
// Each graph node (action) is one unit of analysis.

pkg/golinters/goanalysis/runners.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ func getIssuesCacheKey(analyzers []*analysis.Analyzer) string {
124124
}
125125

126126
func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.Package]bool,
127-
issues []result.Issue, lintCtx *linter.Context, analyzers []*analysis.Analyzer) {
127+
issues []result.Issue, lintCtx *linter.Context, analyzers []*analysis.Analyzer,
128+
) {
128129
startedAt := time.Now()
129130
perPkgIssues := map[*packages.Package][]result.Issue{}
130131
for ind := range issues {
@@ -185,7 +186,8 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.
185186

186187
//nolint:gocritic
187188
func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
188-
analyzers []*analysis.Analyzer) ([]result.Issue, map[*packages.Package]bool) {
189+
analyzers []*analysis.Analyzer,
190+
) ([]result.Issue, map[*packages.Package]bool) {
189191
startedAt := time.Now()
190192

191193
lintResKey := getIssuesCacheKey(analyzers)

pkg/golinters/nolintlint/nolintlint.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ func NewLinter(needs Needs, excludes []string) (*Linter, error) {
151151
}, nil
152152
}
153153

154-
var leadingSpacePattern = regexp.MustCompile(`^//(\s*)`)
155-
var trailingBlankExplanation = regexp.MustCompile(`\s*(//\s*)?$`)
154+
var (
155+
leadingSpacePattern = regexp.MustCompile(`^//(\s*)`)
156+
trailingBlankExplanation = regexp.MustCompile(`\s*(//\s*)?$`)
157+
)
156158

157159
//nolint:funlen,gocyclo
158160
func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {

pkg/golinters/testpackage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func NewTestpackage(cfg *config.TestpackageSettings) *goanalysis.Linter {
14-
var a = testpackage.NewAnalyzer()
14+
a := testpackage.NewAnalyzer()
1515

1616
var settings map[string]map[string]any
1717
if cfg != nil {

pkg/lint/load.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ type ContextLoader struct {
3636
}
3737

3838
func NewContextLoader(cfg *config.Config, log logutils.Log, goenv *goutil.Env,
39-
lineCache *fsutils.LineCache, fileCache *fsutils.FileCache, pkgCache *pkgcache.Cache, loadGuard *load.Guard) *ContextLoader {
39+
lineCache *fsutils.LineCache, fileCache *fsutils.FileCache, pkgCache *pkgcache.Cache, loadGuard *load.Guard,
40+
) *ContextLoader {
4041
return &ContextLoader{
4142
cfg: cfg,
4243
log: log,

pkg/lint/runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type Runner struct {
3434

3535
func NewRunner(log logutils.Log, cfg *config.Config, goenv *goutil.Env,
3636
lineCache *fsutils.LineCache, fileCache *fsutils.FileCache,
37-
dbManager *lintersdb.Manager, lintCtx *linter.Context) (*Runner, error) {
37+
dbManager *lintersdb.Manager, lintCtx *linter.Context,
38+
) (*Runner, error) {
3839
// Beware that some processors need to add the path prefix when working with paths
3940
// because they get invoked before the path prefixer (exclude and severity rules)
4041
// or process other paths (skip files).
@@ -129,7 +130,8 @@ func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Is
129130
}
130131

131132
func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
132-
lc *linter.Config) (ret []result.Issue, err error) {
133+
lc *linter.Config,
134+
) (ret []result.Issue, err error) {
133135
defer func() {
134136
if panicData := recover(); panicData != nil {
135137
if pe, ok := panicData.(*errorutil.PanicError); ok {

pkg/logutils/out.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ import (
55
colorable "github.com/mattn/go-colorable"
66
)
77

8-
var StdOut = color.Output // https://github.com/golangci/golangci-lint/issues/14
9-
var StdErr = colorable.NewColorableStderr()
8+
var (
9+
StdOut = color.Output // https://github.com/golangci/golangci-lint/issues/14
10+
StdErr = colorable.NewColorableStderr()
11+
)

pkg/printers/printer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/golangci/golangci-lint/pkg/result"
1414
)
1515

16-
const defaultFileMode = 0644
16+
const defaultFileMode = 0o644
1717

1818
type issuePrinter interface {
1919
Print(issues []result.Issue) error

pkg/result/processors/identifier_marker.go

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +31,80 @@ var replacePatterns = []replacePattern{
3131
{`^composites: (\S+) composite literal uses unkeyed fields$`, "composites: `${1}` composite literal uses unkeyed fields"},
3232

3333
// gosec
34-
{`^(\S+): Blacklisted import (\S+): weak cryptographic primitive$`,
35-
"${1}: Blacklisted import `${2}`: weak cryptographic primitive"},
34+
{
35+
`^(\S+): Blacklisted import (\S+): weak cryptographic primitive$`,
36+
"${1}: Blacklisted import `${2}`: weak cryptographic primitive",
37+
},
3638
{`^TLS InsecureSkipVerify set true.$`, "TLS `InsecureSkipVerify` set true."},
3739

3840
// gosimple
3941
{`should replace loop with (.*)$`, "should replace loop with `${1}`"},
40-
{`should use a simple channel send/receive instead of select with a single case`,
41-
"should use a simple channel send/receive instead of `select` with a single case"},
42-
{`should omit comparison to bool constant, can be simplified to (.+)$`,
43-
"should omit comparison to bool constant, can be simplified to `${1}`"},
42+
{
43+
`should use a simple channel send/receive instead of select with a single case`,
44+
"should use a simple channel send/receive instead of `select` with a single case",
45+
},
46+
{
47+
`should omit comparison to bool constant, can be simplified to (.+)$`,
48+
"should omit comparison to bool constant, can be simplified to `${1}`",
49+
},
4450
{`should write (.+) instead of (.+)$`, "should write `${1}` instead of `${2}`"},
4551
{`redundant return statement$`, "redundant `return` statement"},
46-
{`should replace this if statement with an unconditional strings.TrimPrefix`,
47-
"should replace this `if` statement with an unconditional `strings.TrimPrefix`"},
52+
{
53+
`should replace this if statement with an unconditional strings.TrimPrefix`,
54+
"should replace this `if` statement with an unconditional `strings.TrimPrefix`",
55+
},
4856

4957
// staticcheck
5058
{`this value of (\S+) is never used$`, "this value of `${1}` is never used"},
51-
{`should use time.Since instead of time.Now\(\).Sub$`,
52-
"should use `time.Since` instead of `time.Now().Sub`"},
53-
{`should check returned error before deferring response.Close\(\)$`,
54-
"should check returned error before deferring `response.Close()`"},
59+
{
60+
`should use time.Since instead of time.Now\(\).Sub$`,
61+
"should use `time.Since` instead of `time.Now().Sub`",
62+
},
63+
{
64+
`should check returned error before deferring response.Close\(\)$`,
65+
"should check returned error before deferring `response.Close()`",
66+
},
5567
{`no value of type uint is less than 0$`, "no value of type `uint` is less than `0`"},
5668

5769
// unused
5870
{`(func|const|field|type|var) (\S+) is unused$`, "${1} `${2}` is unused"},
5971

6072
// typecheck
6173
{`^unknown field (\S+) in struct literal$`, "unknown field `${1}` in struct literal"},
62-
{`^invalid operation: (\S+) \(variable of type (\S+)\) has no field or method (\S+)$`,
63-
"invalid operation: `${1}` (variable of type `${2}`) has no field or method `${3}`"},
74+
{
75+
`^invalid operation: (\S+) \(variable of type (\S+)\) has no field or method (\S+)$`,
76+
"invalid operation: `${1}` (variable of type `${2}`) has no field or method `${3}`",
77+
},
6478
{`^undeclared name: (\S+)$`, "undeclared name: `${1}`"},
65-
{`^cannot use addr \(variable of type (\S+)\) as (\S+) value in argument to (\S+)$`,
66-
"cannot use addr (variable of type `${1}`) as `${2}` value in argument to `${3}`"},
79+
{
80+
`^cannot use addr \(variable of type (\S+)\) as (\S+) value in argument to (\S+)$`,
81+
"cannot use addr (variable of type `${1}`) as `${2}` value in argument to `${3}`",
82+
},
6783
{`^other declaration of (\S+)$`, "other declaration of `${1}`"},
6884
{`^(\S+) redeclared in this block$`, "`${1}` redeclared in this block"},
6985

7086
// golint
71-
{`^exported (type|method|function|var|const) (\S+) should have comment or be unexported$`,
72-
"exported ${1} `${2}` should have comment or be unexported"},
73-
{`^comment on exported (type|method|function|var|const) (\S+) should be of the form "(\S+) ..."$`,
74-
"comment on exported ${1} `${2}` should be of the form `${3} ...`"},
87+
{
88+
`^exported (type|method|function|var|const) (\S+) should have comment or be unexported$`,
89+
"exported ${1} `${2}` should have comment or be unexported",
90+
},
91+
{
92+
`^comment on exported (type|method|function|var|const) (\S+) should be of the form "(\S+) ..."$`,
93+
"comment on exported ${1} `${2}` should be of the form `${3} ...`",
94+
},
7595
{`^should replace (.+) with (.+)$`, "should replace `${1}` with `${2}`"},
76-
{`^if block ends with a return statement, so drop this else and outdent its block$`,
77-
"`if` block ends with a `return` statement, so drop this `else` and outdent its block"},
78-
{`^(struct field|var|range var|const|type|(?:func|method|interface method) (?:parameter|result)) (\S+) should be (\S+)$`,
79-
"${1} `${2}` should be `${3}`"},
80-
{`^don't use underscores in Go names; var (\S+) should be (\S+)$`,
81-
"don't use underscores in Go names; var `${1}` should be `${2}`"},
96+
{
97+
`^if block ends with a return statement, so drop this else and outdent its block$`,
98+
"`if` block ends with a `return` statement, so drop this `else` and outdent its block",
99+
},
100+
{
101+
`^(struct field|var|range var|const|type|(?:func|method|interface method) (?:parameter|result)) (\S+) should be (\S+)$`,
102+
"${1} `${2}` should be `${3}`",
103+
},
104+
{
105+
`^don't use underscores in Go names; var (\S+) should be (\S+)$`,
106+
"don't use underscores in Go names; var `${1}` should be `${2}`",
107+
},
82108
}
83109

84110
type IdentifierMarker struct {

pkg/result/processors/identifier_marker_test.go

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,61 @@ func TestIdentifierMarker(t *testing.T) {
1313
//nolint:lll
1414
cases := []struct{ in, out string }{
1515
{"unknown field Address in struct literal", "unknown field `Address` in struct literal"},
16-
{"invalid operation: res (variable of type github.com/iotexproject/iotex-core/explorer/idl/explorer.GetBlkOrActResponse) has no field or method Address",
17-
"invalid operation: `res` (variable of type `github.com/iotexproject/iotex-core/explorer/idl/explorer.GetBlkOrActResponse`) has no field or method `Address`"},
18-
{"should use a simple channel send/receive instead of select with a single case",
19-
"should use a simple channel send/receive instead of `select` with a single case"},
16+
{
17+
"invalid operation: res (variable of type github.com/iotexproject/iotex-core/explorer/idl/explorer.GetBlkOrActResponse) has no field or method Address",
18+
"invalid operation: `res` (variable of type `github.com/iotexproject/iotex-core/explorer/idl/explorer.GetBlkOrActResponse`) has no field or method `Address`",
19+
},
20+
{
21+
"should use a simple channel send/receive instead of select with a single case",
22+
"should use a simple channel send/receive instead of `select` with a single case",
23+
},
2024
{"var testInputs is unused", "var `testInputs` is unused"},
2125
{"undeclared name: stateIDLabel", "undeclared name: `stateIDLabel`"},
22-
{"exported type Metrics should have comment or be unexported",
23-
"exported type `Metrics` should have comment or be unexported"},
24-
{`comment on exported function NewMetrics should be of the form "NewMetrics ..."`,
25-
"comment on exported function `NewMetrics` should be of the form `NewMetrics ...`"},
26-
{"cannot use addr (variable of type string) as github.com/iotexproject/iotex-core/pkg/keypair.PublicKey value in argument to action.FakeSeal",
27-
"cannot use addr (variable of type `string`) as `github.com/iotexproject/iotex-core/pkg/keypair.PublicKey` value in argument to `action.FakeSeal`"},
26+
{
27+
"exported type Metrics should have comment or be unexported",
28+
"exported type `Metrics` should have comment or be unexported",
29+
},
30+
{
31+
`comment on exported function NewMetrics should be of the form "NewMetrics ..."`,
32+
"comment on exported function `NewMetrics` should be of the form `NewMetrics ...`",
33+
},
34+
{
35+
"cannot use addr (variable of type string) as github.com/iotexproject/iotex-core/pkg/keypair.PublicKey value in argument to action.FakeSeal",
36+
"cannot use addr (variable of type `string`) as `github.com/iotexproject/iotex-core/pkg/keypair.PublicKey` value in argument to `action.FakeSeal`",
37+
},
2838
{"other declaration of out", "other declaration of `out`"},
2939
{"should check returned error before deferring response.Close()", "should check returned error before deferring `response.Close()`"},
3040
{"should use time.Since instead of time.Now().Sub", "should use `time.Since` instead of `time.Now().Sub`"},
3141
{"TestFibZeroCount redeclared in this block", "`TestFibZeroCount` redeclared in this block"},
3242
{"should replace i += 1 with i++", "should replace `i += 1` with `i++`"},
3343
{"createEntry - result err is always nil", "`createEntry` - result `err` is always `nil`"},
34-
{"should omit comparison to bool constant, can be simplified to !projectIntegration.Model.Storage",
35-
"should omit comparison to bool constant, can be simplified to `!projectIntegration.Model.Storage`"},
36-
{"if block ends with a return statement, so drop this else and outdent its block",
37-
"`if` block ends with a `return` statement, so drop this `else` and outdent its block"},
38-
{"should write pupData := ms.m[pupID] instead of pupData, _ := ms.m[pupID]",
39-
"should write `pupData := ms.m[pupID]` instead of `pupData, _ := ms.m[pupID]`"},
44+
{
45+
"should omit comparison to bool constant, can be simplified to !projectIntegration.Model.Storage",
46+
"should omit comparison to bool constant, can be simplified to `!projectIntegration.Model.Storage`",
47+
},
48+
{
49+
"if block ends with a return statement, so drop this else and outdent its block",
50+
"`if` block ends with a `return` statement, so drop this `else` and outdent its block",
51+
},
52+
{
53+
"should write pupData := ms.m[pupID] instead of pupData, _ := ms.m[pupID]",
54+
"should write `pupData := ms.m[pupID]` instead of `pupData, _ := ms.m[pupID]`",
55+
},
4056
{"no value of type uint is less than 0", "no value of type `uint` is less than `0`"},
4157
{"redundant return statement", "redundant `return` statement"},
4258
{"struct field Id should be ID", "struct field `Id` should be `ID`"},
43-
{"don't use underscores in Go names; var Go_lint should be GoLint",
44-
"don't use underscores in Go names; var `Go_lint` should be `GoLint`"},
45-
{"G501: Blacklisted import crypto/md5: weak cryptographic primitive",
46-
"G501: Blacklisted import `crypto/md5`: weak cryptographic primitive"},
47-
{"S1017: should replace this if statement with an unconditional strings.TrimPrefix",
48-
"S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix`"},
59+
{
60+
"don't use underscores in Go names; var Go_lint should be GoLint",
61+
"don't use underscores in Go names; var `Go_lint` should be `GoLint`",
62+
},
63+
{
64+
"G501: Blacklisted import crypto/md5: weak cryptographic primitive",
65+
"G501: Blacklisted import `crypto/md5`: weak cryptographic primitive",
66+
},
67+
{
68+
"S1017: should replace this if statement with an unconditional strings.TrimPrefix",
69+
"S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix`",
70+
},
4971
}
5072
p := NewIdentifierMarker()
5173

pkg/result/processors/max_per_file_from_linter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"github.com/golangci/golangci-lint/pkg/result"
66
)
77

8-
type linterToCountMap map[string]int
9-
type fileToLinterToCountMap map[string]linterToCountMap
8+
type (
9+
linterToCountMap map[string]int
10+
fileToLinterToCountMap map[string]linterToCountMap
11+
)
1012

1113
type MaxPerFileFromLinter struct {
1214
flc fileToLinterToCountMap

pkg/result/processors/nolint.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"github.com/golangci/golangci-lint/pkg/result"
1919
)
2020

21-
var nolintDebugf = logutils.Debug(logutils.DebugKeyNolint)
22-
var nolintRe = regexp.MustCompile(`^nolint( |:|$)`)
21+
var (
22+
nolintDebugf = logutils.Debug(logutils.DebugKeyNolint)
23+
nolintRe = regexp.MustCompile(`^nolint( |:|$)`)
24+
)
2325

2426
type ignoredRange struct {
2527
linters []string

pkg/result/processors/nolint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func TestNolintAliases(t *testing.T) {
192192
}
193193

194194
func TestIgnoredRangeMatches(t *testing.T) {
195-
var testcases = []struct {
195+
testcases := []struct {
196196
doc string
197197
issue result.Issue
198198
linters []string

pkg/result/processors/uniq_by_line.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"github.com/golangci/golangci-lint/pkg/result"
66
)
77

8-
type lineToCount map[int]int
9-
type fileToLineToCount map[string]lineToCount
8+
type (
9+
lineToCount map[int]int
10+
fileToLineToCount map[string]lineToCount
11+
)
1012

1113
type UniqByLine struct {
1214
flc fileToLineToCount

0 commit comments

Comments
 (0)