feat: deprecate varcheck, deadcode, and structcheck (#3125)

This commit is contained in:
Ludovic Fernandez 2022-08-21 21:37:47 +02:00 committed by GitHub
parent e1afce4433
commit 37d3aa437a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 67 additions and 60 deletions

View File

@ -68,7 +68,6 @@ linters:
disable-all: true disable-all: true
enable: enable:
- bodyclose - bodyclose
- deadcode
- depguard - depguard
- dogsled - dogsled
- dupl - dupl
@ -93,13 +92,11 @@ linters:
- noctx - noctx
- nolintlint - nolintlint
- staticcheck - staticcheck
- structcheck
- stylecheck - stylecheck
- typecheck - typecheck
- unconvert - unconvert
- unparam - unparam
- unused - unused
- varcheck
- whitespace - whitespace
# don't enable: # don't enable:

View File

@ -320,7 +320,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.0.0"). WithSince("v1.0.0").
WithLoadForGoAnalysis(). WithLoadForGoAnalysis().
WithPresets(linter.PresetUnused). WithPresets(linter.PresetUnused).
WithURL("https://github.com/remyoudompheng/go-misc/tree/master/deadcode"), WithURL("https://github.com/remyoudompheng/go-misc/tree/master/deadcode").
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
linter.NewConfig(golinters.NewDepguard(depGuardCfg)). linter.NewConfig(golinters.NewDepguard(depGuardCfg)).
WithSince("v1.4.0"). WithSince("v1.4.0").
@ -714,6 +715,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithLoadForGoAnalysis(). WithLoadForGoAnalysis().
WithPresets(linter.PresetUnused). WithPresets(linter.PresetUnused).
WithURL("https://github.com/opennota/check"). WithURL("https://github.com/opennota/check").
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused").
WithNoopFallback(m.cfg), WithNoopFallback(m.cfg),
linter.NewConfig(golinters.NewStylecheck(stylecheckCfg)). linter.NewConfig(golinters.NewStylecheck(stylecheckCfg)).
@ -786,7 +788,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.0.0"). WithSince("v1.0.0").
WithLoadForGoAnalysis(). WithLoadForGoAnalysis().
WithPresets(linter.PresetUnused). WithPresets(linter.PresetUnused).
WithURL("https://github.com/opennota/check"), WithURL("https://github.com/opennota/check").
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused"),
linter.NewConfig(golinters.NewVarnamelen(varnamelenCfg)). linter.NewConfig(golinters.NewVarnamelen(varnamelenCfg)).
WithSince("v1.43.0"). WithSince("v1.43.0").
@ -831,9 +834,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
golinters.NewStaticcheck(staticcheckCfg).Name(): true, golinters.NewStaticcheck(staticcheckCfg).Name(): true,
golinters.NewUnused(unusedCfg).Name(): true, golinters.NewUnused(unusedCfg).Name(): true,
golinters.NewGosimple(gosimpleCfg).Name(): true, golinters.NewGosimple(gosimpleCfg).Name(): true,
golinters.NewVarcheck(varcheckCfg).Name(): true,
golinters.NewIneffassign().Name(): true, golinters.NewIneffassign().Name(): true,
golinters.NewDeadcode().Name(): true,
golinters.NewTypecheck().Name(): true, golinters.NewTypecheck().Name(): true,
} }
return enableLinterConfigs(lcs, func(lc *linter.Config) bool { return enableLinterConfigs(lcs, func(lc *linter.Config) bool {

View File

@ -128,16 +128,23 @@ func TestNolintInvalidLinterName(t *testing.T) {
{ {
Pos: token.Position{ Pos: token.Position{
Filename: fileName, Filename: fileName,
Line: 3, Line: 10,
}, },
FromLinter: "varcheck", FromLinter: "errcheck",
}, },
{ {
Pos: token.Position{ Pos: token.Position{
Filename: fileName, Filename: fileName,
Line: 6, Line: 13,
}, },
FromLinter: "deadcode", FromLinter: "errcheck",
},
{
Pos: token.Position{
Filename: fileName,
Line: 22,
},
FromLinter: "ineffassign",
}, },
} }
@ -244,22 +251,22 @@ func TestIgnoredRangeMatches(t *testing.T) {
func TestNolintWholeFile(t *testing.T) { func TestNolintWholeFile(t *testing.T) {
fileName := filepath.Join("testdata", "nolint_whole_file.go") fileName := filepath.Join("testdata", "nolint_whole_file.go")
p := newTestNolintProcessor(nil) p := newTestNolintProcessor(getMockLog())
defer p.Finish() defer p.Finish()
processAssertEmpty(t, p, result.Issue{ processAssertEmpty(t, p, result.Issue{
Pos: token.Position{ Pos: token.Position{
Filename: fileName, Filename: fileName,
Line: 4, Line: 9,
}, },
FromLinter: "varcheck", FromLinter: "errcheck",
}) })
processAssertSame(t, p, result.Issue{ processAssertSame(t, p, result.Issue{
Pos: token.Position{ Pos: token.Position{
Filename: fileName, Filename: fileName,
Line: 4, Line: 14,
}, },
FromLinter: "deadcode", FromLinter: "govet",
}) })
} }

View File

@ -35,17 +35,23 @@ func newIssueFromTextTestCase(text string) result.Issue {
} }
func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue { func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue {
t.Helper()
processedIssues, err := p.Process(issues) processedIssues, err := p.Process(issues)
assert.NoError(t, err) assert.NoError(t, err)
return processedIssues return processedIssues
} }
func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) { func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) {
t.Helper()
processedIssues := process(t, p, issues...) processedIssues := process(t, p, issues...)
assert.Equal(t, issues, processedIssues) assert.Equal(t, issues, processedIssues)
} }
func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) { func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) {
t.Helper()
processedIssues := process(t, p, issues...) processedIssues := process(t, p, issues...)
assert.Empty(t, processedIssues) assert.Empty(t, processedIssues)
} }

View File

@ -1,8 +1,25 @@
package testdata package testdata
var nolintUnknownLinter1 bool //nolint:bad1,deadcode,varcheck,megacheck import "math"
//nolint:bad2,deadcode,megacheck
func nolintUnknownLinter2() {
func RetErr() error {
return nil
}
func MissedErrorCheck() {
RetErr() //nolint:bad1,errcheck
}
//nolint:bad2,errcheck
func MissedErrorCheck2() {
RetErr()
}
func _() {
x := math.MinInt8
for {
_ = x
x = 0 //nolint:bad1,ineffassign
x = 0
}
} }

View File

@ -1,4 +1,14 @@
//nolint: varcheck //nolint:errcheck
package testdata package testdata
var nolintVarcheck int func RetError() error {
return nil
}
func MissedErrorCheck1() {
RetErr()
}
func jo(v, w bool) bool {
return v == w || v == w
}

View File

@ -47,12 +47,7 @@ func prepareGithubProject(owner, name string) func(*testing.B) {
func getBenchLintersArgsNoMegacheck() []string { func getBenchLintersArgsNoMegacheck() []string {
return []string{ return []string{
"--enable=deadcode",
"--enable=gocyclo", "--enable=gocyclo",
"--enable=golint",
"--enable=varcheck",
"--enable=structcheck",
"--enable=maligned",
"--enable=errcheck", "--enable=errcheck",
"--enable=dupl", "--enable=dupl",
"--enable=ineffassign", "--enable=ineffassign",

View File

@ -251,8 +251,8 @@ func TestSortedResults(t *testing.T) {
{ {
opt: "--sort-results=false", opt: "--sort-results=false",
want: strings.Join([]string{ want: strings.Join([]string{
"testdata/sort_results/main.go:12:5: `db` is unused (deadcode)",
"testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)", "testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)",
"testdata/sort_results/main.go:12:5: var `db` is unused (unused)",
"testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)", "testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)",
}, "\n"), }, "\n"),
}, },
@ -260,7 +260,7 @@ func TestSortedResults(t *testing.T) {
opt: "--sort-results=true", opt: "--sort-results=true",
want: strings.Join([]string{ want: strings.Join([]string{
"testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)", "testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)",
"testdata/sort_results/main.go:12:5: `db` is unused (deadcode)", "testdata/sort_results/main.go:12:5: var `db` is unused (unused)",
"testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)", "testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)",
}, "\n"), }, "\n"),
}, },
@ -435,17 +435,6 @@ func TestSkippedDirsTestdata(t *testing.T) {
ExpectNoIssues() // all was skipped because in testdata ExpectNoIssues() // all was skipped because in testdata
} }
func TestDeadcodeNoFalsePositivesInMainPkg(t *testing.T) {
testshared.NewRunnerBuilder(t).
WithNoConfig().
WithArgs("--disable-all", "-Edeadcode").
WithTargetPath(testdataDir, "deadcode_main_pkg").
Runner().
Install().
Run().
ExpectNoIssues()
}
func TestIdentifierUsedOnlyInTests(t *testing.T) { func TestIdentifierUsedOnlyInTests(t *testing.T) {
testshared.NewRunnerBuilder(t). testshared.NewRunnerBuilder(t).
WithNoConfig(). WithNoConfig().

View File

@ -1,4 +1,4 @@
//golangcitest:args -Edeadcode //golangcitest:args -Edeadcode --internal-cmd-test
package testdata package testdata
var y int var y int

View File

@ -1,15 +0,0 @@
package main
import "testing"
func TestF(t *testing.T) {
}
func BenchmarkF(t *testing.B) {
}
func ExampleF() {
}

View File

@ -12,13 +12,13 @@ import (
// Something just some struct // Something just some struct
type Something struct{} type Something struct{}
func aAllowedImport() { //nolint:deadcode,unused func aAllowedImport() { //nolint:unused
mfile, _ := modfile.Parse("go.mod", []byte{}, nil) mfile, _ := modfile.Parse("go.mod", []byte{}, nil)
log.Println(mfile) log.Println(mfile)
} }
func aBlockedImport() { //nolint:deadcode,unused func aBlockedImport() { //nolint:unused
data := []byte{} data := []byte{}
something := Something{} something := Something{}
_ = yaml.Unmarshal(data, &something) _ = yaml.Unmarshal(data, &something)

View File

@ -8,7 +8,7 @@ import "fmt"
func Foo() { func Foo() {
fmt.Println("not specific") //nolint // want "directive `.*` should mention specific linter such as `//nolint:my-linter`" fmt.Println("not specific") //nolint // want "directive `.*` should mention specific linter such as `//nolint:my-linter`"
fmt.Println("not machine readable") // nolint // want "directive `.*` should be written as `//nolint`" fmt.Println("not machine readable") // nolint // want "directive `.*` should be written as `//nolint`"
fmt.Println("extra spaces") // nolint:deadcode // because // want "directive `.*` should not have more than one leading space" fmt.Println("extra spaces") // nolint:unused // because // want "directive `.*` should not have more than one leading space"
// test expanded range // test expanded range
//nolint:misspell // deliberate misspelling to trigger nolintlint //nolint:misspell // deliberate misspelling to trigger nolintlint

View File

@ -1,4 +1,4 @@
//golangcitest:args -Evarcheck //golangcitest:args -Evarcheck --internal-cmd-test
package testdata package testdata
var v string // want "`v` is unused" var v string // want "`v` is unused"