Skip to content

Commit e43d1f7

Browse files
committed
feat: deprecate usage of linter alternative names
1 parent 878e02f commit e43d1f7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

pkg/lint/lintersdb/validator.go

+35
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package lintersdb
33
import (
44
"errors"
55
"fmt"
6+
"os"
67
"slices"
78
"strings"
89

910
"github.com/golangci/golangci-lint/pkg/config"
11+
"github.com/golangci/golangci-lint/pkg/logutils"
1012
)
1113

1214
type Validator struct {
@@ -28,6 +30,7 @@ func (v Validator) Validate(cfg *config.Config) error {
2830
validators := []func(cfg *config.Linters) error{
2931
v.validateLintersNames,
3032
v.validatePresets,
33+
v.alternativeNamesDeprecation,
3134
}
3235

3336
for _, v := range validators {
@@ -75,3 +78,35 @@ func (v Validator) validatePresets(cfg *config.Linters) error {
7578

7679
return nil
7780
}
81+
82+
func (v Validator) alternativeNamesDeprecation(cfg *config.Linters) error {
83+
if v.m.cfg.InternalTest || v.m.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
84+
return nil
85+
}
86+
87+
altNames := map[string][]string{}
88+
for _, lc := range v.m.GetAllSupportedLinterConfigs() {
89+
for _, alt := range lc.AlternativeNames {
90+
altNames[alt] = append(altNames[alt], lc.Name())
91+
}
92+
}
93+
94+
var names []string
95+
names = append(names, cfg.Enable...)
96+
names = append(names, cfg.Disable...)
97+
98+
for _, name := range names {
99+
lc, ok := altNames[name]
100+
if !ok {
101+
continue
102+
}
103+
104+
if len(lc) > 1 {
105+
v.m.log.Warnf("The linter name %q is deprecated. It has been splited into: %s.", name, strings.Join(lc, ", "))
106+
} else {
107+
v.m.log.Warnf("The linter name %q is deprecated. It has been renamed to: %s.", name, lc[0])
108+
}
109+
}
110+
111+
return nil
112+
}

pkg/lint/lintersdb/validator_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/stretchr/testify/require"
77

88
"github.com/golangci/golangci-lint/pkg/config"
9+
"github.com/golangci/golangci-lint/pkg/logutils"
910
)
1011

1112
type validateErrorTestCase struct {
@@ -215,3 +216,25 @@ func TestValidator_validatePresets_error(t *testing.T) {
215216
})
216217
}
217218
}
219+
220+
func TestValidator_alternativeNamesDeprecation(t *testing.T) {
221+
log := logutils.NewMockLog()
222+
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "vet", "govet")
223+
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "vetshadow", "govet")
224+
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "logrlint", "loggercheck")
225+
log.On("Warnf", "The linter name %q is deprecated. It has been splited into: %s.", "megacheck", "gosimple, staticcheck, unused")
226+
log.On("Warnf", "The linter name %q is deprecated. It has been renamed to: %s.", "gas", "gosec")
227+
228+
m, err := NewManager(log, nil, NewLinterBuilder())
229+
require.NoError(t, err)
230+
231+
v := NewValidator(m)
232+
233+
cfg := &config.Linters{
234+
Enable: []string{"vet", "vetshadow", "logrlint"},
235+
Disable: []string{"megacheck", "gas"},
236+
}
237+
238+
err = v.alternativeNamesDeprecation(cfg)
239+
require.NoError(t, err)
240+
}

0 commit comments

Comments
 (0)