Skip to content

Commit 7b4cc6a

Browse files
committed
dev: update global migration command
1 parent 40d6afb commit 7b4cc6a

12 files changed

+70
-46
lines changed

pkg/commands/internal/migrate/migrate_linter_names.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,9 @@ func allLinters() []LinterInfo {
712712
Slow: true,
713713
},
714714
{
715-
Name: "wsl",
716-
Presets: []string{"style"},
715+
Name: "wsl_v5",
716+
Presets: []string{"style"},
717+
AlternativeNames: []string{"wsl"}, // Fake alternative name.
717718
},
718719
{
719720
Name: "zerologlint",
@@ -937,6 +938,10 @@ func convertAlternativeNames(names []string) []string {
937938
"megacheck": "staticcheck",
938939
"vet": "govet",
939940
"vetshadow": "govet",
941+
942+
// Not an alternative name but a new linter major version,
943+
// but it can be handled in the same way.
944+
"wsl": "wsl_v5",
940945
}
941946

942947
var results []string

pkg/commands/internal/migrate/migrate_linters_settings.go

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"slices"
55
"strings"
66

7+
wslv5 "github.com/bombsimon/wsl/v5"
8+
79
"github.com/golangci/golangci-lint/v2/pkg/commands/internal/migrate/ptr"
810
"github.com/golangci/golangci-lint/v2/pkg/commands/internal/migrate/versionone"
911
"github.com/golangci/golangci-lint/v2/pkg/commands/internal/migrate/versiontwo"
@@ -87,7 +89,7 @@ func toLinterSettings(old versionone.LintersSettings) versiontwo.LintersSettings
8789
Varnamelen: toVarnamelenSettings(old.Varnamelen),
8890
Whitespace: toWhitespaceSettings(old.Whitespace),
8991
Wrapcheck: toWrapcheckSettings(old.Wrapcheck),
90-
WSL: toWSLSettings(old.WSL),
92+
WSLv5: toWSLSettings(old.WSL),
9193
Custom: toCustom(old.Custom),
9294
}
9395
}
@@ -998,22 +1000,46 @@ func toWrapcheckSettings(old versionone.WrapcheckSettings) versiontwo.WrapcheckS
9981000
}
9991001
}
10001002

1001-
func toWSLSettings(old versionone.WSLSettings) versiontwo.WSLv4Settings {
1002-
return versiontwo.WSLv4Settings{
1003-
StrictAppend: old.StrictAppend,
1004-
AllowAssignAndCallCuddle: old.AllowAssignAndCallCuddle,
1005-
AllowAssignAndAnythingCuddle: old.AllowAssignAndAnythingCuddle,
1006-
AllowMultiLineAssignCuddle: old.AllowMultiLineAssignCuddle,
1007-
ForceCaseTrailingWhitespaceLimit: old.ForceCaseTrailingWhitespaceLimit,
1008-
AllowTrailingComment: old.AllowTrailingComment,
1009-
AllowSeparatedLeadingComment: old.AllowSeparatedLeadingComment,
1010-
AllowCuddleDeclaration: old.AllowCuddleDeclaration,
1011-
AllowCuddleWithCalls: old.AllowCuddleWithCalls,
1012-
AllowCuddleWithRHS: old.AllowCuddleWithRHS,
1013-
ForceCuddleErrCheckAndAssign: old.ForceCuddleErrCheckAndAssign,
1014-
ErrorVariableNames: old.ErrorVariableNames,
1015-
ForceExclusiveShortDeclarations: old.ForceExclusiveShortDeclarations,
1003+
func toWSLSettings(old *versionone.WSLSettings) versiontwo.WSLv5Settings {
1004+
if old == nil {
1005+
return versiontwo.WSLv5Settings{}
1006+
}
1007+
1008+
cfg := versiontwo.WSLv5Settings{
1009+
AllowFirstInBlock: ptr.Pointer(true),
1010+
AllowWholeBlock: ptr.Pointer(false),
1011+
BranchMaxLines: ptr.Pointer(2),
1012+
CaseMaxLines: old.ForceCaseTrailingWhitespaceLimit,
1013+
}
1014+
1015+
if !ptr.Deref(old.StrictAppend) {
1016+
cfg.Disable = append(cfg.Disable, wslv5.CheckAppend.String())
1017+
}
1018+
1019+
if ptr.Deref(old.AllowAssignAndAnythingCuddle) {
1020+
cfg.Disable = append(cfg.Disable, wslv5.CheckAssign.String())
1021+
}
1022+
1023+
if ptr.Deref(old.AllowCuddleDeclaration) {
1024+
cfg.Disable = append(cfg.Disable, wslv5.CheckDecl.String())
1025+
}
1026+
1027+
if ptr.Deref(old.ForceCuddleErrCheckAndAssign) {
1028+
cfg.Enable = append(cfg.Enable, wslv5.CheckErr.String())
1029+
}
1030+
1031+
if ptr.Deref(old.ForceExclusiveShortDeclarations) {
1032+
cfg.Enable = append(cfg.Enable, wslv5.CheckAssignExclusive.String())
10161033
}
1034+
1035+
if !ptr.Deref(old.AllowAssignAndCallCuddle) {
1036+
cfg.Enable = append(cfg.Enable, wslv5.CheckAssignExpr.String())
1037+
}
1038+
1039+
slices.Sort(cfg.Enable)
1040+
slices.Sort(cfg.Disable)
1041+
1042+
return cfg
10171043
}
10181044

10191045
func toCustom(old map[string]versionone.CustomLinterSettings) map[string]versiontwo.CustomLinterSettings {

pkg/commands/internal/migrate/testdata/yaml/linters-settings_goconst.golden.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ version: "2"
22
linters:
33
settings:
44
goconst:
5-
ignore-strings: foo.+
65
match-constant: false
76
min-len: 2
87
min-occurrences: 2
98
numbers: true
109
min: 2
1110
max: 2
1211
ignore-calls: false
12+
ignore-strings: foo.+
1313
exclusions:
1414
rules:
1515
- linters:

pkg/commands/internal/migrate/testdata/yaml/linters-settings_nakedret_zero.golden.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: "2"
2-
32
linters:
43
settings:
54
nakedret:
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
version: "2"
22
linters:
33
settings:
4-
wsl:
5-
strict-append: false
6-
allow-assign-and-call: false
7-
allow-assign-and-anything: true
8-
allow-multiline-assign: false
9-
force-case-trailing-whitespace: 1
10-
allow-trailing-comment: true
11-
allow-separated-leading-comment: true
12-
allow-cuddle-declarations: true
13-
allow-cuddle-with-calls:
14-
- Foo
15-
- Bar
16-
allow-cuddle-with-rhs:
17-
- Foo
18-
- Bar
19-
force-err-cuddling: true
20-
error-variable-names:
21-
- foo
22-
force-short-decl-cuddling: true
4+
wsl_v5:
5+
allow-first-in-block: true
6+
allow-whole-block: false
7+
branch-max-lines: 2
8+
case-max-lines: 1
9+
enable:
10+
- assign-exclusive
11+
- assign-expr
12+
- err
13+
disable:
14+
- append
15+
- assign
16+
- decl

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ linters:
105105
- wastedassign
106106
- whitespace
107107
- wrapcheck
108-
- wsl
108+
- wsl_v5
109109
- zerologlint
110110
formatters:
111111
enable:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,5 @@ linters:
105105
- wastedassign
106106
- whitespace
107107
- wrapcheck
108-
- wsl
108+
- wsl_v5
109109
- zerologlint

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ linters:
2020
- wastedassign
2121
- whitespace
2222
- wrapcheck
23-
- wsl
23+
- wsl_v5
2424
- zerologlint
2525
disable:
2626
- asasalint

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ linters:
2222
- wastedassign
2323
- whitespace
2424
- wrapcheck
25-
- wsl
25+
- wsl_v5
2626
- zerologlint
2727
disable:
2828
- asasalint

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ linters:
103103
- wastedassign
104104
- whitespace
105105
- wrapcheck
106-
- wsl
106+
- wsl_v5
107107
- zerologlint
108108
formatters:
109109
enable:

0 commit comments

Comments
 (0)