protolint icon indicating copy to clipboard operation
protolint copied to clipboard

Feature Request: accept long non-splittable texts with MAX_LINE_LENGTH

Open sulume opened this issue 6 years ago • 6 comments

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 avatar Nov 21 '19 10:11 sulume

@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

yoheimuta avatar Nov 22 '19 00:11 yoheimuta

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 avatar Nov 23 '19 10:11 sulume

@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 avatar Nov 24 '19 08:11 yoheimuta

@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 avatar Oct 17 '23 19:10 bochengyang

@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.

yoheimuta avatar Oct 18 '23 02:10 yoheimuta

Great! It saves my day :)

Thanks

bochengyang avatar Oct 18 '23 12:10 bochengyang