Skip to content

Commit aa3550a

Browse files
authored
fix: reduce flaky in the CI and clean the .golangci.yml of the project (#2359)
* fix: clean linter configuration * fix: minor changes * fix: increase timeout
1 parent 99c6516 commit aa3550a

File tree

8 files changed

+12
-24
lines changed

8 files changed

+12
-24
lines changed

.golangci.yml

+5-15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ linters-settings:
3939
mnd:
4040
# don't include the "operation" and "assign"
4141
checks: argument,case,condition,return
42+
ignored-numbers: 0,1,2,3
43+
ignored-functions: strings.SplitN
44+
4245
govet:
4346
check-shadowing: true
4447
settings:
@@ -115,9 +118,6 @@ linters:
115118
# - wsl
116119

117120
issues:
118-
exclude:
119-
# disable this rule for go1.15 compatibility
120-
- 'ioutilDeprecated:'
121121
# Excluding configuration per-path, per-linter, per-text and per-source
122122
exclude-rules:
123123
- path: _test\.go
@@ -128,21 +128,11 @@ issues:
128128
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
129129
- path: pkg/commands/run.go
130130
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
131-
132-
# TODO must be removed after the release of the next version (v1.41.0)
133131
- path: pkg/commands/run.go
134-
linters:
135-
- gomnd
136-
# TODO must be removed after the release of the next version (v1.41.0)
137-
- path: pkg/golinters/nolintlint/nolintlint.go
138-
linters:
139-
- gomnd
140-
# TODO must be removed after the release of the next version (v1.41.0)
141-
- path: pkg/printers/tab.go
142-
linters:
143-
- gomnd
132+
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."
144133

145134
run:
135+
timeout: 5m
146136
skip-dirs:
147137
- test/testdata_etc
148138
- internal/cache

pkg/commands/run.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func wh(text string) string {
5353

5454
const defaultTimeout = time.Minute
5555

56-
//nolint:funlen
56+
//nolint:funlen,gomnd
5757
func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, isFinalInit bool) {
5858
hideFlag := func(name string) {
5959
if err := fs.MarkHidden(name); err != nil {
@@ -479,7 +479,6 @@ func (e *Executor) executeRun(_ *cobra.Command, args []string) {
479479

480480
// to be removed when deadline is finally decommissioned
481481
func (e *Executor) setTimeoutToDeadlineIfOnlyDeadlineIsSet() {
482-
// nolint:staticcheck
483482
deadlineValue := e.cfg.Run.Deadline
484483
if deadlineValue != 0 && e.cfg.Run.Timeout == defaultTimeout {
485484
e.cfg.Run.Timeout = deadlineValue
@@ -497,7 +496,7 @@ func (e *Executor) setupExitCode(ctx context.Context) {
497496
return
498497
}
499498

500-
needFailOnWarnings := (os.Getenv("GL_TEST_RUN") == "1" || os.Getenv("FAIL_ON_WARNINGS") == "1")
499+
needFailOnWarnings := os.Getenv("GL_TEST_RUN") == "1" || os.Getenv("FAIL_ON_WARNINGS") == "1"
501500
if needFailOnWarnings && len(e.reportData.Warnings) != 0 {
502501
e.exitCode = exitcodes.WarningInTest
503502
return

pkg/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Config struct {
1717
InternalTest bool // Option is used only for testing golangci-lint code, don't use it
1818
}
1919

20-
// getConfigDir returns the directory that contains golangci config file.
20+
// GetConfigDir returns the directory that contains golangci config file.
2121
func (c *Config) GetConfigDir() string {
2222
return c.cfgDir
2323
}

pkg/golinters/gocritic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ func configureCheckerInfo(
119119
// but the file parsers (TOML, YAML, JSON) don't create the same representation for raw type.
120120
// then we have to convert value types into the expected value types.
121121
// Maybe in the future, this kind of conversion will be done in go-critic itself.
122-
//nolint:exhaustive // only 3 types (int, bool, and string) are supported by CheckerParam.Value
123122
func normalizeCheckerParamsValue(lintCtx *linter.Context, p interface{}) interface{} {
124123
rv := reflect.ValueOf(p)
124+
//nolint:exhaustive // only 3 types (int, bool, and string) are supported by CheckerParam.Value
125125
switch rv.Type().Kind() {
126126
case reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int:
127127
return int(rv.Int())

pkg/lint/lintersdb/validator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (v Validator) validateLintersNames(cfg *config.Linters) error {
2121
allNames := append([]string{}, cfg.Enable...)
2222
allNames = append(allNames, cfg.Disable...)
2323

24-
unknownNames := []string{}
24+
var unknownNames []string
2525

2626
for _, name := range allNames {
2727
if v.m.GetLinterConfigs(name) == nil {

pkg/packages/errors.go

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/pkg/errors"
1010
)
1111

12-
//nolint:gomnd
1312
func ParseErrorPosition(pos string) (*token.Position, error) {
1413
// file:line(<optional>:colon)
1514
parts := strings.Split(pos, ":")

pkg/timeutils/stopwatch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (s *Stopwatch) sprintTopStages(n int) string {
7171

7272
stageDurations := s.stageDurationsSorted()
7373

74-
stagesStrings := []string{}
74+
var stagesStrings []string
7575
for i := 0; i < len(stageDurations) && i < n; i++ {
7676
s := stageDurations[i]
7777
stagesStrings = append(stagesStrings, fmt.Sprintf("%s: %s", s.name, s.d))

test/bench/bench_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func printCommand(cmd string, args ...string) {
7171
if os.Getenv("PRINT_CMD") != "1" {
7272
return
7373
}
74-
quotedArgs := []string{}
74+
var quotedArgs []string
7575
for _, a := range args {
7676
quotedArgs = append(quotedArgs, strconv.Quote(a))
7777
}

0 commit comments

Comments
 (0)