Skip to content

fix: improve staticcheck migration #5545

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

Merged
merged 1 commit into from
Mar 13, 2025
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
21 changes: 21 additions & 0 deletions pkg/commands/internal/migrate/migrate_linter_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,27 @@ func convertStaticcheckLinterNames(names []string) []string {
return Unique(results)
}

func convertDisabledStaticcheckLinterNames(names []string) []string {
removeStaticcheck := slices.Contains(names, "staticcheck") && slices.Contains(names, "stylecheck") && slices.Contains(names, "gosimple")

var results []string

for _, name := range names {
if removeStaticcheck && slices.Contains([]string{"stylecheck", "gosimple", "staticcheck"}, name) {
results = append(results, "staticcheck")
continue
}

if slices.Contains([]string{"stylecheck", "gosimple"}, name) {
continue
}

results = append(results, name)
}

return Unique(results)
}

func onlyLinterNames(names []string) []string {
formatters := []string{"gci", "gofmt", "gofumpt", "goimports"}

Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/internal/migrate/migrate_linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func toLinters(old *versionone.Config) versiontwo.Linters {
return versiontwo.Linters{
Default: getDefaultName(old.Linters),
Enable: onlyLinterNames(convertStaticcheckLinterNames(enable)),
Disable: onlyLinterNames(convertStaticcheckLinterNames(disable)),
Disable: onlyLinterNames(convertDisabledStaticcheckLinterNames(disable)),
FastOnly: nil,
Settings: toLinterSettings(old.LintersSettings),
Exclusions: toExclusions(old),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ linters:
- mnd
- mycustomlinter3
- mycustomlinter4
- staticcheck
formatters:
enable:
- gofmt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: "2"
13 changes: 13 additions & 0 deletions pkg/commands/internal/migrate/testdata/yaml/linters_13_a.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
issues:
# Only to not generate unrelated elements inside golden.
exclude-use-default: false
# Only to not generate unrelated elements inside golden.
exclude-generated: strict
# Only to not generate unrelated elements inside golden.
exclude-dirs-use-default: false

linters:
enable:
- staticcheck
disable:
- stylecheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "2"
linters:
default: all
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
12 changes: 12 additions & 0 deletions pkg/commands/internal/migrate/testdata/yaml/linters_13_b.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
issues:
# Only to not generate unrelated elements inside golden.
exclude-use-default: false
# Only to not generate unrelated elements inside golden.
exclude-generated: strict
# Only to not generate unrelated elements inside golden.
exclude-dirs-use-default: false

linters:
enable-all: true
disable:
- gosimple
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: "2"
11 changes: 11 additions & 0 deletions pkg/commands/internal/migrate/testdata/yaml/linters_13_c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
issues:
# Only to not generate unrelated elements inside golden.
exclude-use-default: false
# Only to not generate unrelated elements inside golden.
exclude-generated: strict
# Only to not generate unrelated elements inside golden.
exclude-dirs-use-default: false

linters:
disable:
- stylecheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: "2"
linters:
disable:
- staticcheck
13 changes: 13 additions & 0 deletions pkg/commands/internal/migrate/testdata/yaml/linters_13_d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
issues:
# Only to not generate unrelated elements inside golden.
exclude-use-default: false
# Only to not generate unrelated elements inside golden.
exclude-generated: strict
# Only to not generate unrelated elements inside golden.
exclude-dirs-use-default: false

linters:
disable:
- staticcheck
- stylecheck
- gosimple
Loading