Skip to content

Commit 37d3aa4

Browse files
authored
feat: deprecate varcheck, deadcode, and structcheck (#3125)
1 parent e1afce4 commit 37d3aa4

File tree

13 files changed

+66
-59
lines changed

13 files changed

+66
-59
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ linters:
6868
disable-all: true
6969
enable:
7070
- bodyclose
71-
- deadcode
7271
- depguard
7372
- dogsled
7473
- dupl
@@ -93,13 +92,11 @@ linters:
9392
- noctx
9493
- nolintlint
9594
- staticcheck
96-
- structcheck
9795
- stylecheck
9896
- typecheck
9997
- unconvert
10098
- unparam
10199
- unused
102-
- varcheck
103100
- whitespace
104101

105102
# don't enable:

pkg/lint/lintersdb/manager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
320320
WithSince("v1.0.0").
321321
WithLoadForGoAnalysis().
322322
WithPresets(linter.PresetUnused).
323-
WithURL("https://github.com/remyoudompheng/go-misc/tree/master/deadcode"),
323+
WithURL("https://github.com/remyoudompheng/go-misc/tree/master/deadcode").
324+
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
324325

325326
linter.NewConfig(golinters.NewDepguard(depGuardCfg)).
326327
WithSince("v1.4.0").
@@ -714,6 +715,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
714715
WithLoadForGoAnalysis().
715716
WithPresets(linter.PresetUnused).
716717
WithURL("https://github.com/opennota/check").
718+
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused").
717719
WithNoopFallback(m.cfg),
718720

719721
linter.NewConfig(golinters.NewStylecheck(stylecheckCfg)).
@@ -786,7 +788,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
786788
WithSince("v1.0.0").
787789
WithLoadForGoAnalysis().
788790
WithPresets(linter.PresetUnused).
789-
WithURL("https://github.com/opennota/check"),
791+
WithURL("https://github.com/opennota/check").
792+
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
790793

791794
linter.NewConfig(golinters.NewVarnamelen(varnamelenCfg)).
792795
WithSince("v1.43.0").
@@ -831,9 +834,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
831834
golinters.NewStaticcheck(staticcheckCfg).Name(): true,
832835
golinters.NewUnused(unusedCfg).Name(): true,
833836
golinters.NewGosimple(gosimpleCfg).Name(): true,
834-
golinters.NewVarcheck(varcheckCfg).Name(): true,
835837
golinters.NewIneffassign().Name(): true,
836-
golinters.NewDeadcode().Name(): true,
837838
golinters.NewTypecheck().Name(): true,
838839
}
839840
return enableLinterConfigs(lcs, func(lc *linter.Config) bool {

pkg/result/processors/nolint_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,23 @@ func TestNolintInvalidLinterName(t *testing.T) {
128128
{
129129
Pos: token.Position{
130130
Filename: fileName,
131-
Line: 3,
131+
Line: 10,
132132
},
133-
FromLinter: "varcheck",
133+
FromLinter: "errcheck",
134+
},
135+
{
136+
Pos: token.Position{
137+
Filename: fileName,
138+
Line: 13,
139+
},
140+
FromLinter: "errcheck",
134141
},
135142
{
136143
Pos: token.Position{
137144
Filename: fileName,
138-
Line: 6,
145+
Line: 22,
139146
},
140-
FromLinter: "deadcode",
147+
FromLinter: "ineffassign",
141148
},
142149
}
143150

@@ -244,22 +251,22 @@ func TestIgnoredRangeMatches(t *testing.T) {
244251
func TestNolintWholeFile(t *testing.T) {
245252
fileName := filepath.Join("testdata", "nolint_whole_file.go")
246253

247-
p := newTestNolintProcessor(nil)
254+
p := newTestNolintProcessor(getMockLog())
248255
defer p.Finish()
249256

250257
processAssertEmpty(t, p, result.Issue{
251258
Pos: token.Position{
252259
Filename: fileName,
253-
Line: 4,
260+
Line: 9,
254261
},
255-
FromLinter: "varcheck",
262+
FromLinter: "errcheck",
256263
})
257264
processAssertSame(t, p, result.Issue{
258265
Pos: token.Position{
259266
Filename: fileName,
260-
Line: 4,
267+
Line: 14,
261268
},
262-
FromLinter: "deadcode",
269+
FromLinter: "govet",
263270
})
264271
}
265272

pkg/result/processors/processor_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,23 @@ func newIssueFromTextTestCase(text string) result.Issue {
3535
}
3636

3737
func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue {
38+
t.Helper()
39+
3840
processedIssues, err := p.Process(issues)
3941
assert.NoError(t, err)
4042
return processedIssues
4143
}
4244

4345
func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) {
46+
t.Helper()
47+
4448
processedIssues := process(t, p, issues...)
4549
assert.Equal(t, issues, processedIssues)
4650
}
4751

4852
func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) {
53+
t.Helper()
54+
4955
processedIssues := process(t, p, issues...)
5056
assert.Empty(t, processedIssues)
5157
}
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
package testdata
22

3-
var nolintUnknownLinter1 bool //nolint:bad1,deadcode,varcheck,megacheck
3+
import "math"
44

5-
//nolint:bad2,deadcode,megacheck
6-
func nolintUnknownLinter2() {
5+
func RetErr() error {
6+
return nil
7+
}
8+
9+
func MissedErrorCheck() {
10+
RetErr() //nolint:bad1,errcheck
11+
}
12+
13+
//nolint:bad2,errcheck
14+
func MissedErrorCheck2() {
15+
RetErr()
16+
}
717

18+
func _() {
19+
x := math.MinInt8
20+
for {
21+
_ = x
22+
x = 0 //nolint:bad1,ineffassign
23+
x = 0
24+
}
825
}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
//nolint: varcheck
1+
//nolint:errcheck
22
package testdata
33

4-
var nolintVarcheck int
4+
func RetError() error {
5+
return nil
6+
}
7+
8+
func MissedErrorCheck1() {
9+
RetErr()
10+
}
11+
12+
func jo(v, w bool) bool {
13+
return v == w || v == w
14+
}

test/bench/bench_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ func prepareGithubProject(owner, name string) func(*testing.B) {
4747

4848
func getBenchLintersArgsNoMegacheck() []string {
4949
return []string{
50-
"--enable=deadcode",
5150
"--enable=gocyclo",
52-
"--enable=golint",
53-
"--enable=varcheck",
54-
"--enable=structcheck",
55-
"--enable=maligned",
5651
"--enable=errcheck",
5752
"--enable=dupl",
5853
"--enable=ineffassign",

test/run_test.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,16 @@ func TestSortedResults(t *testing.T) {
251251
{
252252
opt: "--sort-results=false",
253253
want: strings.Join([]string{
254-
"testdata/sort_results/main.go:12:5: `db` is unused (deadcode)",
255254
"testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)",
255+
"testdata/sort_results/main.go:12:5: var `db` is unused (unused)",
256256
"testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)",
257257
}, "\n"),
258258
},
259259
{
260260
opt: "--sort-results=true",
261261
want: strings.Join([]string{
262262
"testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)",
263-
"testdata/sort_results/main.go:12:5: `db` is unused (deadcode)",
263+
"testdata/sort_results/main.go:12:5: var `db` is unused (unused)",
264264
"testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)",
265265
}, "\n"),
266266
},
@@ -435,17 +435,6 @@ func TestSkippedDirsTestdata(t *testing.T) {
435435
ExpectNoIssues() // all was skipped because in testdata
436436
}
437437

438-
func TestDeadcodeNoFalsePositivesInMainPkg(t *testing.T) {
439-
testshared.NewRunnerBuilder(t).
440-
WithNoConfig().
441-
WithArgs("--disable-all", "-Edeadcode").
442-
WithTargetPath(testdataDir, "deadcode_main_pkg").
443-
Runner().
444-
Install().
445-
Run().
446-
ExpectNoIssues()
447-
}
448-
449438
func TestIdentifierUsedOnlyInTests(t *testing.T) {
450439
testshared.NewRunnerBuilder(t).
451440
WithNoConfig().

test/testdata/deadcode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//golangcitest:args -Edeadcode
1+
//golangcitest:args -Edeadcode --internal-cmd-test
22
package testdata
33

44
var y int

test/testdata/deadcode_main_pkg/main_test.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/testdata/gomodguard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
// Something just some struct
1313
type Something struct{}
1414

15-
func aAllowedImport() { //nolint:deadcode,unused
15+
func aAllowedImport() { //nolint:unused
1616
mfile, _ := modfile.Parse("go.mod", []byte{}, nil)
1717

1818
log.Println(mfile)
1919
}
2020

21-
func aBlockedImport() { //nolint:deadcode,unused
21+
func aBlockedImport() { //nolint:unused
2222
data := []byte{}
2323
something := Something{}
2424
_ = yaml.Unmarshal(data, &something)

test/testdata/nolintlint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "fmt"
88
func Foo() {
99
fmt.Println("not specific") //nolint // want "directive `.*` should mention specific linter such as `//nolint:my-linter`"
1010
fmt.Println("not machine readable") // nolint // want "directive `.*` should be written as `//nolint`"
11-
fmt.Println("extra spaces") // nolint:deadcode // because // want "directive `.*` should not have more than one leading space"
11+
fmt.Println("extra spaces") // nolint:unused // because // want "directive `.*` should not have more than one leading space"
1212

1313
// test expanded range
1414
//nolint:misspell // deliberate misspelling to trigger nolintlint

test/testdata/varcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//golangcitest:args -Evarcheck
1+
//golangcitest:args -Evarcheck --internal-cmd-test
22
package testdata
33

44
var v string // want "`v` is unused"

0 commit comments

Comments
 (0)