Skip to content

Built-in govet and golint can't parse quicktemplate output, standalone versions can #316

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

Closed
aaron42net opened this issue Dec 7, 2018 · 3 comments
Labels
area: cgo Related to CGO or line directives bug Something isn't working

Comments

@aaron42net
Copy link

When using a template code generator called quicktemplate (https://github.com/valyala/quicktemplate), golangci-lint's govet and golint linters can't parse the generated output, though go vet and golint work fine.

I've created a tiny git repo that illustrates the interaction. See: https://github.com/aaron42net/glci-demo

Here's the result of running the steps in the README:

$ golint ./...
templates/partials/partials/foo.qtpl:3:1: exported function StreamFoo should have comment or be unexported
templates/partials/partials/foo.qtpl:5:1: exported function Foo should have comment or be unexported
templates/partials/partials/foo.qtpl:5:1: exported function WriteFoo should have comment or be unexported
templates/partials/partials/foo.qtpl:7:1: comment on exported function Bar should be of the form "Bar ..."
$ go vet ./...
# github.com/aaron42net/glci-demo/templates/partials
templates/partials/partials/foo.qtpl:11: Printf format %s has arg 345 of wrong type int
$ golangci-lint run --no-config --disable-all -E golint -E govet
WARN [runner] Can't run linter golint: no AST for file /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/foo.qtpl.go in cache: {m:map[/home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/partials/foo.qtpl:0xc423aa6d20 /home/aaron/go/src/github.com/aaron42net/glci-demo/main.go:0xc423aa6d50 /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/templates.go:0xc423aa6d80] s:[0xc423aa6d50 0xc423aa6d80 0xc423aa6d20] log:{rd:0xc420040360 tags:[loader astcache] origLog:0xc423aa4800}} 
WARN [runner] Can't run linter govet: can't eval symlinks for path /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/partials/foo.qtpl: lstat /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/partials: no such file or directory 

Let me know if you need more info. Thanks!
-- Aaron

Please include the following information:

  1. Version of golangci-lint: golangci-lint --version (or git commit if you don't use binary distribution)

Git commit is current master: ef7864383087163c1330f90342b6a5887e847c37

  1. Config file: cat .golangci.yml

Running with no config: golangci-lint -v run --no-config --disable-all -E golint -E govet

  1. Go environment: go version && go env
go version go1.10.3 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/aaron/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aaron/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build641986617=/tmp/go-build -gno-record-gcc-switches"
  1. Verbose output of running: golangci-lint run -v
$ golangci-lint -v run --no-config --disable-all -E golint -E govet
INFO Gocritic enabled checks: [appendAssign assignOp caseOrder dupArg dupBranchBody dupCase flagDeref ifElseChain regexpMust singleCaseSwitch sloppyLen switchTrue typeSwitchVar underef unlambda unslice defaultCaseOrder] 
INFO [lintersdb] Active 2 linters: [golint govet] 
INFO [loader] Go packages loading at mode load types and syntax took 408.066946ms 
INFO [runner] worker.18 took 4.697µs              
INFO [runner] worker.19 took 7.245µs              
INFO [runner] worker.20 took 1.773µs              
INFO [runner] worker.14 took 5.8µs                
INFO [runner] worker.7 took 4.574µs               
INFO [runner] worker.6 took 2.218µs               
INFO [runner] worker.23 took 1.413µs              
INFO [runner] worker.11 took 2.332µs              
INFO [runner] worker.22 took 1.37µs               
INFO [runner] worker.12 took 2.107µs              
INFO [runner] worker.9 took 1.687µs               
INFO [runner] worker.8 took 4.44µs                
INFO [runner] worker.2 took 2.307µs               
INFO [runner] worker.24 took 4.328µs              
INFO [runner] worker.3 took 1.825µs               
INFO [runner] worker.21 took 1.92µs               
INFO [runner] worker.15 took 2.345µs              
INFO [runner] worker.17 took 1.535µs              
INFO [runner] worker.13 took 1.835µs              
INFO [runner] worker.1 took 1.837µs               
INFO [runner] worker.4 took 1.417µs               
INFO [runner] worker.16 took 1.923µs              
INFO [runner] worker.10 took 706.908µs with stages: golint: 685.518µs 
WARN [runner] Can't run linter golint: no AST for file /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/foo.qtpl.go in cache: {m:map[/home/aaron/go/src/github.com/aaron42net/glci-demo/main.go:0xc4239756e0 /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/templates.go:0xc423975710 /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/partials/foo.qtpl:0xc423975740] s:[0xc4239756e0 0xc423975710 0xc423975740] log:{rd:0xc420040360 tags:[loader astcache] origLog:0xc423978be0}} 
INFO [runner] worker.5 took 3.173777ms with stages: govet: 3.151315ms 
WARN [runner] Can't run linter govet: can't eval symlinks for path /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/partials/foo.qtpl: lstat /home/aaron/go/src/github.com/aaron42net/glci-demo/templates/partials/partials: no such file or directory 
INFO [runner] Workers idle times: #1: 2.818577ms, #2: 2.909626ms, #3: 2.890309ms, #4: 2.812481ms, #6: 3.016928ms, #7: 3.02526ms, #8: 2.938023ms, #9: 2.945976ms, #10: 2.464579ms, #11: 2.982397ms, #12: 2.95158ms, #13: 2.824411ms, #14: 3.03542ms, #15: 2.856895ms, #16: 2.806677ms, #17: 2.850766ms, #18: 3.098844ms, #19: 3.068532ms, #20: 3.057092ms, #21: 2.883212ms, #22: 2.956468ms, #23: 2.989744ms, #24: 2.899334ms 
INFO [runner] processing took 7.524µs with stages: max_same_issues: 1.68µs, path_prettifier: 785ns, skip_dirs: 620ns, skip_files: 545ns, nolint: 540ns, max_from_linter: 537ns, cgo: 397ns, exclude: 390ns, source_code: 390ns, path_shortener: 390ns, autogenerated_exclude: 318ns, diff: 312ns, uniq_by_line: 310ns, max_per_file_from_linter: 310ns 
INFO Memory: 5 samples, avg is 25.4MB, max is 55.3MB 
INFO Execution took 478.054182ms                  
@aaron42net
Copy link
Author

Upon further investigation, it seems that the golangci-lint's built-in govet and golint linters are confused by the //line comments created by quicktemplate. If I remove those from the generated code, this has the expected output:

$ ~/go/bin/golangci-lint run --no-config --exclude-use-default=false --disable-all -E golint -E govet
templates/partials/foo.qtpl.go:42:2: Printf format %s has arg 345 of wrong type int (govet)
	fmt.Printf("%s\n", 345)
	^
templates/partials/foo.qtpl.go:19:1: exported function StreamFoo should have comment or be unexported (golint)
func StreamFoo(qw422016 *qt422016.Writer) {
^
templates/partials/foo.qtpl.go:25:1: exported function WriteFoo should have comment or be unexported (golint)
func WriteFoo(qq422016 qtio422016.Writer) {
^
templates/partials/foo.qtpl.go:31:1: exported function Foo should have comment or be unexported (golint)
func Foo() string {
^
templates/partials/foo.qtpl.go:39:1: comment on exported function Bar should be of the form "Bar ..." (golint)
// This is a badly formatted comment.
^

jirfag added a commit that referenced this issue Apr 20, 2019
Preprocessed files like .qtpl.go quicktemplate Go files can have
//line directives. They map to a source .qtpl file.
This commit fixes linting of such files:
1. don't fail on AST cache loading
2. output Go filename not .qtpl or similar

Also, here we update golint to the upstream version.

Relates: #316, #466, #467, #468
jirfag added a commit that referenced this issue Apr 20, 2019
Preprocessed files like .qtpl.go quicktemplate Go files can have
//line directives. They map to a source .qtpl file.
This commit fixes linting of such files:
1. don't fail on AST cache loading
2. output Go filename not .qtpl or similar

Also, here we update golint to the upstream version.

Relates: #316, #466, #467, #468
jirfag added a commit that referenced this issue Apr 20, 2019
Preprocessed files like .qtpl.go quicktemplate Go files can have
//line directives. They map to a source .qtpl file.
This commit fixes linting of such files:
1. don't fail on AST cache loading
2. output Go filename not .qtpl or similar

Also, here we update golint to the upstream version.

Relates: #316, #466, #467, #468
@jirfag
Copy link
Contributor

jirfag commented Apr 20, 2019

Hi, thank you for the issue! The fix wasn't easy so it took a long time.
I've fixed it in the master. Check it, please.

@tpounds tpounds added the bug Something isn't working label Oct 1, 2019
@tpounds
Copy link
Contributor

tpounds commented Oct 1, 2019

@aaron42net Closing as it appears it was fixed by #504. Please comment back if this is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cgo Related to CGO or line directives bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants