feat: deprecate usage of linter alternative names (#4562)
This commit is contained in:
parent
ed205573c0
commit
5a9f5c1f13
@ -128,8 +128,8 @@ index 0000000..6399915
|
||||
+// line
|
||||
`
|
||||
|
||||
log := logutils.NewMockLog()
|
||||
log.On("Infof", "The diff contains only additions: no original or deleted lines: %#v", mock.Anything)
|
||||
log := logutils.NewMockLog().
|
||||
OnInfof("The diff contains only additions: no original or deleted lines: %#v", mock.Anything)
|
||||
|
||||
var noChanges []Change
|
||||
testDiffProducesChanges(t, log, diff, noChanges...)
|
||||
|
@ -3,10 +3,12 @@ package lintersdb
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
)
|
||||
|
||||
type Validator struct {
|
||||
@ -28,6 +30,7 @@ func (v Validator) Validate(cfg *config.Config) error {
|
||||
validators := []func(cfg *config.Linters) error{
|
||||
v.validateLintersNames,
|
||||
v.validatePresets,
|
||||
v.alternativeNamesDeprecation,
|
||||
}
|
||||
|
||||
for _, v := range validators {
|
||||
@ -40,7 +43,7 @@ func (v Validator) Validate(cfg *config.Config) error {
|
||||
}
|
||||
|
||||
func (v Validator) validateLintersNames(cfg *config.Linters) error {
|
||||
allNames := append([]string{}, cfg.Enable...)
|
||||
allNames := cfg.Enable
|
||||
allNames = append(allNames, cfg.Disable...)
|
||||
|
||||
var unknownNames []string
|
||||
@ -75,3 +78,34 @@ func (v Validator) validatePresets(cfg *config.Linters) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v Validator) alternativeNamesDeprecation(cfg *config.Linters) error {
|
||||
if v.m.cfg.InternalTest || v.m.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
|
||||
return nil
|
||||
}
|
||||
|
||||
altNames := map[string][]string{}
|
||||
for _, lc := range v.m.GetAllSupportedLinterConfigs() {
|
||||
for _, alt := range lc.AlternativeNames {
|
||||
altNames[alt] = append(altNames[alt], lc.Name())
|
||||
}
|
||||
}
|
||||
|
||||
names := cfg.Enable
|
||||
names = append(names, cfg.Disable...)
|
||||
|
||||
for _, name := range names {
|
||||
lc, ok := altNames[name]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(lc) > 1 {
|
||||
v.m.log.Warnf("The linter named %q is deprecated. It has been split into: %s.", name, strings.Join(lc, ", "))
|
||||
} else {
|
||||
v.m.log.Warnf("The name %q is deprecated. The linter has been renamed to: %s.", name, lc[0])
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
)
|
||||
|
||||
type validateErrorTestCase struct {
|
||||
@ -215,3 +216,27 @@ func TestValidator_validatePresets_error(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidator_alternativeNamesDeprecation(t *testing.T) {
|
||||
t.Setenv(logutils.EnvTestRun, "0")
|
||||
|
||||
log := logutils.NewMockLog().
|
||||
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "vet", "govet").
|
||||
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "vetshadow", "govet").
|
||||
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "logrlint", "loggercheck").
|
||||
OnWarnf("The linter named %q is deprecated. It has been split into: %s.", "megacheck", "gosimple, staticcheck, unused").
|
||||
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "gas", "gosec")
|
||||
|
||||
m, err := NewManager(log, nil, NewLinterBuilder())
|
||||
require.NoError(t, err)
|
||||
|
||||
v := NewValidator(m)
|
||||
|
||||
cfg := &config.Linters{
|
||||
Enable: []string{"vet", "vetshadow", "logrlint"},
|
||||
Disable: []string{"megacheck", "gas"},
|
||||
}
|
||||
|
||||
err = v.alternativeNamesDeprecation(cfg)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
@ -13,28 +13,23 @@ func NewMockLog() *MockLog {
|
||||
}
|
||||
|
||||
func (m *MockLog) Fatalf(format string, args ...any) {
|
||||
mArgs := []any{format}
|
||||
m.Called(append(mArgs, args...)...)
|
||||
m.Called(append([]any{format}, args...)...)
|
||||
}
|
||||
|
||||
func (m *MockLog) Panicf(format string, args ...any) {
|
||||
mArgs := []any{format}
|
||||
m.Called(append(mArgs, args...)...)
|
||||
m.Called(append([]any{format}, args...)...)
|
||||
}
|
||||
|
||||
func (m *MockLog) Errorf(format string, args ...any) {
|
||||
mArgs := []any{format}
|
||||
m.Called(append(mArgs, args...)...)
|
||||
m.Called(append([]any{format}, args...)...)
|
||||
}
|
||||
|
||||
func (m *MockLog) Warnf(format string, args ...any) {
|
||||
mArgs := []any{format}
|
||||
m.Called(append(mArgs, args...)...)
|
||||
m.Called(append([]any{format}, args...)...)
|
||||
}
|
||||
|
||||
func (m *MockLog) Infof(format string, args ...any) {
|
||||
mArgs := []any{format}
|
||||
m.Called(append(mArgs, args...)...)
|
||||
m.Called(append([]any{format}, args...)...)
|
||||
}
|
||||
|
||||
func (m *MockLog) Child(name string) Log {
|
||||
@ -45,3 +40,43 @@ func (m *MockLog) Child(name string) Log {
|
||||
func (m *MockLog) SetLevel(level LogLevel) {
|
||||
m.Called(level)
|
||||
}
|
||||
|
||||
func (m *MockLog) OnFatalf(format string, args ...any) *MockLog {
|
||||
arguments := append([]any{format}, args...)
|
||||
|
||||
m.On("Fatalf", arguments...)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockLog) OnPanicf(format string, args ...any) *MockLog {
|
||||
arguments := append([]any{format}, args...)
|
||||
|
||||
m.On("Panicf", arguments...)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockLog) OnErrorf(format string, args ...any) *MockLog {
|
||||
arguments := append([]any{format}, args...)
|
||||
|
||||
m.On("Errorf", arguments...)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockLog) OnWarnf(format string, args ...any) *MockLog {
|
||||
arguments := append([]any{format}, args...)
|
||||
|
||||
m.On("Warnf", arguments...)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockLog) OnInfof(format string, args ...any) *MockLog {
|
||||
arguments := append([]any{format}, args...)
|
||||
|
||||
m.On("Infof", arguments...)
|
||||
|
||||
return m
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user