Skip to content

--new-from-rev not working in binary installation #4047

Closed
@udaya2899

Description

@udaya2899

Welcome

Description of the problem

--new-from-rev doesn't work now

Version of golangci-lint

Downloaded as binary from releases

$ ./golangci-lint --version
# 1.54.2

Configuration

No configuration file

--new-from-rev <sha of 1 commit before HEAD>

Go environment

$ go version && go env
go version go1.20.7 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/builder/.cache/go-build"
GOENV="/home/builder/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.7"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspaces/<our private repo>/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-build2655292750=/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: [./ /workspaces/x /workspaces / /home/builder] 
INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused] 
INFO [loader] Go packages loading at mode 575 (compiled_files|files|imports|name|types_sizes|deps|exports_file) took 444.889053ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.387188ms 
INFO [linters_context/goanalysis] analyzers took 50.516927333s with top 10 stages: buildir: 42.640125989s, inspect: 1.394087802s, nilness: 1.371334261s, fact_purity: 1.01653602s, fact_deprecated: 1.01260606s, printf: 776.098741ms, ctrlflow: 642.379757ms, typedness: 492.101684ms, SA5012: 340.890058ms, S1039: 53.534545ms 
INFO [runner] Issues before processing: 170, after processing: 1 
INFO [runner] Processors filtering stat (out/in): identifier_marker: 170/170, max_per_file_from_linter: 1/1, sort_results: 1/1, nolint: 169/169, severity-rules: 1/1, path_prettifier: 170/170, skip_dirs: 170/170, uniq_by_line: 1/169, source_code: 1/1, path_shortener: 1/1, cgo: 170/170, filename_unadjuster: 170/170, skip_files: 170/170, autogenerated_exclude: 170/170, exclude: 170/170, exclude-rules: 169/170, diff: 1/1, max_same_issues: 1/1, max_from_linter: 1/1, fixer: 1/1, path_prefixer: 1/1 
INFO [runner] processing took 31.828259ms with stages: exclude-rules: 26.156268ms, identifier_marker: 5.237579ms, nolint: 196.997µs, path_prettifier: 89.817µs, skip_dirs: 62.236µs, autogenerated_exclude: 31.399µs, source_code: 17.142µs, uniq_by_line: 14.838µs, cgo: 7.595µs, filename_unadjuster: 7.184µs, max_same_issues: 2.646µs, path_shortener: 1.613µs, max_from_linter: 761ns, max_per_file_from_linter: 571ns, exclude: 300ns, fixer: 262ns, severity-rules: 260ns, sort_results: 241ns, skip_files: 240ns, diff: 210ns, path_prefixer: 100ns 
INFO [runner] linters took 10.432170175s with stages: goanalysis_metalinter: 10.400243905s 
repo/package/file/path.go:1 #github.com/org/repo/package [github.com/org/repo/package.test]
repo/package/file/path.go:17:2: unusedVariableForTest declared and not used (typecheck)(typecheck)
package main
INFO File cache stats: 1 entries of total size 1.6KiB 
INFO Memory: 109 samples, avg is 738.5MB, max is 1267.3MB 
INFO Execution took 10.88257206s                  
$ git diff HEAD~1
diff --git a/repo/package/file/path.go b/repo/package/file/path.go
index oldSha..newSha 100644
--- a/repo/package/file/path.gp
+++ b/repo/package/file/path.go
  func funcName(str string) string {
+       unusedVariableForTest := 0
         <other irrelevant code here>

$ ./golangci-lint cache clean
$ ./golangci-lint run --new-from-rev HEAD~1 -v
INFO [config_reader] Config search paths: [./ /workspaces/x /workspaces / /home/builder] 
INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused] 
INFO [loader] Go packages loading at mode 575 (name|deps|files|imports|types_sizes|compiled_files|exports_file) took 234.057411ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.462167ms 
INFO [linters_context/goanalysis] analyzers took 49.60073403s with top 10 stages: buildir: 42.919947061s, inspect: 1.410713721s, nilness: 1.404110569s, fact_purity: 783.177257ms, fact_deprecated: 706.999347ms, ctrlflow: 641.028833ms, printf: 579.142204ms, typedness: 435.931209ms, SA5012: 328.896903ms, SA1008: 28.322811ms 
INFO [runner] Issues before processing: 170, after processing: 0 
INFO [runner] Processors filtering stat (out/in): cgo: 170/170, path_prettifier: 170/170, exclude-rules: 169/170, skip_files: 170/170, autogenerated_exclude: 170/170, exclude: 170/170, diff: 0/1, skip_dirs: 170/170, identifier_marker: 170/170, nolint: 169/169, uniq_by_line: 1/169, filename_unadjuster: 170/170 
INFO [runner] processing took 46.065829ms with stages: exclude-rules: 26.375165ms, diff: 13.959318ms, identifier_marker: 5.270781ms, nolint: 227.996µs, path_prettifier: 94.285µs, skip_dirs: 65.071µs, autogenerated_exclude: 34.905µs, cgo: 13.394µs, uniq_by_line: 12.363µs, filename_unadjuster: 8.536µs, max_same_issues: 1.112µs, sort_results: 650ns, fixer: 351ns, max_per_file_from_linter: 320ns, skip_files: 300ns, path_shortener: 280ns, severity-rules: 261ns, exclude: 231ns, max_from_linter: 230ns, source_code: 190ns, path_prefixer: 90ns 
INFO [runner] linters took 10.462992366s with stages: goanalysis_metalinter: 10.416826255s 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 109 samples, avg is 783.2MB, max is 1391.2MB 
INFO Execution took 10.702400207s      

A minimal reproducible example or link to a public repository

First make an undesirable change that introduces a linting error

package foo

func bar() {
    unusedVariableForTest := 0
}

Commit it with

$ git commit -m "introduced unused var"
$ curl -Lf https://github.com/golangci/golangci-lint/releases/download/v1.54.2/golangci-lint-1.54.2-linux-amd64.tar.gz | tar xz -C . --strip-components=1 && chmod +x ./golangci-lint
$ ./golangci-lint run --new-from-rev HEAD~1 -v

The expected unusedVar error doesn't show up in --new-from-rev neither with HEAD~1 nor with HEAD~2 and also not with explicitly using a long SHA of 1 or 2 commits before. But they show up when running on the whole repo without --new-from-rev.

Validation

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions