gowrap icon indicating copy to clipboard operation
gowrap copied to clipboard

Wrong position of package comment if template has no own `import`

Open vpbarb opened this issue 5 years ago • 2 comments

If template has own import section (e.g. with github.com/prometheus/client_golang/prometheus) then the generated file header looks correct :

package name

// DO NOT EDIT!
// This code is generated with http://github.com/hexdigest/gowrap tool
// using templates/metrics template

import (
	"context"
	
	"github.com/prometheus/client_golang/prometheus"
)

But if template doesn't have own import section then package comment goes after import in generated file. It looks bad:

package name

import (
	"context"
)

// DO NOT EDIT!
// This code is generated with http://github.com/hexdigest/gowrap tool
// using templates/metrics template

import() in the beginning of template fixes it but looks weird.

vpbarb avatar Mar 10 '20 09:03 vpbarb

IDE Goland expects header from first line. Ex:

// Code generated by protoc-gen-go-grpc. DO NOT EDIT.

package client_api

funvit avatar Dec 07 '20 10:12 funvit

I https://github.com/golang/go/issues/41196 the Go team has settled on the form and the position for the Code generated ... DO NOT EDIT. comment. This is documented in the source code of the go generate command.

To convey to humans and machine tools that code is generated, generated source should have a line that matches the following regular expression (in Go syntax):

^// Code generated .* DO NOT EDIT.$

This line must appear before the first non-comment, non-blank text in the file.

It would be great, if gowrap could comply with this specification to comply with the Go ecosystem and to meet the expectations of other tools.

breml avatar Mar 28 '22 12:03 breml