Skip to content

feat: remove alternative names #5472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/src/docs/product/performance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
5 changes: 0 additions & 5 deletions pkg/golinters/gosec/testdata/gosec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions pkg/golinters/gosimple/testdata/gosimple.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ func GosimpleNolintGosimple(ss []string) {
}
}
}

func GosimpleNolintMegacheck(ss []string) {
if ss != nil { //nolint:megacheck
for _, s := range ss {
log.Printf(s)
}
}
}
8 changes: 0 additions & 8 deletions pkg/golinters/govet/testdata/govet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 0 additions & 28 deletions pkg/golinters/loggercheck/testdata/logrlint_compatiblity.go

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/golinters/staticcheck/testdata/staticcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 0 additions & 26 deletions pkg/golinters/staticcheck/testdata/staticcheck_in_megacheck.go

This file was deleted.

11 changes: 0 additions & 11 deletions pkg/golinters/stylecheck/testdata/stylecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
10 changes: 0 additions & 10 deletions pkg/golinters/stylecheck/testdata/stylecheck_not_in_megacheck.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/golinters/unused/testdata/unused.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 1 addition & 10 deletions pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"),

Expand Down Expand Up @@ -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"),

Expand All @@ -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)).
Expand Down Expand Up @@ -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)).
Expand Down Expand Up @@ -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/"),

Expand Down Expand Up @@ -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"),
Expand Down
65 changes: 0 additions & 65 deletions pkg/lint/lintersdb/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
25 changes: 0 additions & 25 deletions pkg/lint/lintersdb/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
11 changes: 0 additions & 11 deletions pkg/result/processors/nolint_filter_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package processors

import (
"fmt"
"go/token"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions pkg/result/processors/testdata/nolint_filter/nolint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/withxtest/p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading