-
Notifications
You must be signed in to change notification settings - Fork 3
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
Stop aligning struct tags when length difference exceeds threshold #13
Comments
We can add a new option This configuration option specifies the maximum allowable length difference between struct tags in the same column before alignment stops. When the difference between the longest and shortest tags exceeds this threshold, the alignment for subsequent tags in that column will be disabled, while the preceding tags will remain aligned. This helps maintain readability without creating large gaps. Would this approach meet your needs, or do you have any suggestions for improvement? |
I believe that would, yep! |
@lrstanley My code is ready. Could you please provide me with some code so you can preview it before I merge these changes to golangci-lint. If that's not what you want, we can still make changes. |
I have generally always manually grouped struct tags based on a few common patterns, some of which are similar to this linter (sorting, specific tags first, etc). However, when it comes to adding alignment and padding, I've always taken a different approach. For example:
In the above example, I'm doing a couple of things.
It seems like the fall-through approach for 1 is currently supported when
strict: false
, however, there is no "give up when the length is above a certain size" kind of approach. Would you be open to something like this? e.g. if the alignment is different between two of the same, or different, tags is above X amount, no longer try and align. This could default to0
to not impact users.I'd like to avoid these scenarios (where the vertical lines are my typical "ruler" length for how long my lines should be):
Another example with
sort: true
andalign: true
:vs a combo of alignment + "this field is super long, just don't bother aligning anything after X length"
I'm not set on the approach (single field length difference vs "don't sort after X characters" (for the entire struct tag).
The text was updated successfully, but these errors were encountered: