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

--path-prefix and --fix causes wrong file to be attempted opened #3195

Closed
4 tasks done
torkelrogstad opened this issue Sep 6, 2022 · 2 comments
Closed
4 tasks done
Labels
bug Something isn't working

Comments

@torkelrogstad
Copy link

Welcome

  • 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).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

It seems like the --path-prefix and --fix parameters are incompatible. When opening files to auto-fix them the path prefix is applied, which seems incorrect. See the linked output and example repo.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.49.0 built from cc2d97f3 on 2022-08-24T10:24:37Z

Configuration file

$ cat .golangci.yml
linters:
  enable:
    - gofmt

Go environment

$ go version && go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/torkel/Library/Caches/go-build"
GOENV="/Users/torkel/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/torkel/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/torkel/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7_/6snf5h451hv62fr1flgrpcfc0000gn/T/go-build2112860647=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v --path-prefix nested --fix
INFO [config_reader] Config search paths: [./ /Users/torkel/dev/ngu-tek/golangci-lint-test/nested /Users/torkel/dev/ngu-tek/golangci-lint-test /Users/torkel/dev/ngu-tek /Users/torkel/dev /Users/torkel /Users /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 8 linters: [errcheck gofmt gosimple govet ineffassign staticcheck typecheck unused] 
INFO [loader] Go packages loading at mode 575 (files|imports|name|types_sizes|compiled_files|deps|exports_file) took 1.514268788s 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 4.202127ms 
INFO [linters context/goanalysis] analyzers took 713.968288ms with top 10 stages: buildir: 354.234106ms, gofmt: 174.867801ms, ctrlflow: 32.717688ms, printf: 24.774983ms, inspect: 23.402012ms, fact_deprecated: 19.856849ms, SA5012: 19.011276ms, typedness: 18.72946ms, fact_purity: 16.247581ms, nilness: 15.061665ms 
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 1/1, skip_files: 1/1, skip_dirs: 1/1, exclude-rules: 1/1, max_from_linter: 1/1, autogenerated_exclude: 1/1, diff: 1/1, max_per_file_from_linter: 1/1, identifier_marker: 1/1, nolint: 1/1, uniq_by_line: 1/1, source_code: 1/1, path_shortener: 1/1, path_prefixer: 1/1, sort_results: 1/1, cgo: 1/1, path_prettifier: 1/1, exclude: 1/1, max_same_issues: 1/1, severity-rules: 1/1 
INFO [runner] processing took 1.136509ms with stages: identifier_marker: 386.076µs, path_prettifier: 249.212µs, nolint: 178.161µs, autogenerated_exclude: 138.609µs, source_code: 87.739µs, exclude-rules: 31.547µs, skip_dirs: 29.183µs, filename_unadjuster: 11.352µs, cgo: 10.124µs, path_shortener: 2.715µs, max_same_issues: 2.45µs, path_prefixer: 2.068µs, max_from_linter: 1.733µs, uniq_by_line: 1.232µs, skip_files: 1.051µs, max_per_file_from_linter: 934ns, exclude: 620ns, sort_results: 605ns, severity-rules: 561ns, diff: 537ns 
INFO [runner] linters took 1.27840818s with stages: goanalysis_metalinter: 1.275801172s 
ERRO Failed to fix issues in file nested/main.go: failed to get file bytes for nested/main.go: can't read file nested/main.go: open nested/main.go: no such file or directory 
INFO fixer took 58.463µs with stages: all: 58.463µs 
nested/main.go:5: File is not `gofmt`-ed with `-s` (gofmt)


INFO File cache stats: 1 entries of total size 133B 
INFO Memory: 34 samples, avg is 76.0MB, max is 187.6MB 
INFO Execution took 3.252960227s    

Code example or link to a public repository

https://github.com/torkelrogstad/golangci-lint-test

@liufuyang
Copy link

liufuyang commented Sep 15, 2022

Not sure if it is related but we have some tooling that uses golangci-lint 1.49.0 and go1.19.1 and sometimes I ended up getting an error output like this. --path-prefix was also used in the tooling, and if I remove that the problem goes away.

.sage/sagefile.go:5: File is not `gci`-ed with --skip-generated -s standard,default (gci)
"go.einride.tech/sage/sgtool"
.sage/sagefile.go:7: File is not `gci`-ed with --skip-generated -s standard,default (gci)
"go.einride.tech/sage/sg"
[go-lint] exit status 1
make: *** [default] Error 1

@torkelrogstad
Copy link
Author

Closed by #3700

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

No branches or pull requests

2 participants