Skip to content

Commit

Permalink
feat: deprecate varcheck, deadcode, and structcheck (golangci#3125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and SeigeC committed Apr 4, 2023
1 parent 0c5eb11 commit d3e82b0
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 59 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Expand Up @@ -68,7 +68,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -93,13 +92,11 @@ linters:
- noctx
- nolintlint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

# don't enable:
Expand Down
9 changes: 5 additions & 4 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -320,7 +320,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.0.0").
WithLoadForGoAnalysis().
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)).
WithSince("v1.4.0").
Expand Down Expand Up @@ -714,6 +715,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithLoadForGoAnalysis().
WithPresets(linter.PresetUnused).
WithURL("https://github.com/opennota/check").
Deprecated("The owner seems to have abandoned the linter.", "v1.49.0", "unused").
WithNoopFallback(m.cfg),

linter.NewConfig(golinters.NewStylecheck(stylecheckCfg)).
Expand Down Expand Up @@ -786,7 +788,8 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.0.0").
WithLoadForGoAnalysis().
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)).
WithSince("v1.43.0").
Expand Down Expand Up @@ -834,9 +837,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
golinters.NewStaticcheck(staticcheckCfg).Name(): true,
golinters.NewUnused(unusedCfg).Name(): true,
golinters.NewGosimple(gosimpleCfg).Name(): true,
golinters.NewVarcheck(varcheckCfg).Name(): true,
golinters.NewIneffassign().Name(): true,
golinters.NewDeadcode().Name(): true,
golinters.NewTypecheck().Name(): true,
}
return enableLinterConfigs(lcs, func(lc *linter.Config) bool {
Expand Down
25 changes: 16 additions & 9 deletions pkg/result/processors/nolint_test.go
Expand Up @@ -128,16 +128,23 @@ func TestNolintInvalidLinterName(t *testing.T) {
{
Pos: token.Position{
Filename: fileName,
Line: 3,
Line: 10,
},
FromLinter: "varcheck",
FromLinter: "errcheck",
},
{
Pos: token.Position{
Filename: fileName,
Line: 13,
},
FromLinter: "errcheck",
},
{
Pos: token.Position{
Filename: fileName,
Line: 6,
Line: 22,
},
FromLinter: "deadcode",
FromLinter: "ineffassign",
},
}

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

p := newTestNolintProcessor(nil)
p := newTestNolintProcessor(getMockLog())
defer p.Finish()

processAssertEmpty(t, p, result.Issue{
Pos: token.Position{
Filename: fileName,
Line: 4,
Line: 9,
},
FromLinter: "varcheck",
FromLinter: "errcheck",
})
processAssertSame(t, p, result.Issue{
Pos: token.Position{
Filename: fileName,
Line: 4,
Line: 14,
},
FromLinter: "deadcode",
FromLinter: "govet",
})
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/result/processors/processor_test.go
Expand Up @@ -35,17 +35,23 @@ func newIssueFromTextTestCase(text string) result.Issue {
}

func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue {
t.Helper()

processedIssues, err := p.Process(issues)
assert.NoError(t, err)
return processedIssues
}

func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) {
t.Helper()

processedIssues := process(t, p, issues...)
assert.Equal(t, issues, processedIssues)
}

func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) {
t.Helper()

processedIssues := process(t, p, issues...)
assert.Empty(t, processedIssues)
}
23 changes: 20 additions & 3 deletions pkg/result/processors/testdata/nolint_bad_names.go
@@ -1,8 +1,25 @@
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
}
}
14 changes: 12 additions & 2 deletions pkg/result/processors/testdata/nolint_whole_file.go
@@ -1,4 +1,14 @@
//nolint: varcheck
//nolint:errcheck
package testdata

var nolintVarcheck int
func RetError() error {
return nil
}

func MissedErrorCheck1() {
RetErr()
}

func jo(v, w bool) bool {
return v == w || v == w
}
5 changes: 0 additions & 5 deletions test/bench/bench_test.go
Expand Up @@ -47,12 +47,7 @@ func prepareGithubProject(owner, name string) func(*testing.B) {

func getBenchLintersArgsNoMegacheck() []string {
return []string{
"--enable=deadcode",
"--enable=gocyclo",
"--enable=golint",
"--enable=varcheck",
"--enable=structcheck",
"--enable=maligned",
"--enable=errcheck",
"--enable=dupl",
"--enable=ineffassign",
Expand Down
15 changes: 2 additions & 13 deletions test/run_test.go
Expand Up @@ -251,16 +251,16 @@ func TestSortedResults(t *testing.T) {
{
opt: "--sort-results=false",
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:12:5: var `db` is unused (unused)",
"testdata/sort_results/main.go:8:6: func `returnError` is unused (unused)",
}, "\n"),
},
{
opt: "--sort-results=true",
want: strings.Join([]string{
"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)",
}, "\n"),
},
Expand Down Expand Up @@ -435,17 +435,6 @@ func TestSkippedDirsTestdata(t *testing.T) {
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) {
testshared.NewRunnerBuilder(t).
WithNoConfig().
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/deadcode.go
@@ -1,4 +1,4 @@
//golangcitest:args -Edeadcode
//golangcitest:args -Edeadcode --internal-cmd-test
package testdata

var y int
Expand Down
15 changes: 0 additions & 15 deletions test/testdata/deadcode_main_pkg/main_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions test/testdata/gomodguard.go
Expand Up @@ -12,13 +12,13 @@ import (
// Something just some struct
type Something struct{}

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

log.Println(mfile)
}

func aBlockedImport() { //nolint:deadcode,unused
func aBlockedImport() { //nolint:unused
data := []byte{}
something := Something{}
_ = yaml.Unmarshal(data, &something)
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/nolintlint.go
Expand Up @@ -8,7 +8,7 @@ import "fmt"
func Foo() {
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("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
//nolint:misspell // deliberate misspelling to trigger nolintlint
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/varcheck.go
@@ -1,4 +1,4 @@
//golangcitest:args -Evarcheck
//golangcitest:args -Evarcheck --internal-cmd-test
package testdata

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

0 comments on commit d3e82b0

Please sign in to comment.