Limit Parsing to Target Package to Avoid Unnecessary Work and Potential Bugs #11
codemageddon
started this conversation in
Ideas
Replies: 1 comment
-
It might also be better to use the constants themselves during generation rather than their literal values because, for example, golangci-lint, in its default configuration, complains that the original constant is defined but not used (as well as the original type definition). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In the current implementation, all directories — and consequently, all packages — within the
CWD
are parsed. This, first of all, results in unnecessary work and, secondly, may introduce bugs. For example, if another subpackage defines a constant with the same prefix or a type with the same name, there is a risk of selecting the wrong type for values (as in merge #9) and/or adding extra elements to the enum.go generate
sets the environment variablesGOPACKAGE
andGOFILE
for the package and file being processed, which can be used to filter packages. Additionally, in theory, it is possible to parse only the file specified inGOFILE
, but this would remove the ability to “add” elements to an enum from other files within the same package — I’m not sure how necessary that is.Additionally, when parsing values, it would be good to add a condition to check for a matching constant type, not just the presence of a specific prefix.
Beta Was this translation helpful? Give feedback.
All reactions