Skip to content

unused linter does not detect unused exported fields #4969

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

Closed
6 of 7 tasks
mcastorina opened this issue Aug 31, 2024 · 2 comments
Closed
6 of 7 tasks

unused linter does not detect unused exported fields #4969

mcastorina opened this issue Aug 31, 2024 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@mcastorina
Copy link

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

Description of the problem

The unused linter does not detect unused exported struct members when "exported-fields-are-used" configuration is set to false.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c on 2024-08-22T21:45:24Z

Configuration

--config <(echo '{"linters-settings":{"unused":{"exported-fields-are-used":false}}}')

this is equivalent to the yaml config

linter-settings:
  unused:
    exported-fields-are-used: false

Go environment

$ go version && go env
go version go1.23.0 darwin/arm64
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.23.0/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.23.0/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/s2/32jxgw6j2tl3lr6q7_p_0_th0000gn/T/go-build3082553639=/tmp/go-build -gno-record-gcc-switches -fno-common'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run --config <(echo '{"linters-settings":{"unused":{"exported-fields-are-used":false}}}') blah.go -v
INFO golangci-lint has version 1.60.3 built with go1.23.0 from c2e095c on 2024-08-22T21:45:24Z
INFO [config_reader] Used config file ../../dev/fd/11
INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused]
INFO [loader] Go packages loading at mode 575 (files|types_sizes|exports_file|deps|imports|name|compiled_files) took 67.919958ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 126.334µs
INFO [linters_context/goanalysis] analyzers took 853.935539ms with top 10 stages: buildir: 636.946627ms, printf: 33.912087ms, SA5012: 29.531086ms, ctrlflow: 29.333536ms, fact_deprecated: 27.19442ms, inspect: 26.515128ms, nilness: 23.992833ms, fact_purity: 23.913584ms, typedness: 19.195332ms, tokenfileanalyzer: 2.332332ms
INFO [runner] processing took 2.086µs with stages: max_same_issues: 375ns, filename_unadjuster: 208ns, skip_dirs: 167ns, identifier_marker: 167ns, nolint: 167ns, path_prettifier: 125ns, skip_files: 125ns, source_code: 125ns, cgo: 125ns, invalid_issue: 125ns, path_shortener: 42ns, uniq_by_line: 42ns, fixer: 42ns, max_per_file_from_linter: 42ns, autogenerated_exclude: 42ns, diff: 42ns, exclude: 42ns, max_from_linter: 42ns, sort_results: 41ns, path_prefixer: 0s, exclude-rules: 0s, severity-rules: 0s
INFO [runner] linters took 581.634083ms with stages: goanalysis_metalinter: 581.611875ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 8 samples, avg is 150.9MB, max is 231.2MB
INFO Execution took 657.469ms

A minimal reproducible example or link to a public repository

package main

import "fmt"

type Foo struct {
	Bar string
	Baz string
}

func main() {
	f := Foo{}
	fmt.Println(f.Baz)
}

Please note: if you unexport Bar, the linter works as expected.

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@mcastorina mcastorina added the bug Something isn't working label Aug 31, 2024
Copy link

boring-cyborg bot commented Aug 31, 2024

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

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Aug 31, 2024
@ldez
Copy link
Member

ldez commented Aug 31, 2024

duplicate of #4218

@ldez ldez closed this as completed Aug 31, 2024
@ldez ldez added duplicate This issue or pull request already exists and removed question Further information is requested labels Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants