Skip to content

Commit 3f6f904

Browse files
authored
fix: improve staticcheck migration (#5545)
1 parent 61884c8 commit 3f6f904

11 files changed

+86
-2
lines changed

pkg/commands/internal/migrate/migrate_linter_names.go

+21
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,27 @@ func convertStaticcheckLinterNames(names []string) []string {
885885
return Unique(results)
886886
}
887887

888+
func convertDisabledStaticcheckLinterNames(names []string) []string {
889+
removeStaticcheck := slices.Contains(names, "staticcheck") && slices.Contains(names, "stylecheck") && slices.Contains(names, "gosimple")
890+
891+
var results []string
892+
893+
for _, name := range names {
894+
if removeStaticcheck && slices.Contains([]string{"stylecheck", "gosimple", "staticcheck"}, name) {
895+
results = append(results, "staticcheck")
896+
continue
897+
}
898+
899+
if slices.Contains([]string{"stylecheck", "gosimple"}, name) {
900+
continue
901+
}
902+
903+
results = append(results, name)
904+
}
905+
906+
return Unique(results)
907+
}
908+
888909
func onlyLinterNames(names []string) []string {
889910
formatters := []string{"gci", "gofmt", "gofumpt", "goimports"}
890911

pkg/commands/internal/migrate/migrate_linters.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func toLinters(old *versionone.Config) versiontwo.Linters {
1212
return versiontwo.Linters{
1313
Default: getDefaultName(old.Linters),
1414
Enable: onlyLinterNames(convertStaticcheckLinterNames(enable)),
15-
Disable: onlyLinterNames(convertStaticcheckLinterNames(disable)),
15+
Disable: onlyLinterNames(convertDisabledStaticcheckLinterNames(disable)),
1616
FastOnly: nil,
1717
Settings: toLinterSettings(old.LintersSettings),
1818
Exclusions: toExclusions(old),

pkg/commands/internal/migrate/testdata/yaml/linters_09.golden.yml

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ linters:
4343
- mnd
4444
- mycustomlinter3
4545
- mycustomlinter4
46-
- staticcheck
4746
formatters:
4847
enable:
4948
- gofmt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version: "2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
issues:
2+
# Only to not generate unrelated elements inside golden.
3+
exclude-use-default: false
4+
# Only to not generate unrelated elements inside golden.
5+
exclude-generated: strict
6+
# Only to not generate unrelated elements inside golden.
7+
exclude-dirs-use-default: false
8+
9+
linters:
10+
enable:
11+
- staticcheck
12+
disable:
13+
- stylecheck
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "2"
2+
linters:
3+
default: all
4+
formatters:
5+
enable:
6+
- gci
7+
- gofmt
8+
- gofumpt
9+
- goimports
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
issues:
2+
# Only to not generate unrelated elements inside golden.
3+
exclude-use-default: false
4+
# Only to not generate unrelated elements inside golden.
5+
exclude-generated: strict
6+
# Only to not generate unrelated elements inside golden.
7+
exclude-dirs-use-default: false
8+
9+
linters:
10+
enable-all: true
11+
disable:
12+
- gosimple
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version: "2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
issues:
2+
# Only to not generate unrelated elements inside golden.
3+
exclude-use-default: false
4+
# Only to not generate unrelated elements inside golden.
5+
exclude-generated: strict
6+
# Only to not generate unrelated elements inside golden.
7+
exclude-dirs-use-default: false
8+
9+
linters:
10+
disable:
11+
- stylecheck
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: "2"
2+
linters:
3+
disable:
4+
- staticcheck
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
issues:
2+
# Only to not generate unrelated elements inside golden.
3+
exclude-use-default: false
4+
# Only to not generate unrelated elements inside golden.
5+
exclude-generated: strict
6+
# Only to not generate unrelated elements inside golden.
7+
exclude-dirs-use-default: false
8+
9+
linters:
10+
disable:
11+
- staticcheck
12+
- stylecheck
13+
- gosimple

0 commit comments

Comments
 (0)