Skip to content

Commit

Permalink
fix: reduce flaky in the CI and clean the .golangci.yml of the project (
Browse files Browse the repository at this point in the history
golangci#2359)

* fix: clean linter configuration
* fix: minor changes
* fix: increase timeout
  • Loading branch information
ldez authored and SeigeC committed Apr 4, 2023
1 parent 2028ddc commit cfc052f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 24 deletions.
20 changes: 5 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ linters-settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
ignored-numbers: 0,1,2,3
ignored-functions: strings.SplitN

govet:
check-shadowing: true
settings:
Expand Down Expand Up @@ -115,9 +118,6 @@ linters:
# - wsl

issues:
exclude:
# disable this rule for go1.15 compatibility
- 'ioutilDeprecated:'
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
Expand All @@ -128,21 +128,11 @@ issues:
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"

# TODO must be removed after the release of the next version (v1.41.0)
- path: pkg/commands/run.go
linters:
- gomnd
# TODO must be removed after the release of the next version (v1.41.0)
- path: pkg/golinters/nolintlint/nolintlint.go
linters:
- gomnd
# TODO must be removed after the release of the next version (v1.41.0)
- path: pkg/printers/tab.go
linters:
- gomnd
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."

run:
timeout: 5m
skip-dirs:
- test/testdata_etc
- internal/cache
Expand Down
5 changes: 2 additions & 3 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func wh(text string) string {

const defaultTimeout = time.Minute

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

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

needFailOnWarnings := (os.Getenv("GL_TEST_RUN") == "1" || os.Getenv("FAIL_ON_WARNINGS") == "1")
needFailOnWarnings := os.Getenv("GL_TEST_RUN") == "1" || os.Getenv("FAIL_ON_WARNINGS") == "1"
if needFailOnWarnings && len(e.reportData.Warnings) != 0 {
e.exitCode = exitcodes.WarningInTest
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Config struct {
InternalTest bool // Option is used only for testing golangci-lint code, don't use it
}

// getConfigDir returns the directory that contains golangci config file.
// GetConfigDir returns the directory that contains golangci config file.
func (c *Config) GetConfigDir() string {
return c.cfgDir
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gocritic.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func configureCheckerInfo(
// but the file parsers (TOML, YAML, JSON) don't create the same representation for raw type.
// then we have to convert value types into the expected value types.
// Maybe in the future, this kind of conversion will be done in go-critic itself.
//nolint:exhaustive // only 3 types (int, bool, and string) are supported by CheckerParam.Value
func normalizeCheckerParamsValue(lintCtx *linter.Context, p interface{}) interface{} {
rv := reflect.ValueOf(p)
//nolint:exhaustive // only 3 types (int, bool, and string) are supported by CheckerParam.Value
switch rv.Type().Kind() {
case reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8, reflect.Int:
return int(rv.Int())
Expand Down
2 changes: 1 addition & 1 deletion pkg/lint/lintersdb/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (v Validator) validateLintersNames(cfg *config.Linters) error {
allNames := append([]string{}, cfg.Enable...)
allNames = append(allNames, cfg.Disable...)

unknownNames := []string{}
var unknownNames []string

for _, name := range allNames {
if v.m.GetLinterConfigs(name) == nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/packages/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/pkg/errors"
)

//nolint:gomnd
func ParseErrorPosition(pos string) (*token.Position, error) {
// file:line(<optional>:colon)
parts := strings.Split(pos, ":")
Expand Down
2 changes: 1 addition & 1 deletion pkg/timeutils/stopwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *Stopwatch) sprintTopStages(n int) string {

stageDurations := s.stageDurationsSorted()

stagesStrings := []string{}
var stagesStrings []string
for i := 0; i < len(stageDurations) && i < n; i++ {
s := stageDurations[i]
stagesStrings = append(stagesStrings, fmt.Sprintf("%s: %s", s.name, s.d))
Expand Down
2 changes: 1 addition & 1 deletion test/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func printCommand(cmd string, args ...string) {
if os.Getenv("PRINT_CMD") != "1" {
return
}
quotedArgs := []string{}
var quotedArgs []string
for _, a := range args {
quotedArgs = append(quotedArgs, strconv.Quote(a))
}
Expand Down

0 comments on commit cfc052f

Please sign in to comment.