Skip to content

Commit d7d4986

Browse files
committed
fix: add a missing linter names migration case
1 parent ca11e3e commit d7d4986

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

pkg/commands/internal/migrate/migrate_linter_names.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ func ProcessEffectiveLinters(old one.Linters) (enable, disable []string) {
4646

4747
// disableAllFilter generates the value of `enable` when `disable-all` is `true`.
4848
func disableAllFilter(old one.Linters) []string {
49+
// Note:
50+
// - disable-all + enable-all
51+
// => impossible (https://github.com/golangci/golangci-lint/blob/e1eb4cb2c7fba29b5831b63e454844d83c692874/pkg/config/linters.go#L38)
52+
// - disable-all + disable
53+
// => impossible (https://github.com/golangci/golangci-lint/blob/e1eb4cb2c7fba29b5831b63e454844d83c692874/pkg/config/linters.go#L47)
54+
4955
// if disable-all -> presets fast enable
5056
// - presets fast enable: (presets - [slow]) + enable => effective enable + none
5157
// - presets fast: presets - slow => effective enable + none
@@ -69,19 +75,31 @@ func disableAllFilter(old one.Linters) []string {
6975

7076
// enableAllFilter generates the value of `disable` when `enable-all` is `true`.
7177
func enableAllFilter(old one.Linters) []string {
72-
// if enable-all -> presets fast disable
78+
// Note:
79+
// - enable-all + disable-all
80+
// => impossible (https://github.com/golangci/golangci-lint/blob/e1eb4cb2c7fba29b5831b63e454844d83c692874/pkg/config/linters.go#L38)
81+
// - enable-all + enable + fast=false
82+
// => impossible (https://github.com/golangci/golangci-lint/blob/e1eb4cb2c7fba29b5831b63e454844d83c692874/pkg/config/linters.go#L52)
83+
// - enable-all + enable + fast=true
84+
// => possible (https://github.com/golangci/golangci-lint/blob/e1eb4cb2c7fba29b5831b63e454844d83c692874/pkg/config/linters.go#L51)
85+
86+
// if enable-all -> presets fast enable disable
87+
// - presets fast enable disable: all - fast - enable + disable => effective disable + all
7388
// - presets fast disable: all - fast + disable => effective disable + all
7489
// - presets fast: all - fast => effective disable + all
7590
// - presets disable: disable => effective disable + all
7691
// - disable => effective disable + all
7792
// - fast: all - fast => effective disable + all
7893
// - fast disable: all - fast + disable => effective disable + all
7994

80-
// all - [fast] + disable => effective disable + all
95+
// all - [fast] - enable + disable => effective disable + all
8196
names := toNames(
8297
slices.Concat(
83-
filter(
84-
allLinters(), keepSlow(old), // all - fast
98+
removeLinters(
99+
filter(
100+
allLinters(), keepSlow(old), // all - fast
101+
),
102+
allEnabled(old, allLinters()), // - enable
85103
),
86104
allDisabled(old, allLinters()), // + disable
87105
),
@@ -92,6 +110,10 @@ func enableAllFilter(old one.Linters) []string {
92110

93111
// defaultLintersFilter generates the values of `enable` and `disable` when using default linters.
94112
func defaultLintersFilter(old one.Linters) (enable, disable []string) {
113+
// Note:
114+
// - a linter cannot be inside `enable` and `disable` in the same configuration
115+
// => https://github.com/golangci/golangci-lint/blob/e1eb4cb2c7fba29b5831b63e454844d83c692874/pkg/config/linters.go#L66
116+
95117
// if default -> presets fast disable
96118
// - presets > fast > disable > enable => effective enable + disable + standard
97119
// - (default - fast) - enable + disable => effective disable

pkg/commands/internal/migrate/migrate_linter_names_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ func Test_enableAllFilter(t *testing.T) {
170170
},
171171
expected: []string{"asasalint", "bodyclose", "canonicalheader", "containedctx", "contextcheck", "durationcheck", "err113", "errcheck", "errchkjson", "errname", "errorlint", "exhaustive", "exhaustruct", "exptostd", "fatcontext", "forbidigo", "forcetypeassert", "ginkgolinter", "gochecknoglobals", "gochecksumtype", "gocritic", "gosec", "gosimple", "gosmopolitan", "govet", "iface", "importas", "intrange", "ireturn", "lll", "loggercheck", "makezero", "mirror", "misspell", "musttag", "nilerr", "nilnesserr", "nilnil", "noctx", "nonamedreturns", "paralleltest", "perfsprint", "protogetter", "reassign", "recvcheck", "revive", "rowserrcheck", "sloglint", "spancheck", "sqlclosecheck", "staticcheck", "stylecheck", "tagliatelle", "tenv", "testifylint", "thelper", "tparallel", "unconvert", "unparam", "unused", "usetesting", "varnamelen", "wastedassign", "wrapcheck", "zerologlint"},
172172
},
173+
{
174+
desc: "disable, enable, fast",
175+
old: one.Linters{
176+
EnableAll: ptr.Pointer(true),
177+
Enable: []string{"canonicalheader", "errname"},
178+
Disable: []string{"lll", "misspell", "govet"},
179+
Fast: ptr.Pointer(true),
180+
Presets: nil,
181+
},
182+
expected: []string{"asasalint", "bodyclose", "containedctx", "contextcheck", "durationcheck", "err113", "errcheck", "errchkjson", "errorlint", "exhaustive", "exhaustruct", "exptostd", "fatcontext", "forbidigo", "forcetypeassert", "ginkgolinter", "gochecknoglobals", "gochecksumtype", "gocritic", "gosec", "gosimple", "gosmopolitan", "govet", "iface", "importas", "intrange", "ireturn", "lll", "loggercheck", "makezero", "mirror", "misspell", "musttag", "nilerr", "nilnesserr", "nilnil", "noctx", "nonamedreturns", "paralleltest", "perfsprint", "protogetter", "reassign", "recvcheck", "revive", "rowserrcheck", "sloglint", "spancheck", "sqlclosecheck", "staticcheck", "stylecheck", "tagliatelle", "tenv", "testifylint", "thelper", "tparallel", "unconvert", "unparam", "unused", "usetesting", "varnamelen", "wastedassign", "wrapcheck", "zerologlint"},
183+
},
173184
}
174185

175186
for _, test := range testCases {

0 commit comments

Comments
 (0)