protolint
protolint copied to clipboard
Feature Request: accept long non-splittable texts with MAX_LINE_LENGTH
It'd be nice to have some exceptions for lines exceeding max line length (without explicit disable macros) since it's sometimes not feasible to split in proto files for cases like long URLs and import paths.
Just for reference, Google's C++ Style Guide and Java Style Guide both specify some exceptions and the same discussion would apply in protos although the Official Protocol Buffers Style Guide suggests to keep the line length without mentioning exceptions.
@sulume Thank you for your feature request! It makes sense a lot overall. I understand the need to accept some exceptions.
Do you have any good ideas or references to a specific implementation for that? I think protolint should conservatively handle the exceptions because it already allows end-users to disable the rule by a line.
At first glance, at least an exception for import paths would be right without any nasty surprises.
[memo] Here is a current implementation.
- https://github.com/yoheimuta/protolint/blob/c99b4b987f0f928f1e858b04ee870645766a9e99/internal/addon/rules/maxLineLengthRule.go#L94-L110
Thank you for your quick response.
I think protolint should conservatively handle the exceptions because it already allows end-users to disable the rule by a line.
I'm not really sure how the consistency is maintained, but I think one way is to add another rule option alongside max_chars and tab_chars so that users have options on its behavior and existing users would see it working the same by default.
For example,
- a boolean rule option to ignore import lines, and another for URLs
- Separate options may have different default values.
- There would be no single general criteria to decide if a line of URL is not splittable, so it might need a heuristic rule, e.g. a comment line with only a single URL.
- a string rule option to specify a regexp pattern to match lines to ignore their lengths
- This way leaves users some extensibility for arbitrary long ID strings.
@sulume
so that users have options on its behavior and existing users would see it working the same by default.
That sounds great. Thank you for providing nice examples. Thanks to those, it's time to implement each exception incrementally.
[memo] I'm thinking of working on them when I finish existing priority issues. If you need them (asap) before I will assign myself, PRs are always welcome.
@yoheimuta
Since we can extract each line individually, can we have a regex for extracting annotation, e.g., #protolint:ignore: MAX_LINE_LENGTH at the end of the original protobuf definition? Once a rule is specified to be ignored, the line length is not a problem.
@bochengyang We already have a disable comment feature. So you can append // protolint:disable:this MAX_LINE_LENGTH at the end of the target line to skip the check.
Great! It saves my day :)
Thanks