Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structcheck doesn't detect unused fields #1695

Closed
krasi-georgiev opened this issue Feb 6, 2021 · 4 comments
Closed

structcheck doesn't detect unused fields #1695

krasi-georgiev opened this issue Feb 6, 2021 · 4 comments
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@krasi-georgiev
Copy link

krasi-georgiev commented Feb 6, 2021

$ golangci-lint --version
golangci-lint has version v1.36.1-0.20210201221353-60455b502b0b built from (unknown, mod sum: "h1:3s0UVAF/vBuyquXpqfB7udcV+BdJiu0vg+WKxcR6mFg=") on (unknown)```

Config and code is in the repo.
https://github.com/tellor-io/telliot/tree/684f7a33c4871b3d9e7824f6c448f89aac8bda23

Problem is that Password field is definitely unused, but structcheck doesn't report this.
https://github.com/tellor-io/telliot/blob/684f7a33c4871b3d9e7824f6c448f89aac8bda23/pkg/config/config.go#L85

Go env
$ go version && go env
go version go1.15.7 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/krasi/.cache/go-build"
GOENV="/home/krasi/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/krasi/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/krasi"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/krasi/src/github.com/tellor-io/telliot/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build006005362=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/krasi/src/github.com/tellor-io/telliot /home/krasi/src/github.com/tellor-io /home/krasi/src/github.com /home/krasi/src /home/krasi /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 17 linters: [deadcode errcheck exportloopref goconst godot gofmt goimports gosimple govet ineffassign misspell staticcheck structcheck typecheck unparam unused varcheck] 
INFO [loader] Go packages loading at mode 575 (deps|imports|compiled_files|files|name|types_sizes|exports_file) took 441.981306ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 24.113292ms 
INFO [linters context/goanalysis] analyzers took 58.767260452s with top 10 stages: buildir: 31.434209053s, buildssa: 4.867688357s, goimports: 3.385716333s, ineffassign: 2.225159868s, inspect: 1.827348229s, misspell: 1.471122671s, gofmt: 1.430827037s, ctrlflow: 932.446372ms, godot: 854.469145ms, printf: 799.374609ms 
INFO [linters context/goanalysis] analyzers took 1.790821627s with top 10 stages: buildir: 1.380523691s, U1000: 410.297936ms 
INFO [runner] Issues before processing: 1358, after processing: 0 
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 1358/1358, identifier_marker: 15/15, nolint: 0/1, skip_dirs: 1358/1358, exclude: 15/15, exclude-rules: 1/15, autogenerated_exclude: 15/1358, cgo: 1358/1358, path_prettifier: 1358/1358, skip_files: 1358/1358 
INFO [runner] processing took 3.17687ms with stages: path_prettifier: 1.096669ms, autogenerated_exclude: 804.423µs, nolint: 322.972µs, skip_dirs: 316.782µs, identifier_marker: 276.415µs, exclude-rules: 193.036µs, cgo: 88.261µs, filename_unadjuster: 71.322µs, max_same_issues: 2µs, diff: 1.064µs, uniq_by_line: 875ns, severity-rules: 543ns, source_code: 458ns, max_from_linter: 411ns, sort_results: 409ns, skip_files: 331ns, exclude: 305ns, path_shortener: 277ns, max_per_file_from_linter: 179ns, path_prefixer: 138ns 
INFO [runner] linters took 10.871170771s with stages: goanalysis_metalinter: 10.012745442s, unused: 855.108401ms 
INFO File cache stats: 96 entries of total size 1.7MiB 
INFO Memory: 112 samples, avg is 701.3MB, max is 946.0MB 
INFO Execution took 11.346133708s
@krasi-georgiev krasi-georgiev added the bug Something isn't working label Feb 6, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 6, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez added the dependencies Relates to an upstream dependency label Mar 21, 2021
@krasi-georgiev
Copy link
Author

closing for no activity

@bombsimon
Copy link
Member

Did you configure the linter to also check and report exported fields?

type StructCheckSettings struct {
CheckExportedFields bool `mapstructure:"exported-fields"`
}

$ golangci-lint version
golangci-lint has version 1.43.0 built from 861262b7 on 2021-11-03T11:57:46Z

main.go

package main

type Foo struct {
        private string
        Public  string
}

func main() {
        _ = &Foo{}
}

.golangci.yml

linters-settings:
  structcheck:
    exported-fields: true
$ golangci-lint run
main.go:4:2: `private` is unused (structcheck)
        private string
        ^
main.go:5:2: `Public` is unused (structcheck)
        Public  string
        ^

@krasi-georgiev
Copy link
Author

yep that worked, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

No branches or pull requests

3 participants