prototool icon indicating copy to clipboard operation
prototool copied to clipboard

Keep blank lines

Open ronnylt opened this issue 6 years ago • 4 comments

It would be good to keep blank lines in the original file after the formatting has been applied, or at list to control this behaviour with a rule. Is it possible?

For example:

message Machine {
  // Unique ID of the machine
  string id = 1;

  // Human readable name of the machine
  string name = 2;

  // Description of the machine
  string description = 4;

  // Machine image preview
  string preview_image_url = 5;
}

Get formatted to the following, losing all blank line separation between the fields of the messages.

message Machine {
  // Unique ID of the machine
  string id = 1;
  // Human readable name of the machine
  string name = 2;
  // Description of the machine
  string description = 4;
  // Machine image preview
  string preview_image_url = 5;
}

ronnylt avatar Aug 30 '19 14:08 ronnylt

What about if we add something like --keep-line-breaks or something like that?

smaye81 avatar Sep 06 '19 01:09 smaye81

@smaye81 @ronnylt How to use format? I execute ./prototool format test.proto and it did nothing. Below is the content of test.proto

syntax = "proto3";

message Machine {
           // Unique ID of the machine
           string id = 1;

  // Human readable name of the machine
  string name = 2;

  // Description of the machine
                                 string description = 4;

  // Machine image preview
  string preview_image_url = 5;
}

```

new-commer avatar Nov 13 '19 08:11 new-commer

Try this:

./prototool format -w --fix test.proto

See:

prototool format --help

smaye81 avatar Mar 07 '20 02:03 smaye81

So in looking at this, it will most likely be implemented slightly different. Keeping spaces will be too difficult due to the nature of how the proto files are traversed using the proto parser.

What we can do though is add a flag --newline or similar, which would simply add a newline between message fields so that they end up like:

message Example {
   // This is a foo
   string foo = 1;

   // This is a bar
   string bar = 2;
 
   // This is a baz
   string baz = 3;
}

smaye81 avatar Mar 09 '20 20:03 smaye81