protoc-gen-star
protoc-gen-star copied to clipboard
Add GoImports Post Processor
Thanks a lot for this wonderful framework. I was building a protoc-gen plugin and needed a post processor for GoImports
. As it was not a part of this framework, I implemented my own. I think that this could be a useful part of this framework.
@dkunitsk any chance to see this merged soon? We would also be interested in this feature.
In the Match()
method, setting g.filename
is ineffective since the method is not working on a pointer.
But this is never use by Process()
so we rewrote it this way:
type goImports struct {}
// GoImports returns a PostProcessor that run goimports on any files ending in ".go"
func GoImports() pgs.PostProcessor { return goImports{} }
func (g goImports) Match(a pgs.Artifact) bool {
var n string
switch a := a.(type) {
case pgs.GeneratorFile:
n = a.Name
case pgs.GeneratorTemplateFile:
n = a.Name
case pgs.CustomFile:
n = a.Name
case pgs.CustomTemplateFile:
n = a.Name
default:
return false
}
return strings.HasSuffix(n, ".go")
}
func (g goImports) Process(in []byte) ([]byte, error) {
// We do not want to give a filename here, ever
return imports.Process("", in, nil)
}
thanks @upils ! I have updated my branch with your feedback.
@keith @ardakuyumcu @pdecks Could you please review this? Thanks!
Hello @pdecks I have updated the PR with your feedback.
It looks like the linter test started failing after this merge commit: https://github.com/lyft/protoc-gen-star/pull/96/commits/cd567a8de02cdc28453b8b44eaba7f50175748f2
It looks like the linter test started failing after this merge commit: cd567a8
This is now fixed @pdecks
@pdecks When can we expect a new release with this PR?
@pdecks When can we expect a new release with this PR?
You'll need to address the error in the pre-commit
check first.
@pdecks When can we expect a new release with this PR?
You'll need to address the error in the
pre-commit
check first.
I've fixed the pre-commit
check but now the pre-commit.ci
is failing. I have looked at the error and it does not look to be failing due to the code. There's some connection timeout error there.
@pdecks When can we expect a new release with this PR?
You'll need to address the error in the
pre-commit
check first.I've fixed the
pre-commit
check but now thepre-commit.ci
is failing. I have looked at the error and it does not look to be failing due to the code. There's some connection timeout error there.
Thanks for the heads up -- a teammate had enabled pre-commit.ci
right after I merged the previous commit, and it looks like we're running into something akin to this issue https://github.com/pre-commit-ci/issues/issues/29. We'll disable it for now.