Skip to content

Commit

Permalink
Merge pull request #141 from yoheimuta/fix-indentatino-inner-elements…
Browse files Browse the repository at this point in the history
…-on-the-same-line/139

Fix indentations of the inner elements on the same line/139
  • Loading branch information
yoheimuta authored Dec 19, 2020
2 parents dd1422e + bfa8400 commit f309b98
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 113 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Some rules support a feature that automatically fixed the problems.
| Yes | RPC_NAMES_UPPER_CAMEL_CASE | Verifies that all rpc names are CamelCase (with an initial capital). |
| Yes | SERVICE_NAMES_UPPER_CAMEL_CASE | Verifies that all service names are CamelCase (with an initial capital). |
| Yes | MAX_LINE_LENGTH | Enforces a maximum line length. The length of a line is defined as the number of Unicode characters in the line. The default is 80 characters. You can configure the detail with `.protolint.yaml`. |
| Yes | INDENT | Enforces a consistent indentation style. The --fix option on the command line can automatically fix some of the problems reported by this rule. The default style is 2 spaces. You can configure the detail with `.protolint.yaml`. |
| Yes | INDENT | Enforces a consistent indentation style. The --fix option on the command line can automatically fix some of the problems reported by this rule. The default style is 2 spaces. Inserting appropriate new lines is also forced by default. You can configure the detail with `.protolint.yaml`. |
| Yes | PROTO3_FIELDS_AVOID_REQUIRED | Verifies that all fields should avoid required for proto3. |
| Yes | PROTO3_GROUPS_AVOID | Verifies that all groups should be avoided for proto3. |
| Yes | REPEATED_FIELD_NAMES_PLURALIZED | Verifies that repeated field names are pluralized names. |
Expand Down Expand Up @@ -274,6 +274,27 @@ __REPEATED_FIELD_NAMES_PLURALIZED__
+ repeated string song_names = 1;
```

__INDENT__

```diff
enum enumAllowingAlias {
UNKNOWN = 0;
- option allow_alias = true;
+ option allow_alias = true;
STARTED = 1;
- RUNNING = 2 [(custom_option) = "hello world"];
+ RUNNING = 2 [(custom_option) = "hello world"];
- }
+}
```

```diff
- message TestMessage { string test_field = 1; }
+ message TestMessage {
+ string test_field = 1;
+}
```

## Creating your custom rules

protolint is the pluggable linter so that you can freely create custom lint rules.
Expand Down
3 changes: 3 additions & 0 deletions _example/config/.protolint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ lint:
style: 4
# Available newlines are "\n", "\r", or "\r\n".
newline: "\n"
# Specifies if it should stop considering and inserting new lines at the appropriate positions
# when the inner elements are on the same line. Default is false.
not_insert_newline: true

# FILE_NAMES_LOWER_SNAKE_CASE rule option.
file_names_lower_snake_case:
Expand Down
27 changes: 27 additions & 0 deletions _testdata/rules/indentrule/incorrect_issue_139.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

package foobar;

option java_package = "com.test.foo.bar";

message TestMessage { string test_field = 1; }

message TestMessageWithTwoInnerElements { string test_field = 1; string test_field2 = 2; }

message TestMessageWithWrongOuterIndentation { string test_field = 1; }

message TestMessageWithoutExtraSpaces {string test_field = 1;}

message TestMessageWithFollowedSemicolon {string test_field = 1;};

enum enumAllowingAlias { UNKNOWN = 0; option allow_alias = true; }

message TestMessageWithFollowedSemicolon { enum EnumAllowingAlias { UNKNOWN = 0; option allow_alias = true; } EnumAllowingAlias enum_field =1; };

service SearchApi { rpc search (SearchRequest) returns (SearchResponse) {};};

service SearchApi { rpc search (SearchRequest) returns (SearchResponse) {}};

service SearchApi { rpc search (SearchRequest) returns (SearchResponse);};

service camelCaseServiceName { rpc Empty(google.protobuf.Empty) returns (google.protobuf.Empty) { option (google.api.http) = { get: "/v2/example/empty", };}}
7 changes: 7 additions & 0 deletions _testdata/rules/indentrule/incorrect_issue_139_short.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package foobar;

option java_package = "com.test.foo.bar";

message TestMessage { string test_field = 1; }
27 changes: 27 additions & 0 deletions _testdata/rules/indentrule/issue_139.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

package foobar;

option java_package = "com.test.foo.bar";

message TestMessage { string test_field = 1; }

message TestMessageWithTwoInnerElements { string test_field = 1; string test_field2 = 2; }

message TestMessageWithWrongOuterIndentation { string test_field = 1; }

message TestMessageWithoutExtraSpaces {string test_field = 1;}

message TestMessageWithFollowedSemicolon {string test_field = 1;};

enum enumAllowingAlias { UNKNOWN = 0; option allow_alias = true; }

message TestMessageWithFollowedSemicolon { enum EnumAllowingAlias { UNKNOWN = 0; option allow_alias = true; } EnumAllowingAlias enum_field =1; };

service SearchApi { rpc search (SearchRequest) returns (SearchResponse) {};};

service SearchApi { rpc search (SearchRequest) returns (SearchResponse) {}};

service SearchApi { rpc search (SearchRequest) returns (SearchResponse);};

service camelCaseServiceName { rpc Empty(google.protobuf.Empty) returns (google.protobuf.Empty) { option (google.api.http) = { get: "/v2/example/empty", };}}
57 changes: 57 additions & 0 deletions _testdata/rules/indentrule/issue_139_insert_linebreaks.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
syntax = "proto3";

package foobar;

option java_package = "com.test.foo.bar";

message TestMessage {
string test_field = 1;
}

message TestMessageWithTwoInnerElements {
string test_field = 1;
string test_field2 = 2;
}

message TestMessageWithWrongOuterIndentation {
string test_field = 1;
}

message TestMessageWithoutExtraSpaces {
string test_field = 1;
}

message TestMessageWithFollowedSemicolon {
string test_field = 1;
};

enum enumAllowingAlias {
UNKNOWN = 0;
option allow_alias = true;
}

message TestMessageWithFollowedSemicolon {
enum EnumAllowingAlias {
UNKNOWN = 0;
option allow_alias = true;
}
EnumAllowingAlias enum_field =1;
};

service SearchApi {
rpc search (SearchRequest) returns (SearchResponse) {};
};

service SearchApi {
rpc search (SearchRequest) returns (SearchResponse) {}
};

service SearchApi {
rpc search (SearchRequest) returns (SearchResponse);
};

service camelCaseServiceName {
rpc Empty(google.protobuf.Empty) returns (google.protobuf.Empty) {
option (google.api.http) = { get: "/v2/example/empty", };
}
}
Loading

0 comments on commit f309b98

Please sign in to comment.