Skip to content

Deprecate varcheck, structcheck, and deadcode #1841

Closed
@ldez

Description

@ldez

Is your feature request related to a problem?

Currently, by default golangci-lint runs the following linters about unused/dead code:

  • deadcode
  • structcheck
  • unused (staticcheck)
  • varcheck

Those linters, activated by default, are all the linters related to unused/dead code detection.

https://golangci-lint.run/usage/linters/

I created a small sandbox to find the scope of each of these linters.

linter var const function struct struct field method
deadcode ✔️ (1) ✔️ (2)
structcheck ✔️
varcheck ✔️ ✔️
unused ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
  • (1) False-negative on function
  • (2) See unused exported struct as unused
deadcode
$ golangci-lint run --no-config --disable-all -Edeadcode --print-issued-lines=false
sub/sub.go:11:7: `unexportedConstUnusedLocally` is unused (deadcode)
sub/sub.go:16:5: `unexportedGlobalUnused` is unused (deadcode)
main.go:29:6: `fn6` is unused (deadcode)
main.go:31:6: `unusedStruct` is unused (deadcode)
main.go:41:6: `ExposedUnusedStruct` is unused (deadcode)
structcheck
$ golangci-lint run --no-config --disable-all -Evarcheck --print-issued-lines=false
sub/sub.go:11:7: `unexportedConstUnusedLocally` is unused (varcheck)
sub/sub.go:16:5: `unexportedGlobalUnused` is unused (varcheck)
varcheck
$ golangci-lint run --no-config --disable-all -Estructcheck --print-issued-lines=false
sub/sub.go:19:2: `unexportedField` is unused (structcheck)
sub/sub.go:24:2: `unexportedField` is unused (structcheck)
main.go:32:2: `unexportedField` is unused (structcheck)
main.go:37:2: `unusedField` is unused (structcheck)
unused
$ golangci-lint run --no-config --disable-all -Eunused --print-issued-lines=false
sub/sub.go:19:2: field `unexportedField` is unused (unused)
sub/sub.go:24:2: field `unexportedField` is unused (unused)
sub/sub.go:16:5: var `unexportedGlobalUnused` is unused (unused)
sub/sub.go:11:7: const `unexportedConstUnusedLocally` is unused (unused)
main.go:51:34: func `unusedStructWithMethods.unexportedMethod` is unused (unused)
main.go:55:34: func `unusedStructWithMethods.ExportedMethod` is unused (unused)
main.go:25:6: func `fn4` is unused (unused)
main.go:27:6: func `fn5` is unused (unused)
main.go:42:2: field `unexportedField` is unused (unused)
main.go:64:32: func `usedStructWithMethods.unexportedMethod` is unused (unused)
main.go:37:2: field `unusedField` is unused (unused)
main.go:46:6: type `unusedStructWithMethods` is unused (unused)
main.go:29:6: func `fn6` is unused (unused)
main.go:31:6: type `unusedStruct` is unused (unused)

Describe the solution you'd like

  • deprecate varcheck, structcheck, and deadcode.
  • remove varcheck, structcheck, and deadcode from the default linters

Describe alternatives you've considered

  • deprecate varcheck, structcheck, and deadcode.

or

  • remove varcheck, structcheck, and deadcode from the default linters

Additional context

varcheck and structcheck

varcheck and structcheck come from https://github.com/opennota/check.

https://github.com/opennota/check has moved to https://gitlab.com/opennota/check.

And currently, we use a fork https://github.com/golangci/check

The 2 linters are based on the old golang.org/x/tools/go/loader

deadcode

deadcode is also a fork https://github.com/golangci/go-misc

It is based on the old golang.org/x/tools/go/loader

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvementforksWe shall not use forks of linterstopic: cleanupRelated to code, process, or doc cleanup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions