From 4640d4f1dd13708bcb0a5a38362d2a89771b7484 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 20 Feb 2025 23:56:42 +0100 Subject: [PATCH 1/2] chore: remove alternative names --- docs/src/docs/product/performance.mdx | 6 +- pkg/golinters/gosec/testdata/gosec.go | 5 -- pkg/golinters/gosimple/testdata/gosimple.go | 8 --- pkg/golinters/govet/testdata/govet.go | 8 --- .../testdata/logrlint_compatiblity.go | 28 -------- .../staticcheck/testdata/staticcheck.go | 5 -- .../testdata/staticcheck_in_megacheck.go | 26 -------- .../stylecheck/testdata/stylecheck.go | 11 ---- .../testdata/stylecheck_not_in_megacheck.go | 10 --- pkg/golinters/unused/testdata/unused.go | 2 - pkg/lint/lintersdb/builder_linter.go | 11 +--- pkg/lint/lintersdb/manager_test.go | 65 ------------------- pkg/lint/lintersdb/validator_test.go | 25 ------- pkg/result/processors/nolint_filter_test.go | 11 ---- .../testdata/nolint_filter/nolint.go | 4 -- test/testdata/withxtest/p_test.go | 2 +- 16 files changed, 5 insertions(+), 222 deletions(-) delete mode 100644 pkg/golinters/loggercheck/testdata/logrlint_compatiblity.go delete mode 100644 pkg/golinters/staticcheck/testdata/staticcheck_in_megacheck.go delete mode 100644 pkg/golinters/stylecheck/testdata/stylecheck_not_in_megacheck.go diff --git a/docs/src/docs/product/performance.mdx b/docs/src/docs/product/performance.mdx index 4863361129ec..790319a6c243 100644 --- a/docs/src/docs/product/performance.mdx +++ b/docs/src/docs/product/performance.mdx @@ -33,7 +33,7 @@ Less `GOGC` values trigger garbage collection more frequently and golangci-lint - build `ssa.Program` once - Some linters (megacheck, interfacer, unparam) work on SSA representation. + Some linters (staticcheck, gosec, unparam) work on SSA representation. Building of this representation takes 1.5 seconds on 8 kLoC repo and 6 seconds on `$GOROOT/src`. - parse source code and build AST once @@ -49,9 +49,9 @@ Less `GOGC` values trigger garbage collection more frequently and golangci-lint 2. Smart linters scheduling We schedule linters by a special algorithm which takes estimated execution time into account. It allows - to save 10-30% of time when one of heavy linters (megacheck etc) is enabled. + to save 10-30% of time when one of heavy linters (staticcheck, etc) is enabled. 3. Don't fork to run shell commands -All linters has their version fixed with go modules, they are builtin +All linters have their version fixed with go modules, they are builtin and you don't need to install them separately. diff --git a/pkg/golinters/gosec/testdata/gosec.go b/pkg/golinters/gosec/testdata/gosec.go index bd984d6cacf0..e2ddf11aafbd 100644 --- a/pkg/golinters/gosec/testdata/gosec.go +++ b/pkg/golinters/gosec/testdata/gosec.go @@ -14,11 +14,6 @@ func Gosec() { log.Print(h) } -func GosecNolintGas() { - h := md5.New() //nolint:gas - log.Print(h) -} - func GosecNolintGosec() { h := md5.New() //nolint:gosec log.Print(h) diff --git a/pkg/golinters/gosimple/testdata/gosimple.go b/pkg/golinters/gosimple/testdata/gosimple.go index 970b1fdc1199..d8d90315ca46 100644 --- a/pkg/golinters/gosimple/testdata/gosimple.go +++ b/pkg/golinters/gosimple/testdata/gosimple.go @@ -20,11 +20,3 @@ func GosimpleNolintGosimple(ss []string) { } } } - -func GosimpleNolintMegacheck(ss []string) { - if ss != nil { //nolint:megacheck - for _, s := range ss { - log.Printf(s) - } - } -} diff --git a/pkg/golinters/govet/testdata/govet.go b/pkg/golinters/govet/testdata/govet.go index 9c0526512f0e..b604694d051c 100644 --- a/pkg/golinters/govet/testdata/govet.go +++ b/pkg/golinters/govet/testdata/govet.go @@ -24,14 +24,6 @@ func GovetShadow(f io.Reader, buf []byte) (err error) { return } -func GovetNolintVet() error { - return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vet -} - -func GovetNolintVetShadow() error { - return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vetshadow -} - func GovetPrintf() { x := "dummy" fmt.Printf("%d", x) // want "printf: fmt.Printf format %d has arg x of wrong type string" diff --git a/pkg/golinters/loggercheck/testdata/logrlint_compatiblity.go b/pkg/golinters/loggercheck/testdata/logrlint_compatiblity.go deleted file mode 100644 index 78bc8d91ee6f..000000000000 --- a/pkg/golinters/loggercheck/testdata/logrlint_compatiblity.go +++ /dev/null @@ -1,28 +0,0 @@ -//golangcitest:args -Elogrlint -package loggercheck - -import ( - "fmt" - - "github.com/go-logr/logr" - "go.uber.org/zap" - "k8s.io/klog/v2" -) - -func ExampleLogrlintLogr() { - log := logr.Discard() - log = log.WithValues("key") // want `odd number of arguments passed as key-value pairs for logging` - log.Info("message", "key1", "value1", "key2", "value2", "key3") // want `odd number of arguments passed as key-value pairs for logging` - log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2") // want `odd number of arguments passed as key-value pairs for logging` - log.Error(fmt.Errorf("error"), "message", "key1", "value1", "key2", "value2") -} - -func ExampleLogrlintKlog() { - klog.InfoS("message", "key1") // want `odd number of arguments passed as key-value pairs for logging` -} - -func ExampleLogrlintZapSugar() { - sugar := zap.NewExample().Sugar() - defer sugar.Sync() - sugar.Infow("message", "key1", "value1", "key2") // want `odd number of arguments passed as key-value pairs for logging` -} diff --git a/pkg/golinters/staticcheck/testdata/staticcheck.go b/pkg/golinters/staticcheck/testdata/staticcheck.go index 2782ce148a2b..f8080f37bc56 100644 --- a/pkg/golinters/staticcheck/testdata/staticcheck.go +++ b/pkg/golinters/staticcheck/testdata/staticcheck.go @@ -16,11 +16,6 @@ func StaticcheckNolintStaticcheck() { x = x //nolint:staticcheck } -func StaticcheckNolintMegacheck() { - var x int - x = x //nolint:megacheck -} - func StaticcheckPrintf() { x := "dummy" fmt.Printf("%d", x) // want "SA5009: Printf format %d has arg #1 of wrong type" diff --git a/pkg/golinters/staticcheck/testdata/staticcheck_in_megacheck.go b/pkg/golinters/staticcheck/testdata/staticcheck_in_megacheck.go deleted file mode 100644 index 355d2a38ac2b..000000000000 --- a/pkg/golinters/staticcheck/testdata/staticcheck_in_megacheck.go +++ /dev/null @@ -1,26 +0,0 @@ -//golangcitest:args -Emegacheck -package testdata - -import "fmt" - -func StaticcheckInMegacheck() { - var x int - x = x // want staticcheck:"self-assignment of x to x" - fmt.Printf("%d", x) -} - -func StaticcheckNolintStaticcheckInMegacheck() { - var x int - x = x //nolint:staticcheck -} - -func StaticcheckNolintMegacheckInMegacheck() { - var x int - x = x //nolint:megacheck -} - -func Staticcheck2() { - var x int - x = x // want staticcheck:"self-assignment of x to x" - fmt.Printf("%d", x) -} diff --git a/pkg/golinters/stylecheck/testdata/stylecheck.go b/pkg/golinters/stylecheck/testdata/stylecheck.go index 07c29e5ae999..6258dc81ab60 100644 --- a/pkg/golinters/stylecheck/testdata/stylecheck.go +++ b/pkg/golinters/stylecheck/testdata/stylecheck.go @@ -23,14 +23,3 @@ func StylecheckNolintStylecheck(x int) { return } } - -func StylecheckNolintMegacheck(x int) { - switch x { - case 1: - return - default: //nolint:megacheck // want "ST1015: default case should be first or last in switch statement" - return - case 2: - return - } -} diff --git a/pkg/golinters/stylecheck/testdata/stylecheck_not_in_megacheck.go b/pkg/golinters/stylecheck/testdata/stylecheck_not_in_megacheck.go deleted file mode 100644 index 1d03aa148f65..000000000000 --- a/pkg/golinters/stylecheck/testdata/stylecheck_not_in_megacheck.go +++ /dev/null @@ -1,10 +0,0 @@ -//golangcitest:args -Emegacheck -//golangcitest:expected_exitcode 0 -// Package testdata ... -package testdata - -func StylecheckNotInMegacheck(x int) { - if 0 == x { - panic(x) - } -} diff --git a/pkg/golinters/unused/testdata/unused.go b/pkg/golinters/unused/testdata/unused.go index d514ea515108..d8b78d1a3109 100644 --- a/pkg/golinters/unused/testdata/unused.go +++ b/pkg/golinters/unused/testdata/unused.go @@ -17,5 +17,3 @@ func fn6() { fn4() } // want "func `fn6` is unused" type unusedStruct struct{} // want "type `unusedStruct` is unused" type unusedStructNolintUnused struct{} //nolint:unused - -type unusedStructNolintMegacheck struct{} //nolint:megacheck diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 46b8e37fe71b..a3a0cdb358a1 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -131,8 +131,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { return nil, nil } - const megacheckName = "megacheck" - // The linters are sorted in the alphabetical order (case-insensitive). // When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint. return []*linter.Config{ @@ -365,7 +363,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.26.0"). WithPresets(linter.PresetStyle, linter.PresetError). WithLoadForGoAnalysis(). - WithAlternativeNames("goerr113"). WithAutoFix(). WithURL("https://github.com/Djarvur/go-err113"), @@ -423,15 +420,13 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetBugs). - WithURL("https://github.com/securego/gosec"). - WithAlternativeNames("gas"), + WithURL("https://github.com/securego/gosec"), linter.NewConfig(gosimple.New(&cfg.LintersSettings.Gosimple)). WithEnabledByDefault(). WithSince("v1.20.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle). - WithAlternativeNames(megacheckName). WithAutoFix(). WithURL("https://github.com/dominikh/go-tools/tree/HEAD/simple"), @@ -447,7 +442,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithPresets(linter.PresetBugs, linter.PresetMetaLinter). WithAutoFix(). - WithAlternativeNames("vet", "vetshadow"). WithURL("https://pkg.go.dev/cmd/vet"), linter.NewConfig(grouper.New(&cfg.LintersSettings.Grouper)). @@ -507,7 +501,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.49.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetStyle, linter.PresetBugs). - WithAlternativeNames("logrlint"). WithURL("https://github.com/timonwong/loggercheck"), linter.NewConfig(maintidx.New(&cfg.LintersSettings.MaintIdx)). @@ -675,7 +668,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetBugs, linter.PresetMetaLinter). - WithAlternativeNames(megacheckName). WithAutoFix(). WithURL("https://staticcheck.dev/"), @@ -749,7 +741,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.20.0"). WithLoadForGoAnalysis(). WithPresets(linter.PresetUnused). - WithAlternativeNames(megacheckName). ConsiderSlow(). WithChangeTypes(). WithURL("https://github.com/dominikh/go-tools/tree/HEAD/unused"), diff --git a/pkg/lint/lintersdb/manager_test.go b/pkg/lint/lintersdb/manager_test.go index 4fec48d90246..fa8c783fde71 100644 --- a/pkg/lint/lintersdb/manager_test.go +++ b/pkg/lint/lintersdb/manager_test.go @@ -65,63 +65,17 @@ func TestManager_GetOptimizedLinters(t *testing.T) { } func TestManager_build(t *testing.T) { - allMegacheckLinterNames := []string{"gosimple", "staticcheck", "unused"} - testCases := []struct { desc string cfg *config.Config defaultSet []string // enabled by default linters expected []string // alphabetically ordered enabled linter names }{ - { - desc: "disable all linters from megacheck", - cfg: &config.Config{ - Linters: config.Linters{ - Disable: []string{"megacheck"}, - }, - }, - defaultSet: allMegacheckLinterNames, - expected: []string{"typecheck"}, // all disabled - }, - { - desc: "disable only staticcheck", - cfg: &config.Config{ - Linters: config.Linters{ - Disable: []string{"staticcheck"}, - }, - }, - defaultSet: allMegacheckLinterNames, - expected: []string{"gosimple", "typecheck", "unused"}, - }, - { - desc: "don't merge into megacheck", - defaultSet: allMegacheckLinterNames, - expected: []string{"gosimple", "staticcheck", "typecheck", "unused"}, - }, - { - desc: "expand megacheck", - cfg: &config.Config{ - Linters: config.Linters{ - Enable: []string{"megacheck"}, - }, - }, - defaultSet: nil, - expected: []string{"gosimple", "staticcheck", "typecheck", "unused"}, - }, { desc: "don't disable anything", defaultSet: []string{"gofmt", "govet", "typecheck"}, expected: []string{"gofmt", "govet", "typecheck"}, }, - { - desc: "enable gosec by gas alias", - cfg: &config.Config{ - Linters: config.Linters{ - Enable: []string{"gas"}, - }, - }, - expected: []string{"gosec", "typecheck"}, - }, { desc: "enable gosec by primary name", cfg: &config.Config{ @@ -131,25 +85,6 @@ func TestManager_build(t *testing.T) { }, expected: []string{"gosec", "typecheck"}, }, - { - desc: "enable gosec by both names", - cfg: &config.Config{ - Linters: config.Linters{ - Enable: []string{"gosec", "gas"}, - }, - }, - expected: []string{"gosec", "typecheck"}, - }, - { - desc: "disable gosec by gas alias", - cfg: &config.Config{ - Linters: config.Linters{ - Disable: []string{"gas"}, - }, - }, - defaultSet: []string{"gosec"}, - expected: []string{"typecheck"}, - }, { desc: "disable gosec by primary name", cfg: &config.Config{ diff --git a/pkg/lint/lintersdb/validator_test.go b/pkg/lint/lintersdb/validator_test.go index 25e77e4490b0..f7a076348e4e 100644 --- a/pkg/lint/lintersdb/validator_test.go +++ b/pkg/lint/lintersdb/validator_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/require" "github.com/golangci/golangci-lint/pkg/config" - "github.com/golangci/golangci-lint/pkg/logutils" ) type validateErrorTestCase struct { @@ -210,27 +209,3 @@ 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) -} diff --git a/pkg/result/processors/nolint_filter_test.go b/pkg/result/processors/nolint_filter_test.go index 66263b9eca12..7238294a1c25 100644 --- a/pkg/result/processors/nolint_filter_test.go +++ b/pkg/result/processors/nolint_filter_test.go @@ -1,7 +1,6 @@ package processors import ( - "fmt" "go/token" "path/filepath" "testing" @@ -180,16 +179,6 @@ func TestNolintFilter_Process_invalidLinterNameWithViolationOnTheSameLine(t *tes assert.Equal(t, issues, processedIssues) } -func TestNolintFilter_Process_aliases(t *testing.T) { - p := newTestNolintFilter(getMockLog()) - for _, line := range []int{47, 49, 51} { - t.Run(fmt.Sprintf("line-%d", line), func(t *testing.T) { - processAssertEmpty(t, p, newNolintFileIssue(line, "gosec")) - }) - } - p.Finish() -} - func Test_ignoredRange_doesMatch(t *testing.T) { testcases := []struct { doc string diff --git a/pkg/result/processors/testdata/nolint_filter/nolint.go b/pkg/result/processors/testdata/nolint_filter/nolint.go index 08821854b8ed..05f51ddc5f9a 100644 --- a/pkg/result/processors/testdata/nolint_filter/nolint.go +++ b/pkg/result/processors/testdata/nolint_filter/nolint.go @@ -44,12 +44,8 @@ func nolintFuncByPrecedingMultilineComment3() *string { return &xv } -var nolintAliasGAS bool //nolint:gas - var nolintAliasGosec bool //nolint:gosec -var nolintAliasUpperCase int // nolint: GAS - //nolint:errcheck var ( nolintVarBlockVar1 int diff --git a/test/testdata/withxtest/p_test.go b/test/testdata/withxtest/p_test.go index 94031e8e9148..1ca4dc083ef0 100644 --- a/test/testdata/withxtest/p_test.go +++ b/test/testdata/withxtest/p_test.go @@ -2,7 +2,7 @@ package p_test import "fmt" -func WithGolintIssues(b bool) { //nolint:megacheck +func WithGolintIssues(b bool) { //nolint:staticcheck if b { return } else { From 391aee7cf2aa747ffc75c0499a38ffe9de13fb85 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 25 Feb 2025 19:07:04 +0100 Subject: [PATCH 2/2] review Co-authored-by: Oleksandr Redko --- docs/src/docs/product/performance.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/docs/product/performance.mdx b/docs/src/docs/product/performance.mdx index 790319a6c243..4ad523594ce7 100644 --- a/docs/src/docs/product/performance.mdx +++ b/docs/src/docs/product/performance.mdx @@ -49,9 +49,9 @@ Less `GOGC` values trigger garbage collection more frequently and golangci-lint 2. Smart linters scheduling We schedule linters by a special algorithm which takes estimated execution time into account. It allows - to save 10-30% of time when one of heavy linters (staticcheck, etc) is enabled. + to save 10-30% of time when one of heavy linters (e.g., staticcheck) is enabled. 3. Don't fork to run shell commands -All linters have their version fixed with go modules, they are builtin +All linters have their versions fixed with Go modules, they are built-in, and you don't need to install them separately.