-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Go lint naming compliance #53
Comments
It is not an aim for generated code to pass golint. |
I actually agree. Passing golint here would be a "moving target" for protobuf. |
https://jira.hyperledger.org/browse/FAB-2030 According to the proto style guide, fields should be lower_underscored which generally converts nicely to golang as LowerUnderscored. However, for certain cases, like chaincode_id, this converts to ChaincodeId rather than as desired to ChaincodeID. This change updates the problematic fields to use the correct proto style, and updates the golang to expect the appropriate (although odd) output. Note, per the proto devs, golang/protobuf#53 there is no intent to modify the protoc generation to attempt to produce upper case ID API, etc. Still, the odd golang results seem worth following the style guide. Note, this CR also changes chainID to channel_id as these lines were already being affected and a community apparently came to a decision that the world channel is preferable to the word chain. https://jira.hyperledger.org/browse/FAB-2033 Change-Id: I9c5ebab88fc8d7f45335c904a56676c55a467e5d Signed-off-by: Jason Yellick <[email protected]>
For anyone else who see this, it doesn't pass golint unles you structure it like that.
I add in the json_name specifier so it doesn't turn into iD and aPIEndpoint because json always lowercases the first character. And this way your golang variables look like ID and APIEndpoint, and your json keys will still look clean with id and apiEndpoint |
The problem with such a work around is that now your C/python code is |
I think what you probably want is something like #555. That said, perfect |
Maybe it's easier to configure golint to ignore fields from Protocol Buffers? |
While this is easy enough in-file (it just has to match As for making golint ignore single lines, or blocks of code rather than whole files, that is a) going to require a change to golint itself, and b) almost certainly would end up being rejected because it goes against a guiding principle that golint should be all-or-nothing. If you’re going to lint a file, then you should lint everything, and not provide an ability to ignore a rule here or there. Either the rule is a good rule, and should be applied everywhere, or it’s a bad rule. (Not necessarily my own philosophy.) |
The problem in my mind isn't with golint of the generated files, it's with code that utlizes generated structs and interfaces. Code becomes littered with inconsistencies, such as this: return &service.Response{
UserId: userModel.ID,
} |
Correct me if im wrong or saying something completely stupid.... but is this not rather simple to implement? https://github.com/golang/lint/blob/master/lint.go#L699-L809 If this Example here: https://play.golang.org/p/f8YXDyBsF7W We have the exact same problem as @dpup. We have mappers from internal definitions of an object to the protobuf representation. So it ends up polluting out actual code as well, not simply the What do you thing @dsnet ? gogo/protobuf#691 it seems like this proposal lost traction. I feel like this solution would also make it simpler and have much less friction than having to explicitly add an option to the proto file. |
Several thoughts:
|
Fair points... I actually didn't know that golint was now deprecated and I'm actually really sad about that.. For me it was a huge advantage. Having standards/style defined by the community as a whole and the developers of the language other than our company so we don't have to fight over who wants a different style or not. It was also nice to see this as a way of trying to create more consistent code across opensource as well. Thanks for your feedback though appreciate it! |
Is it an aim of
protoc-gen-go
to produce names which pass golint? In particular, I find it is not capitalizing abbreviations as I expect (Id vs ID).A contrived example is
which produces
I prefer the names
ID
andAPIEndpoint
which pass golint. Currently, I must wrap these public fields in getters and be sure to use them to avoid propagating use of the generated names throughout my codebase.For this project, is passing golint a goal, a loose aspiration, or no stance?
Thanks a bunch for your work on this :)
Related:
golang/lint#89
The text was updated successfully, but these errors were encountered: