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

duplicate package and import lines when unused linting error and --fix #967

Closed
3 tasks done
truesilver92 opened this issue Feb 11, 2020 · 7 comments
Closed
3 tasks done
Labels
duplicate This issue or pull request already exists stale No recent correspondence or work activity

Comments

@truesilver92
Copy link

truesilver92 commented Feb 11, 2020

Thank you for creating the issue!

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

Please include the following information:

Version of golangci-lint 1.23.6
$ golangci-lint --version
golangci-lint has version 1.23.6 built from b9eef79 on 2020-02-10T17:54:23Z
Config file
$ cat .golangci.yml
# See: https://github.com/golangci/golangci-lint#config-file
linters:
  enable:
    - gofmt
    - golint
    - gosec
    - lll
    - misspell
    - nakedret
    - stylecheck
    - unconvert
linters-settings:
  misspell:
    locale: US
    ignore-words: []
Go environment
$ go version && go env
go version go1.13.7 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/joel/.cache/go-build"
GOENV="/home/joel/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/joel/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/joel/work/tomahawk/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-build807793369=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/joel/work/tomahawk /home/joel/work /home/joel /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 18 linters: [deadcode errcheck gofmt golint gosec gosimple govet ineffassign lll misspell nakedret staticcheck structcheck stylecheck typecheck unconvert unused varcheck] 
INFO [lintersdb] Active 18 linters: [deadcode errcheck gofmt golint gosec gosimple govet ineffassign lll misspell nakedret staticcheck structcheck stylecheck typecheck unconvert unused varcheck] 
INFO [loader] Go packages loading at mode 575 (compiled_files|deps|name|types_sizes|exports_file|files|imports) took 606.568899ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 4.542894ms 
INFO [runner/unused/goanalysis] analyzers took 0s with no stages 
INFO [runner/goanalysis_metalinter/goanalysis] analyzers took 0s with no stages 
INFO [runner] Issues before processing: 292, after processing: 22 
INFO [runner] Processors filtering stat (out/in): max_per_file_from_linter: 22/22, max_from_linter: 22/22, filename_unadjuster: 292/292, path_prettifier: 292/292, exclude-rules: 34/34, nolint: 33/34, diff: 22/22, autogenerated_exclude: 93/292, max_same_issues: 22/22, source_code: 22/22, cgo: 292/292, skip_files: 292/292, skip_dirs: 292/292, identifier_marker: 93/93, exclude: 34/93, uniq_by_line: 22/33, path_shortener: 22/22 
INFO [runner] processing took 5.568874ms with stages: exclude: 1.776721ms, identifier_marker: 1.742474ms, nolint: 1.181013ms, path_prettifier: 377.908µs, autogenerated_exclude: 193.272µs, skip_dirs: 99.867µs, source_code: 97.172µs, cgo: 36.459µs, filename_unadjuster: 28.834µs, max_same_issues: 14.046µs, uniq_by_line: 7.754µs, max_from_linter: 5.479µs, path_shortener: 4.8µs, max_per_file_from_linter: 2.124µs, skip_files: 490ns, diff: 290ns, exclude-rules: 171ns 
INFO [runner] linters took 85.035574ms with stages: unused: 67.095204ms, goanalysis_metalinter: 12.259104ms 
actions/gql/login_resolver.go:14:7: const `letterBytes` is unused (unused)
config/version.go:22:7: const `defaultRelease` is unused (unused)
config/version.go:24:5: var `versionRegex` is unused (unused)
actions/home.go:12:5: var `loginSource` is unused (unused)
grifts/db.go:9:12: Error return value of `grift.Desc` is not checked (errcheck)
	grift.Desc("seed", "Seeds a database")
	          ^
grifts/db.go:10:11: Error return value of `grift.Add` is not checked (errcheck)
	grift.Add("seed", func(c *grift.Context) error {
	         ^
actions/app.go:78: line is 126 characters (lll)
		loginSource, err := login.New(envy.Get("LOGIN_DSN", "ad://ad2-nvoffice.ec2software.net:636/CN=Users,DC=ec2software,DC=net"))
actions/home.go:16: line is 124 characters (lll)
	loginSource, err = login.New(envy.Get("LOGIN_DSN", "ad://ad2-nvoffice.ec2software.net:636/CN=Users,DC=ec2software,DC=net"))
actions/app.go:115:11: Error return value of `app.Stop` is not checked (errcheck)
		app.Stop(err)
		        ^
actions/app.go:26:5: don't use ALL_CAPS in Go names; use CamelCase (golint)
var BASE_URL = envy.Get("BASE_URL", "http://localhost:3000")
    ^
actions/app.go:27:5: var `BaseUrl` should be `BaseURL` (golint)
var BaseUrl *url.URL
    ^
actions/middleware.go:16:9: `if` block ends with a `return` statement, so drop this `else` and outdent its block (golint)
	} else {
	       ^
models/customer.go:37: line is 134 characters (lll)
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
models/session.go:14:2: struct field `PermissionsJson` should be `PermissionsJSON` (golint)
	PermissionsJson string      `json:"-" db:"permissions"`
	^
models/login/ldap.go:104:2: don't use underscores in Go names; var `group_entries` should be `groupEntries` (golint)
	group_entries, err := conn.Search(fmt.Sprintf("(member:1.2.840.113556.1.4.1941:=%v)", ldap.EscapeFilter(dn)), []string{}, -1)
	^
models/login/login.go:10:6: type name will be used as login.LoginResults by other packages, and that stutters; consider calling this Results (golint)
type LoginResults struct {
     ^
models/login/ldap.go:80: line is 176 characters (lll)
	_, err = conn.SearchOne(fmt.Sprintf("(&(objectCategory=Person)(sAMAccountName=%v)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))", ldap.EscapeFilter(username)), []string{})
actions/gql/helper.go:36:9: `if` block ends with a `return` statement, so drop this `else` and outdent its block (golint)
	} else {
	       ^
actions/gql/login_resolver.go:63:2: naked return in func `Login` with 37 lines of code (nakedret)
	return
	^
actions/gql/scalars.go:14:10: Error return value of `w.Write` is not checked (errcheck)
		w.Write([]byte("\"" + id.String() + "\""))
		       ^
actions/gql/helper.go:35:20: ST1005: error strings should not be capitalized (stylecheck)
		return errors.New("Not logged in")
		                 ^
actions/gql/login_resolver.go:52:6: SA4006: this value of `err` is never used (staticcheck)
	ID, err := uuid.NewV4()
	    ^
INFO File cache stats: 11 entries of total size 16.3KiB 
INFO Memory: 9 samples, avg is 69.4MB, max is 70.9MB 
INFO Execution took 701.227251ms

When running golangci-lint run --fix each of the files that have the linting error unused ends up with a duplicate of the package line and import lines added to the top of the file. If a single file has multiple unused errors then it looks like the package and import lines are duplicated as many times as an unused error is found.

This is probably an error with the underlying linter that golangci-lint calls. Any advice for running the unused linter on the project by itself? I would like to report this issue on the correct project if it doesn't belong here.

@hiromaily
Copy link

+1

@gen0cide
Copy link

+1

I was able to reproduce this issue.

@gen0cide
Copy link

gen0cide commented Mar 9, 2020

Can we get any update on this? I've had to disable --fix

nightah added a commit to authelia/authelia that referenced this issue Apr 6, 2020
In this run the unused linter was disabled due to golangci/golangci-lint#967.
@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale No recent correspondence or work activity label Mar 19, 2021
@stale stale bot closed this as completed Apr 18, 2021
@Gentoli
Copy link

Gentoli commented Jul 12, 2021

This is still broken as of 36aa124
golangci-lint run -v --fix --no-config -E gci --disable-all will still generate duplicated imports

@panter-dsd
Copy link

The bug is still presenting in 1.54.2

@bombsimon
Copy link
Member

Tracking duplicate issue #3230. See linked tickets there fore more context.

@ldez ldez added the duplicate This issue or pull request already exists label Aug 25, 2023
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 stale No recent correspondence or work activity
Projects
None yet
Development

No branches or pull requests

7 participants