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

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

Closed
5 tasks done
udaya2899 opened this issue Aug 29, 2023 · 2 comments
Closed
5 tasks done

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

udaya2899 opened this issue Aug 29, 2023 · 2 comments
Labels
question Further information is requested

Comments

@udaya2899
Copy link

udaya2899 commented Aug 29, 2023

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.).
@udaya2899 udaya2899 added the bug Something isn't working label Aug 29, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 29, 2023

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

@ldez
Copy link
Member

ldez commented Sep 1, 2023

Everything works as expected:

example 1
$ git init rev-binary && cd $_
$ git commit -m "chore: initial empty commit." --allow-empty
[main (root-commit) ff0b5a7] chore: initial empty commit.
$ go mod init github.com/gcl/example 
go: creating new go.mod: module github.com/gcl/example
$ git add .
$ git commit -m "chore: setup project"

$ cat <<EOF > foo.go
package foo

func bar() {
    unusedVariableForTest := 0
}
EOF

$ git add .
$ git commit -m "introduced unused var"

$ golangci-lint run           
foo.go:1: : # github.com/gcl/example
./foo.go:4:5: unusedVariableForTest declared and not used (typecheck)
package foo

$ golangci-lint run --new-from-rev HEAD~1
foo.go:1: : # github.com/gcl/example
./foo.go:4:5: unusedVariableForTest declared and not used (typecheck)
package foo

$ 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
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 9774k  100 9774k    0     0  18.4M      0 --:--:-- --:--:-- --:--:-- 18.4M

$ ./golangci-lint run --new-from-rev HEAD~1
foo.go:1: : # github.com/gcl/example
./foo.go:4:5: unusedVariableForTest declared and not used (typecheck)
package foo
example 2
$ git init rev-binary && cd $_
$ git commit -m "chore: initial empty commit." --allow-empty
[main (root-commit) ff0b5a7] chore: initial empty commit.
$ go mod init github.com/gcl/example 
go: creating new go.mod: module github.com/gcl/example
$ git add .

$ cat <<EOF > foo.go
package foo

func bar() {}
EOF

$ git commit -m "chore: setup project"

$ cat <<EOF > foo.go
package foo

func bar() {
    unusedVariableForTest := 0
}
EOF

$ git add .
$ git commit -m "introduced unused var"

$ golangci-lint run           
foo.go:1: : # github.com/gcl/example
./foo.go:4:5: unusedVariableForTest declared and not used (typecheck)
package foo

$ golangci-lint run --new-from-rev HEAD~1

$ golangci-lint run --new-from-rev HEAD~2
foo.go:1: : # github.com/gcl/example
./foo.go:4:5: unusedVariableForTest declared and not used (typecheck)
package foo

$ 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
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 9774k  100 9774k    0     0  18.4M      0 --:--:-- --:--:-- --:--:-- 18.4M

$ ./golangci-lint run --new-from-rev HEAD~1

$ ./golangci-lint run --new-from-rev HEAD~2
foo.go:1: : # github.com/gcl/example
./foo.go:4:5: unusedVariableForTest declared and not used (typecheck)
package foo

@ldez ldez closed this as completed Sep 1, 2023
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants