protoc-gen-star icon indicating copy to clipboard operation
protoc-gen-star copied to clipboard

Add GoImports Post Processor

Open asahasrabuddhe opened this issue 3 years ago • 4 comments

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.

asahasrabuddhe avatar May 24 '21 12:05 asahasrabuddhe

@dkunitsk any chance to see this merged soon? We would also be interested in this feature.

upils avatar Mar 07 '22 15:03 upils

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)
}

upils avatar Mar 09 '22 13:03 upils

thanks @upils ! I have updated my branch with your feedback.

@keith @ardakuyumcu @pdecks Could you please review this? Thanks!

asahasrabuddhe avatar Apr 19 '22 04:04 asahasrabuddhe

Hello @pdecks I have updated the PR with your feedback.

asahasrabuddhe avatar Aug 09 '22 23:08 asahasrabuddhe

It looks like the linter test started failing after this merge commit: https://github.com/lyft/protoc-gen-star/pull/96/commits/cd567a8de02cdc28453b8b44eaba7f50175748f2

pdecks avatar Aug 15 '22 23:08 pdecks

It looks like the linter test started failing after this merge commit: cd567a8

This is now fixed @pdecks

asahasrabuddhe avatar Aug 16 '22 14:08 asahasrabuddhe

@pdecks When can we expect a new release with this PR?

asahasrabuddhe avatar Aug 21 '22 13:08 asahasrabuddhe

@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 avatar Sep 14 '22 17:09 pdecks

@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.

asahasrabuddhe avatar Sep 20 '22 15:09 asahasrabuddhe

@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.

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.

pdecks avatar Sep 20 '22 19:09 pdecks