Skip to content

Commit 7892153

Browse files
authored
feat: remove alternative names (#5472)
1 parent 45f39cc commit 7892153

File tree

16 files changed

+5
-222
lines changed

16 files changed

+5
-222
lines changed

docs/src/docs/product/performance.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Less `GOGC` values trigger garbage collection more frequently and golangci-lint
3333

3434
- build `ssa.Program` once
3535

36-
Some linters (megacheck, interfacer, unparam) work on SSA representation.
36+
Some linters (staticcheck, gosec, unparam) work on SSA representation.
3737
Building of this representation takes 1.5 seconds on 8 kLoC repo and 6 seconds on `$GOROOT/src`.
3838

3939
- parse source code and build AST once
@@ -49,9 +49,9 @@ Less `GOGC` values trigger garbage collection more frequently and golangci-lint
4949
2. Smart linters scheduling
5050

5151
We schedule linters by a special algorithm which takes estimated execution time into account. It allows
52-
to save 10-30% of time when one of heavy linters (megacheck etc) is enabled.
52+
to save 10-30% of time when one of heavy linters (e.g., staticcheck) is enabled.
5353

5454
3. Don't fork to run shell commands
5555

56-
All linters has their version fixed with go modules, they are builtin
56+
All linters have their versions fixed with Go modules, they are built-in,
5757
and you don't need to install them separately.

pkg/golinters/gosec/testdata/gosec.go

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ func Gosec() {
1414
log.Print(h)
1515
}
1616

17-
func GosecNolintGas() {
18-
h := md5.New() //nolint:gas
19-
log.Print(h)
20-
}
21-
2217
func GosecNolintGosec() {
2318
h := md5.New() //nolint:gosec
2419
log.Print(h)

pkg/golinters/gosimple/testdata/gosimple.go

-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,3 @@ func GosimpleNolintGosimple(ss []string) {
2020
}
2121
}
2222
}
23-
24-
func GosimpleNolintMegacheck(ss []string) {
25-
if ss != nil { //nolint:megacheck
26-
for _, s := range ss {
27-
log.Printf(s)
28-
}
29-
}
30-
}

pkg/golinters/govet/testdata/govet.go

-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ func GovetShadow(f io.Reader, buf []byte) (err error) {
2424
return
2525
}
2626

27-
func GovetNolintVet() error {
28-
return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vet
29-
}
30-
31-
func GovetNolintVetShadow() error {
32-
return &os.PathError{"first", "path", os.ErrNotExist} //nolint:vetshadow
33-
}
34-
3527
func GovetPrintf() {
3628
x := "dummy"
3729
fmt.Printf("%d", x) // want "printf: fmt.Printf format %d has arg x of wrong type string"

pkg/golinters/loggercheck/testdata/logrlint_compatiblity.go

-28
This file was deleted.

pkg/golinters/staticcheck/testdata/staticcheck.go

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ func StaticcheckNolintStaticcheck() {
1616
x = x //nolint:staticcheck
1717
}
1818

19-
func StaticcheckNolintMegacheck() {
20-
var x int
21-
x = x //nolint:megacheck
22-
}
23-
2419
func StaticcheckPrintf() {
2520
x := "dummy"
2621
fmt.Printf("%d", x) // want "SA5009: Printf format %d has arg #1 of wrong type"

pkg/golinters/staticcheck/testdata/staticcheck_in_megacheck.go

-26
This file was deleted.

pkg/golinters/stylecheck/testdata/stylecheck.go

-11
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,3 @@ func StylecheckNolintStylecheck(x int) {
2323
return
2424
}
2525
}
26-
27-
func StylecheckNolintMegacheck(x int) {
28-
switch x {
29-
case 1:
30-
return
31-
default: //nolint:megacheck // want "ST1015: default case should be first or last in switch statement"
32-
return
33-
case 2:
34-
return
35-
}
36-
}

pkg/golinters/stylecheck/testdata/stylecheck_not_in_megacheck.go

-10
This file was deleted.

pkg/golinters/unused/testdata/unused.go

-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ func fn6() { fn4() } // want "func `fn6` is unused"
1717
type unusedStruct struct{} // want "type `unusedStruct` is unused"
1818

1919
type unusedStructNolintUnused struct{} //nolint:unused
20-
21-
type unusedStructNolintMegacheck struct{} //nolint:megacheck

pkg/lint/lintersdb/builder_linter.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
131131
return nil, nil
132132
}
133133

134-
const megacheckName = "megacheck"
135-
136134
// The linters are sorted in the alphabetical order (case-insensitive).
137135
// When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint.
138136
return []*linter.Config{
@@ -365,7 +363,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
365363
WithSince("v1.26.0").
366364
WithPresets(linter.PresetStyle, linter.PresetError).
367365
WithLoadForGoAnalysis().
368-
WithAlternativeNames("goerr113").
369366
WithAutoFix().
370367
WithURL("https://github.com/Djarvur/go-err113"),
371368

@@ -423,15 +420,13 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
423420
WithSince("v1.0.0").
424421
WithLoadForGoAnalysis().
425422
WithPresets(linter.PresetBugs).
426-
WithURL("https://github.com/securego/gosec").
427-
WithAlternativeNames("gas"),
423+
WithURL("https://github.com/securego/gosec"),
428424

429425
linter.NewConfig(gosimple.New(&cfg.LintersSettings.Gosimple)).
430426
WithEnabledByDefault().
431427
WithSince("v1.20.0").
432428
WithLoadForGoAnalysis().
433429
WithPresets(linter.PresetStyle).
434-
WithAlternativeNames(megacheckName).
435430
WithAutoFix().
436431
WithURL("https://github.com/dominikh/go-tools/tree/HEAD/simple"),
437432

@@ -447,7 +442,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
447442
WithLoadForGoAnalysis().
448443
WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
449444
WithAutoFix().
450-
WithAlternativeNames("vet", "vetshadow").
451445
WithURL("https://pkg.go.dev/cmd/vet"),
452446

453447
linter.NewConfig(grouper.New(&cfg.LintersSettings.Grouper)).
@@ -507,7 +501,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
507501
WithSince("v1.49.0").
508502
WithLoadForGoAnalysis().
509503
WithPresets(linter.PresetStyle, linter.PresetBugs).
510-
WithAlternativeNames("logrlint").
511504
WithURL("https://github.com/timonwong/loggercheck"),
512505

513506
linter.NewConfig(maintidx.New(&cfg.LintersSettings.MaintIdx)).
@@ -675,7 +668,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
675668
WithSince("v1.0.0").
676669
WithLoadForGoAnalysis().
677670
WithPresets(linter.PresetBugs, linter.PresetMetaLinter).
678-
WithAlternativeNames(megacheckName).
679671
WithAutoFix().
680672
WithURL("https://staticcheck.dev/"),
681673

@@ -749,7 +741,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
749741
WithSince("v1.20.0").
750742
WithLoadForGoAnalysis().
751743
WithPresets(linter.PresetUnused).
752-
WithAlternativeNames(megacheckName).
753744
ConsiderSlow().
754745
WithChangeTypes().
755746
WithURL("https://github.com/dominikh/go-tools/tree/HEAD/unused"),

pkg/lint/lintersdb/manager_test.go

-65
Original file line numberDiff line numberDiff line change
@@ -65,63 +65,17 @@ func TestManager_GetOptimizedLinters(t *testing.T) {
6565
}
6666

6767
func TestManager_build(t *testing.T) {
68-
allMegacheckLinterNames := []string{"gosimple", "staticcheck", "unused"}
69-
7068
testCases := []struct {
7169
desc string
7270
cfg *config.Config
7371
defaultSet []string // enabled by default linters
7472
expected []string // alphabetically ordered enabled linter names
7573
}{
76-
{
77-
desc: "disable all linters from megacheck",
78-
cfg: &config.Config{
79-
Linters: config.Linters{
80-
Disable: []string{"megacheck"},
81-
},
82-
},
83-
defaultSet: allMegacheckLinterNames,
84-
expected: []string{"typecheck"}, // all disabled
85-
},
86-
{
87-
desc: "disable only staticcheck",
88-
cfg: &config.Config{
89-
Linters: config.Linters{
90-
Disable: []string{"staticcheck"},
91-
},
92-
},
93-
defaultSet: allMegacheckLinterNames,
94-
expected: []string{"gosimple", "typecheck", "unused"},
95-
},
96-
{
97-
desc: "don't merge into megacheck",
98-
defaultSet: allMegacheckLinterNames,
99-
expected: []string{"gosimple", "staticcheck", "typecheck", "unused"},
100-
},
101-
{
102-
desc: "expand megacheck",
103-
cfg: &config.Config{
104-
Linters: config.Linters{
105-
Enable: []string{"megacheck"},
106-
},
107-
},
108-
defaultSet: nil,
109-
expected: []string{"gosimple", "staticcheck", "typecheck", "unused"},
110-
},
11174
{
11275
desc: "don't disable anything",
11376
defaultSet: []string{"gofmt", "govet", "typecheck"},
11477
expected: []string{"gofmt", "govet", "typecheck"},
11578
},
116-
{
117-
desc: "enable gosec by gas alias",
118-
cfg: &config.Config{
119-
Linters: config.Linters{
120-
Enable: []string{"gas"},
121-
},
122-
},
123-
expected: []string{"gosec", "typecheck"},
124-
},
12579
{
12680
desc: "enable gosec by primary name",
12781
cfg: &config.Config{
@@ -131,25 +85,6 @@ func TestManager_build(t *testing.T) {
13185
},
13286
expected: []string{"gosec", "typecheck"},
13387
},
134-
{
135-
desc: "enable gosec by both names",
136-
cfg: &config.Config{
137-
Linters: config.Linters{
138-
Enable: []string{"gosec", "gas"},
139-
},
140-
},
141-
expected: []string{"gosec", "typecheck"},
142-
},
143-
{
144-
desc: "disable gosec by gas alias",
145-
cfg: &config.Config{
146-
Linters: config.Linters{
147-
Disable: []string{"gas"},
148-
},
149-
},
150-
defaultSet: []string{"gosec"},
151-
expected: []string{"typecheck"},
152-
},
15388
{
15489
desc: "disable gosec by primary name",
15590
cfg: &config.Config{

pkg/lint/lintersdb/validator_test.go

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

88
"github.com/golangci/golangci-lint/pkg/config"
9-
"github.com/golangci/golangci-lint/pkg/logutils"
109
)
1110

1211
type validateErrorTestCase struct {
@@ -210,27 +209,3 @@ func TestValidator_validatePresets_error(t *testing.T) {
210209
})
211210
}
212211
}
213-
214-
func TestValidator_alternativeNamesDeprecation(t *testing.T) {
215-
t.Setenv(logutils.EnvTestRun, "0")
216-
217-
log := logutils.NewMockLog().
218-
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "vet", "govet").
219-
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "vetshadow", "govet").
220-
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "logrlint", "loggercheck").
221-
OnWarnf("The linter named %q is deprecated. It has been split into: %s.", "megacheck", "gosimple, staticcheck, unused").
222-
OnWarnf("The name %q is deprecated. The linter has been renamed to: %s.", "gas", "gosec")
223-
224-
m, err := NewManager(log, nil, NewLinterBuilder())
225-
require.NoError(t, err)
226-
227-
v := NewValidator(m)
228-
229-
cfg := &config.Linters{
230-
Enable: []string{"vet", "vetshadow", "logrlint"},
231-
Disable: []string{"megacheck", "gas"},
232-
}
233-
234-
err = v.alternativeNamesDeprecation(cfg)
235-
require.NoError(t, err)
236-
}

pkg/result/processors/nolint_filter_test.go

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package processors
22

33
import (
4-
"fmt"
54
"go/token"
65
"path/filepath"
76
"testing"
@@ -180,16 +179,6 @@ func TestNolintFilter_Process_invalidLinterNameWithViolationOnTheSameLine(t *tes
180179
assert.Equal(t, issues, processedIssues)
181180
}
182181

183-
func TestNolintFilter_Process_aliases(t *testing.T) {
184-
p := newTestNolintFilter(getMockLog())
185-
for _, line := range []int{47, 49, 51} {
186-
t.Run(fmt.Sprintf("line-%d", line), func(t *testing.T) {
187-
processAssertEmpty(t, p, newNolintFileIssue(line, "gosec"))
188-
})
189-
}
190-
p.Finish()
191-
}
192-
193182
func Test_ignoredRange_doesMatch(t *testing.T) {
194183
testcases := []struct {
195184
doc string

pkg/result/processors/testdata/nolint_filter/nolint.go

-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ func nolintFuncByPrecedingMultilineComment3() *string {
4444
return &xv
4545
}
4646

47-
var nolintAliasGAS bool //nolint:gas
48-
4947
var nolintAliasGosec bool //nolint:gosec
5048

51-
var nolintAliasUpperCase int // nolint: GAS
52-
5349
//nolint:errcheck
5450
var (
5551
nolintVarBlockVar1 int

test/testdata/withxtest/p_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package p_test
22

33
import "fmt"
44

5-
func WithGolintIssues(b bool) { //nolint:megacheck
5+
func WithGolintIssues(b bool) { //nolint:staticcheck
66
if b {
77
return
88
} else {

0 commit comments

Comments
 (0)