valyala / quicktemplate

Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add flag to not have the comments in the qtpl.go file

ChielTimmermans opened this issue · comments

Is it possible to add a flag that will not add the comments in the qtpl.go file?
Because at the moment for some reason the comment lines are bugging with my golintci-lint.
Another option would be to add a space between the // and the first letter of the comment.

so instead of
//line internal/.....qtpl:1 it would become
// line internal/....qtpl:1

Could you provide more information on golintci-lint output? Probably, golintci-lint must be fixed instead?

golintci-lint throws the following error
level=warning msg="[runner] Can't run linter goanalysis_metalinter: goimports: open /drone/src/internal/push/email/templates/internal/push/email/templates/verification.qtpl: no such file or directory"

i'm trying to skip the qtpl files but it is not working

Valid reason. qtc may accept -skipLineComments flag for this case in order to generate *.qtpl.go files without //line comments.
IMHO the issue must be also reported to golangci-lint.

Thanks, will report the issue to golangci-lint aswel

I've been doing stuff like this for a while:

//go:generate qtc
//go:generate sh -c "set -x; sed -i '/.qtpl:/d' *.qtpl.go"

I'd appreciate a flag to drop these line comments, though my motivation is mainly to not have big diffs when I add a line to the top of the template (and the number change cascades down). Fixing golangci-lint is nice as well.

IIRC the //line comments are a special syntax that the Go compiler uses when it's generating stuff via cgo/swig/etc (https://golang.org/cmd/compile/#hdr-Compiler_Directives). I'm not sure if there are specific restrictions there are with these. Maybe line directives are only intended to point to .go files, and that's what's breaking linters based on x/tools/analysis.

I'm happy to submit a PR to add a flag that omits these comments, if needed.

-skipLineComments command-line flag has been added to qtc at #70 . @ChielTimmermans , could you verify whether it works as expected for your case?

It is working perfect.