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

FAIL: TestSourcesFromTestdata/go-header_bad.go #3682

Closed
4 tasks done
Antonboom opened this issue Mar 12, 2023 · 12 comments
Closed
4 tasks done

FAIL: TestSourcesFromTestdata/go-header_bad.go #3682

Antonboom opened this issue Mar 12, 2023 · 12 comments
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@Antonboom
Copy link
Contributor

Antonboom commented Mar 12, 2023

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 (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

Tests in master fail because of no expected warning from go-header.

The standalone run is silence too:

$ go install github.com/denis-tingaikin/go-header/cmd/go-header@latest
$ go-header version   
v0.4.3

$ cat .go-header.yml
template: MY {{title}}
values:
  const:
    title: TITLE.

$ go-header /Users/anthony/golangci-lint/test/testdata/go-header_bad.go
$ echo "$?"                  
0

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version (devel) built with go1.20.1 from (unknown, mod sum: "") on (unknown)

Configuration file

$ cat .go-header.yml
template: MY {{title}}
values:
  const:
    title: TITLE.

Go environment

$ uname -a            
Darwin MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103 arm64
$ go version && go env
go version go1.20.1 darwin/arm64
GO111MODULE="on"
GOARCH="arm64"
GOBIN="/Users/anthony/golang_workspace/bin"
GOCACHE="/Users/anthony/Library/Caches/go-build"
GOENV="/Users/anthony/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/anthony/golang_workspace/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/anthony/golang_workspace"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/anthony/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6t/v80c8sfs5zqf38b2yhzq592h0000gn/T/go-build2562567091=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

=== RUN   TestSourcesFromTestdata/go-header_bad.go
=== PAUSE TestSourcesFromTestdata/go-header_bad.go
=== CONT  TestSourcesFromTestdata/go-header_bad.go
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test --no-config --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Etypecheck -Etestableexamples testableexamples_test.go] in 783.097458ms"
    linters_test.go:70: 
        	Error Trace:	/Users/anthony/golangci-lint/test/linters_test.go:120
        	            				/Users/anthony/golangci-lint/test/linters_test.go:70
        	Error:      	Not equal: 
        	            	expected: 1
        	            	actual  : 0
        	Test:       	TestSourcesFromTestdata/go-header_bad.go
        	Messages:   	Unexpected exit code: {"Issues":[],"Report":{"Linters":[{"Name":"asasalint"},{"Name":"asciicheck"},{"Name":"bidichk"},{"Name":"bodyclose"},{"Name":"containedctx"},{"Name":"contextcheck"},{"Name":"cyclop"},{"Name":"decorder"},{"Name":"deadcode"},{"Name":"depguard"},{"Name":"dogsled"},{"Name":"dupl"},{"Name":"dupword"},{"Name":"durationcheck"},{"Name":"errcheck","EnabledByDefault":true},{"Name":"errchkjson"},{"Name":"errname"},{"Name":"errorlint"},{"Name":"execinquery"},{"Name":"exhaustive"},{"Name":"exhaustivestruct"},{"Name":"exhaustruct"},{"Name":"exportloopref"},{"Name":"forbidigo"},{"Name":"forcetypeassert"},{"Name":"funlen"},{"Name":"gci"},{"Name":"ginkgolinter"},{"Name":"gocheckcompilerdirectives"},{"Name":"gochecknoglobals"},{"Name":"gochecknoinits"},{"Name":"gocognit"},{"Name":"goconst"},{"Name":"gocritic"},{"Name":"gocyclo"},{"Name":"godot"},{"Name":"godox"},{"Name":"goerr113"},{"Name":"gofmt"},{"Name":"gofumpt"},{"Name":"goheader","Enabled":true},{"Name":"goimports"},{"Name":"golint"},{"Name":"gomnd"},{"Name":"gomoddirectives"},{"Name":"gomodguard"},{"Name":"goprintffuncname"},{"Name":"gosec"},{"Name":"gosimple","EnabledByDefault":true},{"Name":"govet","EnabledByDefault":true},{"Name":"grouper"},{"Name":"ifshort"},{"Name":"importas"},{"Name":"ineffassign","EnabledByDefault":true},{"Name":"interfacebloat"},{"Name":"interfacer"},{"Name":"ireturn"},{"Name":"lll"},{"Name":"loggercheck"},{"Name":"maintidx"},{"Name":"makezero"},{"Name":"maligned"},{"Name":"misspell"},{"Name":"musttag"},{"Name":"nakedret"},{"Name":"nestif"},{"Name":"nilerr"},{"Name":"nilnil"},{"Name":"nlreturn"},{"Name":"noctx"},{"Name":"nonamedreturns"},{"Name":"nosnakecase"},{"Name":"nosprintfhostport"},{"Name":"paralleltest"},{"Name":"prealloc"},{"Name":"predeclared"},{"Name":"promlinter"},{"Name":"reassign"},{"Name":"revive"},{"Name":"rowserrcheck"},{"Name":"scopelint"},{"Name":"sqlclosecheck"},{"Name":"staticcheck","EnabledByDefault":true},{"Name":"structcheck"},{"Name":"stylecheck"},{"Name":"tagliatelle"},{"Name":"tenv"},{"Name":"testableexamples"},{"Name":"testpackage"},{"Name":"thelper"},{"Name":"tparallel"},{"Name":"typecheck","EnabledByDefault":true},{"Name":"unconvert"},{"Name":"unparam"},{"Name":"unused","EnabledByDefault":true},{"Name":"usestdlibvars"},{"Name":"varcheck"},{"Name":"varnamelen"},{"Name":"wastedassign"},{"Name":"whitespace"},{"Name":"wrapcheck"},{"Name":"wsl"},{"Name":"nolintlint"}]}}
    analysis.go:66: go-header_bad.go:1: no diagnostic was reported matching `Expected:TITLE\., Actual: TITLE!`
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test -c configs/lll_import.yml --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Elll lll_multi_import.go] in 517.607ms"
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test -c configs/ireturn_stdlib_reject.yml --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Eireturn ireturn_reject_stdlib.go] in 498.444459ms"
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test -c configs/lll.yml --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Elll lll.go] in 602.801166ms"
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test --no-config --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Eireturn ireturn_default.go] in 446.485458ms"
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test -c configs/ireturn.yml --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Eireturn ireturn_allow.go] in 442.368083ms"
level=info msg="[test] ran [/Users/anthony/golangci-lint/golangci-lint run --go=1.17 --internal-cmd-test -c configs/lll_import.yml --allow-parallel-runners --disable-all --out-format=json --max-same-issues=100 -Etypecheck -Elll lll_multi_import.go] in 325.737041ms"
    linters_test.go:70: 
        	Error Trace:	/Users/anthony/golangci-lint/test/linters_test.go:120
        	            				/Users/anthony/golangci-lint/test/linters_test.go:70
        	Error:      	Not equal: 
        	            	expected: 1
        	            	actual  : 0
        	Test:       	TestSourcesFromTestdata/go-header_bad.go
        	Messages:   	Unexpected exit code: {"Issues":[],"Report":{"Linters":[{"Name":"asasalint"},{"Name":"asciicheck"},{"Name":"bidichk"},{"Name":"bodyclose"},{"Name":"containedctx"},{"Name":"contextcheck"},{"Name":"cyclop"},{"Name":"decorder"},{"Name":"deadcode"},{"Name":"depguard"},{"Name":"dogsled"},{"Name":"dupl"},{"Name":"dupword"},{"Name":"durationcheck"},{"Name":"errcheck","EnabledByDefault":true},{"Name":"errchkjson"},{"Name":"errname"},{"Name":"errorlint"},{"Name":"execinquery"},{"Name":"exhaustive"},{"Name":"exhaustivestruct"},{"Name":"exhaustruct"},{"Name":"exportloopref"},{"Name":"forbidigo"},{"Name":"forcetypeassert"},{"Name":"funlen"},{"Name":"gci"},{"Name":"ginkgolinter"},{"Name":"gocheckcompilerdirectives"},{"Name":"gochecknoglobals"},{"Name":"gochecknoinits"},{"Name":"gocognit"},{"Name":"goconst"},{"Name":"gocritic"},{"Name":"gocyclo"},{"Name":"godot"},{"Name":"godox"},{"Name":"goerr113"},{"Name":"gofmt"},{"Name":"gofumpt"},{"Name":"goheader","Enabled":true},{"Name":"goimports"},{"Name":"golint"},{"Name":"gomnd"},{"Name":"gomoddirectives"},{"Name":"gomodguard"},{"Name":"goprintffuncname"},{"Name":"gosec"},{"Name":"gosimple","EnabledByDefault":true},{"Name":"govet","EnabledByDefault":true},{"Name":"grouper"},{"Name":"ifshort"},{"Name":"importas"},{"Name":"ineffassign","EnabledByDefault":true},{"Name":"interfacebloat"},{"Name":"interfacer"},{"Name":"ireturn"},{"Name":"lll"},{"Name":"loggercheck"},{"Name":"maintidx"},{"Name":"makezero"},{"Name":"maligned"},{"Name":"misspell"},{"Name":"musttag"},{"Name":"nakedret"},{"Name":"nestif"},{"Name":"nilerr"},{"Name":"nilnil"},{"Name":"nlreturn"},{"Name":"noctx"},{"Name":"nonamedreturns"},{"Name":"nosnakecase"},{"Name":"nosprintfhostport"},{"Name":"paralleltest"},{"Name":"prealloc"},{"Name":"predeclared"},{"Name":"promlinter"},{"Name":"reassign"},{"Name":"revive"},{"Name":"rowserrcheck"},{"Name":"scopelint"},{"Name":"sqlclosecheck"},{"Name":"staticcheck","EnabledByDefault":true},{"Name":"structcheck"},{"Name":"stylecheck"},{"Name":"tagliatelle"},{"Name":"tenv"},{"Name":"testableexamples"},{"Name":"testpackage"},{"Name":"thelper"},{"Name":"tparallel"},{"Name":"typecheck","Enabled":true,"EnabledByDefault":true},{"Name":"unconvert"},{"Name":"unparam"},{"Name":"unused","EnabledByDefault":true},{"Name":"usestdlibvars"},{"Name":"varcheck"},{"Name":"varnamelen"},{"Name":"wastedassign"},{"Name":"whitespace"},{"Name":"wrapcheck"},{"Name":"wsl"},{"Name":"nolintlint"}]}}
    analysis.go:66: go-header_bad.go:1: no diagnostic was reported matching `Expected:TITLE\., Actual: TITLE!`
    --- FAIL: TestSourcesFromTestdata/go-header_bad.go (0.97s)


Expected :1
Actual   :0
<Click to see difference>
@Antonboom Antonboom added bug Something isn't working dependencies Relates to an upstream dependency labels Mar 12, 2023
@Antonboom
Copy link
Contributor Author

@denis-tingaikin FYI

@ldez
Copy link
Member

ldez commented Mar 12, 2023

Tests in master fail because of no expected warning from go-header.

I want to be precise: the tests don't fail on the branch master in our CI.

So I think you are saying that locally the tests are failing.

@Antonboom
Copy link
Contributor Author

Antonboom commented Mar 12, 2023

Yes, sorry, of course I am about local running.
I suspect my OS or version of Go...

$ git status                                                           
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .go-header.yml

$ git log -n 1
commit c6231164ade6daa377a08ba2cbd7479302d71404 (HEAD -> master, origin/master, origin/HEAD)
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sun Mar 12 13:14:48 2023 +0100

    build(deps): bump github.com/Antonboom/nilnil from 0.1.2 to 0.1.3 (#3679)

$ make test | grep FAIL
--- FAIL: TestSourcesFromTestdata (0.00s)
    --- FAIL: TestSourcesFromTestdata/go-header_bad.go (0.35s)
FAIL
FAIL    github.com/golangci/golangci-lint/test  66.131s
FAIL
make: *** [test] Error 1

@ldez
Copy link
Member

ldez commented Mar 12, 2023

I think I find the bug but I'm not sure for now:

https://github.com/denis-tingaikin/go-header/blob/663afa48e79cbf9a95ac4f49f6bdb611ba366cde/analyzer.go#L60

-		if t.Year() != time.Now().Year() {
+		if t.UTC().Year() >= time.Now().UTC().Year() {

@ldez
Copy link
Member

ldez commented Mar 12, 2023

I think the bug has been described here: denis-tingaikin/go-header#22

It's coming from this commit denis-tingaikin/go-header@97ef360 and it was related to this issue denis-tingaikin/go-header#5

@ldez
Copy link
Member

ldez commented Mar 12, 2023

My change makes the linter work but IMO the real fix is to remove the check.

It fixes the problem for me locally, @Antonboom can you try it also?

-	if t, err := target.ModTime(); err == nil {
-		if t.Year() != time.Now().Year() {
-			return nil
-		}
-	}

https://github.com/denis-tingaikin/go-header/blob/663afa48e79cbf9a95ac4f49f6bdb611ba366cde/analyzer.go#L59-L63

T=go-header_bad.go make test_linters

@Antonboom
Copy link
Contributor Author

It fixes the problem for me locally, @Antonboom can you try it also?

Yes, it helps 👍
But please look at my comment in related issue.

@mateusoliveira43
Copy link
Contributor

@ldez how/what should someone change to make test succeed locally?

I changed the test/testdata/go-header_bad.go file to trigger the linter

Could the code generate that file at test run time (adding it to .gitignore), so it will always trigger the linter?

@ldez
Copy link
Member

ldez commented Dec 23, 2023

@mateusoliveira43 It's not a problem inside golangci-lint, please read the thread.

@denis-tingaikin
Copy link
Member

I've provided a fix for the root cause: denis-tingaikin/go-header#39

Am going to merge the fix next Sunday, so please feel free to add comments or thoughts.

@ldez
Copy link
Member

ldez commented Feb 18, 2024

🎉 denis-tingaikin/go-header#39 (review)

Thank you ❤️

@ldez
Copy link
Member

ldez commented Mar 2, 2024

Fixed by #4396

@ldez ldez closed this as completed Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

No branches or pull requests

4 participants