golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.65k stars 1.39k forks source link

--new/--new-from-rev flags don't work with custom differ #4060

Closed dan-smetana closed 1 year ago

dan-smetana commented 1 year ago

Welcome

Description of the problem

I use difftastic as my custom diff tool (set as diff.external). This prevents golangci-lint's --new/--new-from-rev flags from functioning because my git diff output differs from the regular one. Fortunately, this can be easily fixed by passing a flag telling git not to use custom diff tools (--no-ext-diff). I've created a PR for revgrep that does exactly that: https://github.com/golangci/revgrep/pull/7

Recompiling golangci-lint with replace github.com/golangci/revgrep => github.com/danielslee/revgrep v0.0.0-20230828115018-3e4edc4a761e added to go.mod fixes the issue for me.

Can anyone look at the PR and merge it if possible?

Version of golangci-lint

```console $ golangci-lint --version golangci-lint has version 1.54.2 built with go1.21.0 from 411e0bbb on 2023-08-21T12:04:32Z ```

Configuration

```console golangci-lint run --new ```

Go environment

```console $ go version && go env go version go1.20.6 linux/amd64 GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/var/home/daniel/.cache/go-build" GOENV="/var/home/daniel/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/var/home/daniel/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/var/home/daniel/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/nix/store/l9n531fcx4grk3wvfbigya3p66scj61h-go-1.20.6/share/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/nix/store/l9n531fcx4grk3wvfbigya3p66scj61h-go-1.20.6/share/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.6" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/var/home/daniel/projects/golangci-lint/go.mod" 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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3995759777=/tmp/go-build -gno-record-gcc-switches" ```

Verbose output of running

```console $ golangci-lint cache clean $ golangci-lint run -v 4s INFO [config_reader] Config search paths: [./ /var/home/daniel/projects/golangci-lint /var/home/daniel/projects /var/home/daniel /var/home /var /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 31 linters: [bodyclose depguard dogsled dupl errcheck exportloopref funlen gochecknoinits goconst gocritic gocyclo gofmt goimports gomnd goprintffuncname gosec gosimple govet ineffassign lll misspell nakedret noctx nolintlint revive staticcheck stylecheck unconvert unparam unused whitespace] INFO [loader] Go packages loading at mode 575 (name|exports_file|files|imports|types_sizes|compiled_files|deps) took 172.062307ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 7.452607ms INFO [linters_context/goanalysis] analyzers took 19.519134399s with top 10 stages: gocritic: 12.895139816s, gosec: 610.314938ms, buildir: 605.779912ms, buildssa: 456.644902ms, goimports: 323.914061ms, dupl: 281.917519ms, gofmt: 220.392366ms, unparam: 137.080152ms, unused: 135.733579ms, S1038: 130.678959ms INFO [runner/skip_dirs] Skipped 18 issues from dir internal/renameio by pattern internal/renameio INFO [runner/skip_dirs] Skipped 79 issues from dir internal/cache by pattern internal/cache INFO [runner/skip_dirs] Skipped 2 issues from dir internal/robustio by pattern internal/robustio INFO [runner/skip_dirs] Skipped 2 issues from dir test/testdata_etc/abspath by pattern test/testdata_etc INFO [runner/skip_dirs] Skipped 1 issues from dir test/testdata_etc/unused_exported/lib by pattern test/testdata_etc INFO [runner] Issues before processing: 749, after processing: 1 INFO [runner] Processors filtering stat (out/in): path_shortener: 1/1, severity-rules: 1/1, cgo: 749/749, path_prettifier: 749/749, identifier_marker: 647/647, nolint: 214/399, max_same_issues: 1/1, source_code: 1/1, path_prefixer: 1/1, filename_unadjuster: 749/749, skip_dirs: 647/749, autogenerated_exclude: 647/647, exclude: 647/647, diff: 1/1, sort_results: 1/1, exclude-rules: 399/647, uniq_by_line: 1/214, max_per_file_from_linter: 1/1, max_from_linter: 1/1, fixer: 1/1, skip_files: 749/749 INFO [runner] processing took 30.685434ms with stages: exclude-rules: 16.126647ms, nolint: 7.472753ms, identifier_marker: 4.414998ms, path_prettifier: 1.350313ms, autogenerated_exclude: 1.075018ms, skip_dirs: 184.954µs, cgo: 25.369µs, filename_unadjuster: 15.696µs, source_code: 9.019µs, uniq_by_line: 6.672µs, max_same_issues: 1.222µs, path_shortener: 723ns, max_from_linter: 472ns, max_per_file_from_linter: 317ns, exclude: 304ns, fixer: 253ns, skip_files: 203ns, severity-rules: 190ns, sort_results: 155ns, diff: 90ns, path_prefixer: 66ns INFO [runner] linters took 2.560594624s with stages: goanalysis_metalinter: 2.529871747s cmd/golangci-lint/main.go:1: : # github.com/golangci/golangci-lint/cmd/golangci-lint cmd/golangci-lint/main.go:22:9: unused declared and not used (typecheck) package main INFO File cache stats: 270 entries of total size 718.4KiB INFO Memory: 29 samples, avg is 720.4MB, max is 940.3MB INFO Execution took 2.74326455s $ golangci-lint run -v --new INFO [config_reader] Config search paths: [./ /var/home/daniel/projects/golangci-lint /var/home/daniel/projects /var/home/daniel /var/home /var /] INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 31 linters: [bodyclose depguard dogsled dupl errcheck exportloopref funlen gochecknoinits goconst gocritic gocyclo gofmt goimports gomnd goprintffuncname gosec gosimple govet ineffassign lll misspell nakedret noctx nolintlint revive staticcheck stylecheck unconvert unparam unused whitespace] INFO [loader] Go packages loading at mode 575 (deps|exports_file|files|name|types_sizes|compiled_files|imports) took 934.865417ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 6.847528ms INFO [linters_context/goanalysis] analyzers took 18.435084303s with top 10 stages: gocritic: 12.781307852s, buildir: 709.353212ms, gosec: 508.318534ms, buildssa: 349.076686ms, goimports: 240.937472ms, gofmt: 178.842058ms, dupl: 177.182692ms, S1038: 120.975454ms, unparam: 93.888317ms, unused: 91.604127ms INFO [runner/skip_dirs] Skipped 18 issues from dir internal/renameio by pattern internal/renameio INFO [runner/skip_dirs] Skipped 79 issues from dir internal/cache by pattern internal/cache INFO [runner/skip_dirs] Skipped 2 issues from dir internal/robustio by pattern internal/robustio INFO [runner/skip_dirs] Skipped 2 issues from dir test/testdata_etc/abspath by pattern test/testdata_etc INFO [runner/skip_dirs] Skipped 1 issues from dir test/testdata_etc/unused_exported/lib by pattern test/testdata_etc INFO [runner] Issues before processing: 749, after processing: 0 INFO [runner] Processors filtering stat (out/in): cgo: 749/749, filename_unadjuster: 749/749, exclude-rules: 399/647, nolint: 214/399, skip_files: 749/749, skip_dirs: 647/749, exclude: 647/647, uniq_by_line: 1/214, diff: 0/1, path_prettifier: 749/749, autogenerated_exclude: 647/647, identifier_marker: 647/647 INFO [runner] processing took 77.575312ms with stages: diff: 45.659095ms, exclude-rules: 16.921268ms, nolint: 7.574441ms, identifier_marker: 4.784369ms, path_prettifier: 1.351615ms, autogenerated_exclude: 1.049343ms, skip_dirs: 183.896µs, cgo: 24.967µs, filename_unadjuster: 16.153µs, uniq_by_line: 6.705µs, max_same_issues: 1.114µs, fixer: 522ns, skip_files: 373ns, sort_results: 283ns, max_per_file_from_linter: 216ns, exclude: 207ns, source_code: 189ns, severity-rules: 173ns, max_from_linter: 171ns, path_shortener: 150ns, path_prefixer: 62ns INFO [runner] linters took 2.738648291s with stages: goanalysis_metalinter: 2.661030219s INFO File cache stats: 269 entries of total size 717.5KiB INFO Memory: 38 samples, avg is 584.6MB, max is 1006.2MB INFO Execution took 3.684407023s ```

Golangci-lint run -v works fine. Golangci-lint run -v --new doesn't -- the issue doesn't show up. It does work fine if I remove my custom diff.external git setting.

A minimal reproducible example or link to a public repository

Any repo. https://github.com/golangci/golangci-lint will do. Make some changes that trigger a warning and then use --new or --new-from-rev=master.

Validation

boring-cyborg[bot] commented 1 year ago

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