Skip to content

Commit

Permalink
Merge pull request #216 from yoheimuta/order-fixer
Browse files Browse the repository at this point in the history
Order fixer
  • Loading branch information
yoheimuta authored Feb 12, 2022
2 parents 7e1088b + f1a487d commit 9f11d8e
Show file tree
Hide file tree
Showing 15 changed files with 816 additions and 18 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ See `internal/addon/rules` in detail.

The rule set follows:

- [Official Style Guide](https://developers.google.com/protocol-buffers/docs/style). This is enabled by default.
- [Official Style Guide](https://developers.google.com/protocol-buffers/docs/style). This is enabled by default. Basically, these rules can fix the violations by appending `-fix` option.
- Unofficial Style Guide. This is disabled by default. You can enable each rule with `.protolint.yaml`.

The --fix option on the command line can automatically fix some of the problems reported by fixable rules.
The `-fix` option on the command line can automatically fix some of the problems reported by fixable rules.
See Fixable columns below.

| Official | Fixable | ID | Purpose |
Expand All @@ -163,16 +163,16 @@ See Fixable columns below.
| Yes | ✅ | FIELD_NAMES_LOWER_SNAKE_CASE | Verifies that all field names are underscore_separated_names. |
| Yes | ✅ | IMPORTS_SORTED | Verifies that all imports are sorted. |
| Yes | ✅ | MESSAGE_NAMES_UPPER_CAMEL_CASE | Verifies that all message names are CamelCase (with an initial capital). |
| Yes | _ | ORDER | Verifies that all files should be ordered in the specific manner. |
| Yes | | ORDER | Verifies that all files should be ordered in the specific manner. |
| Yes | ✅ | PACKAGE_NAME_LOWER_CASE | Verifies that the package name should not contain any lowercase letters. |
| 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 | ✅ | REPEATED_FIELD_NAMES_PLURALIZED | Verifies that repeated field names are pluralized names. |
| Yes | ✅ | QUOTE_CONSISTENT | Verifies that the use of quote for strings is consistent. The default is double quoted. You can configure the specific quote with `.protolint.yaml`. |
| Yes | ✅ | INDENT | Enforces a consistent indentation style. 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. |
| Yes | ✅ | QUOTE_CONSISTENT | Verifies that the use of quote for strings is consistent. The default is double quoted. You can configure the specific quote with `.protolint.yaml`. |
| 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`. |
| No | _ | SERVICE_NAMES_END_WITH | Enforces a consistent suffix for service names. You can configure the specific suffix with `.protolint.yaml`. |
| No | _ | FIELD_NAMES_EXCLUDE_PREPOSITIONS | Verifies that all field names don't include prepositions (e.g. "for", "during", "at"). You can configure the specific prepositions and excluded keywords with `.protolint.yaml`. |
| No | _ | MESSAGE_NAMES_EXCLUDE_PREPOSITIONS | Verifies that all message names don't include prepositions (e.g. "With", "For"). You can configure the specific prepositions and excluded keywords with `.protolint.yaml`. |
Expand Down
12 changes: 12 additions & 0 deletions _testdata/rules/order/invalid.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

message Outer {
option (my_option).a = true;
// inner is an inner message.
message Inner { // Level 2
int64 ival = 1;
}
repeated Inner inner_messages = 2;
}

package my.package;
19 changes: 19 additions & 0 deletions _testdata/rules/order/invalidContiguousMisc.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";

message Outer {
option (my_option).a = true;
// inner is an inner message.
message Inner { // Level 2
int64 ival = 1;
}
repeated Inner inner_messages = 2;
}

message SecondOuter {
option (my_option).a = true;
}
message ContiguousOuter {
option (my_option).a = true;
}

package my.package;
205 changes: 205 additions & 0 deletions _testdata/rules/order/invalidMany.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
syntax = "proto3";

message Outer {
option (my_option).a = true;
}

extend google.protobuf.MethodOptions {
// See `HttpRule`.
HttpRule http = 72295728;
}

option java_package = "com.example.foo";

enum EnumAllowingAlias {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 2 [(custom_option) = "this is a "
"string on two lines"
];
}

service HelloService {
rpc SayHello (HelloRequest) returns (HelloResponse) {};
}

import 'other.proto';
import public "new.proto";

package my.package;

import "google/protobuf/empty.proto";

import "google/protobuf/timestamp.proto";

import "myproject/other_protos.proto";
import "myproject/main_protos.proto";

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
info: {
title: "A Bit of Everything";
version: "1.0";
contact: {
name: "gRPC-Gateway project";
url: "https://github.com/grpc-ecosystem/grpc-gateway";
email: "[email protected]";
};
license: {
name: "BSD 3-Clause License";
url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/master/LICENSE.txt";
};
extensions: {
key: "x-something-something";
value {
string_value: "yadda";
}
}
};
// Overwriting host entry breaks tests, so this is not done here.
external_docs: {
url: "https://github.com/grpc-ecosystem/grpc-gateway";
description: "More about gRPC-Gateway";
}
schemes: HTTP;
schemes: HTTPS;
schemes: WSS;
consumes: "application/json";
consumes: "application/x-foo-mime";
produces: "application/json";
produces: "application/x-foo-mime";
security_definitions: {
security: {
key: "BasicAuth";
value: {
type: TYPE_BASIC;
}
}
security: {
key: "ApiKeyAuth";
value: {
type: TYPE_API_KEY;
in: IN_HEADER;
name: "X-API-Key";
extensions: {
key: "x-amazon-apigateway-authtype";
value {
string_value: "oauth2";
}
}
extensions: {
key: "x-amazon-apigateway-authorizer";
value {
struct_value {
fields {
key: "type";
value {
string_value: "token";
}
}
fields {
key: "authorizerResultTtlInSeconds";
value {
number_value: 60;
}
}
}
}
}
}
}
security: {
key: "OAuth2";
value: {
type: TYPE_OAUTH2;
flow: FLOW_ACCESS_CODE;
authorization_url: "https://example.com/oauth/authorize";
token_url: "https://example.com/oauth/token";
scopes: {
scope: {
key: "read";
value: "Grants read access";
}
scope: {
key: "write";
value: "Grants write access";
}
scope: {
key: "admin";
value: "Grants read and write access to administrative information";
}
}
}
}
}
security: {
security_requirement: {
key: "BasicAuth";
value: {};
}
security_requirement: {
key: "ApiKeyAuth";
value: {};
}
}
security: {
security_requirement: {
key: "OAuth2";
value: {
scope: "read";
scope: "write";
}
}
security_requirement: {
key: "ApiKeyAuth";
value: {};
}
}
responses: {
key: "403";
value: {
description: "Returned when the user does not have permission to access the resource.";
}
}
responses: {
key: "404";
value: {
description: "Returned when the resource does not exist.";
schema: {
json_schema: {
type: STRING;
}
}
}
}
responses: {
key: "418";
value: {
description: "I'm a teapot.";
schema: {
json_schema: {
ref: ".grpc.gateway.examples.internal.examplepb.NumericEnum";
}
}
}
}
extensions: {
key: "x-grpc-gateway-foo";
value {
string_value: "bar";
}
}
extensions: {
key: "x-grpc-gateway-baz-list";
value {
list_value: {
values: {
string_value: "one";
}
values: {
bool_value: true;
}
}
}
}
};
31 changes: 31 additions & 0 deletions _testdata/rules/order/invalidWithComments.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Syntax here
syntax = "proto3"; // Inline syntax comment

/*
License information
*/

// Before outer message
message Outer { /*
Inside outer message */
// Option
option (my_option).a = true; // Inline option
// inner is an inner message.
message Inner { // Level 2
// field 1
int64 ival = 1; // Inline field 1
// after field 1
} // Inline Innter Message
repeated Inner inner_messages = 2; // Inline field 2
} // Trailing outer message

/* Package comment
Line 2
Line 3
*/
package my.package; // Inline package comment /* comment */

// Last comments
/*
License information
*/
12 changes: 12 additions & 0 deletions _testdata/rules/order/order.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package my.package;

message Outer {
option (my_option).a = true;
// inner is an inner message.
message Inner { // Level 2
int64 ival = 1;
}
repeated Inner inner_messages = 2;
}
19 changes: 19 additions & 0 deletions _testdata/rules/order/orderContiguousMisc.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";

package my.package;

message Outer {
option (my_option).a = true;
// inner is an inner message.
message Inner { // Level 2
int64 ival = 1;
}
repeated Inner inner_messages = 2;
}

message SecondOuter {
option (my_option).a = true;
}
message ContiguousOuter {
option (my_option).a = true;
}
Loading

0 comments on commit 9f11d8e

Please sign in to comment.