-
Notifications
You must be signed in to change notification settings - Fork 18
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
File-level go.lint option #32
Conversation
I’m not sure about this. It’s kind of gross, kind of magic. |
f45e414
to
6ddf957
Compare
Feeling better about this now. @Green7 want to take a look? |
I tried and I have such observations: Regarding the enums: |
Do you have an example of this? What do you want or expect to happen?
What do you mean by this?
Idiomatic Go specifies that global vars or const values should be prefixed with the type name. |
Here is an example proto file:
I have: option (go.initialisms) = "ID";
Yes, but i have codebase without prefixes because I used gogoprotobuf with option goproto_enum_prefix_all to generate my files. Now I want replace gogoprotobuf with protopatch and get the same result. |
Thanks to @Green7 for the breaking examples: #32 (comment)
@Green7 I added your examples as test cases and fixed an issue with enum value name generation. Fixed: Are you saying you don’t want all names like |
I think it should be fully configurable. It should be possible to disable common initlialism if we don't want them. |
Makes sense. In your case I'd recommend using an explicit |
I do not understand. It's not just about the enum values. I would like to change only the ID fields in all files without touching other names. How can this be achieved? |
For messages: message ExampleId {
option (go.message).name = "ExampleID";
// ...
} For fields: message Account {
string id = 1; [(go.field).name = "ID"];
} etc. |
To be clear, it doesn’t make sense to use a hammer (linting/renaming) when you only want to selectively rename certain things. It’s better to be explicit at the declaration of the specific field or enum value you wish to rename, particularly if you only care about renames with |
I have about 50 proto files. There are many fields in each with the name id or _id. Tagging each one separately is a lot of work. And I will have to remember to tag each newly added field as well. |
I actually think it’s simpler for you to add this to your fields. It’s one change, ideally a straightforward regexp find and replace. Assuming you have tests, it’s a single commit, and you’re done. I prefer that to a specialized code path in this package that will have to be maintained forever just to rename some things with the word To explain further: a goal of this project is to have a minimal interface, with fewer options, and in general, one way to do something. Second, if something can be accomplished with a bit more typing, but is simpler and more understandable by folks reading the code, that’s preferable to a global option. |
I understand your point of view: but I have a different. For me, a tool is good when it allows me to achieve the effect I want. gogoprotobuf was such a tool, it was easy to add any code modifying field names. Summarizing my attempt to make changes in protopatch:
|
This is a separate feature, and I agree it’s worth implementing. |
that's good 👍 when it may be available ? |
Usage: option (go.all.values.prefix = '') // To omit all enum type prefixes by default patch: de-nested FileOptions patch/gopb: recompile protos lint: copy lintName func from golang.org/x/lint patch, patch/gopb: simplify file-level options interface patch: add file-level name linting via (go.lint) = true This will fix non-idiomatic generated Go code with initialisms like Url→URL and Id→ID. tests/lint: smoke tests for (go.lint) option patch: introduce comments into dense Patcher methods CHANGELOG: add note about go.lint option, thanks to @Green7 patch, tests/lint: lint extension names patch, patch/gopb: remove unused Prefix option CHANGELOG: update for changes in #32 patch: look at enum value parent file, not enum, even though they are the same patch, tests/lint: new file-level go.initialisms option to specify additional initialisms for linting Example: (go.initialisms) = 'RGB'; // Will convert RgbColor to RGBColor tests/lint: add tests from @Green7 in #32 patch: improve enum value name linting Thanks to @Green7 for the breaking examples: #32 (comment) patch, tests/lint: correctly lint nested enum value names patch: replacePrefix should only replace prefix if it exists patch: dry up enum value renaming logic patch: remove unnecessary duplicate branch tests/lint: improve nested enum tests tests/lint: test case for linting (and fixing) a custom name tests/enum: conformance tests for deeply-nested enums patch: correctly mimic protogen’s name generation for nested enum values tests/lint: additional lint tests for renamed nested enums tests/enum: rework enum conformance and renaming tests CHANGELOG: added note about correct nested enum value renaming tests/message: improve message tests
This PR borrows code from https://golang.org/x/lint to automatically fix initialisms and stuttering in generated names.
Thanks to @Green7 for the initial implementation in #22!