Skip to content

Commit 1402ffd

Browse files
protolint: configure protolint and fix the protolinting issues
This PR addresses the following: - Install and Configure protolint to enforce the protobuf style guide rules in the CI. - Fix the protolinting issues (package and import ordering) while maintaining the comaptibility.
1 parent ec5b824 commit 1402ffd

File tree

10 files changed

+92
-14
lines changed

10 files changed

+92
-14
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ jobs:
134134
- name: check go modules tidiness
135135
run: make tidy-module-check
136136

137+
- name: lint proto files
138+
run: make protolint
139+
137140
- name: lint
138141
run: GOGC=50 make lint
139142

.protolint.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# The example configuration file for the protolint is located here:
2+
# https://github.com/yoheimuta/protolint/blob/master/_example/config/.protolint.yaml
3+
---
4+
# Lint directives.
5+
lint:
6+
# Linter rules.
7+
# Run `protolint list` to see all available rules.
8+
rules:
9+
# Determines whether or not to include the default set of linters.
10+
no_default: true
11+
12+
# Set the default to all linters. This option works the other way around as no_default does.
13+
# If you want to enable this option, delete the comment out below and no_default.
14+
# all_default: true.
15+
16+
# The specific linters to add.
17+
add:
18+
- MESSAGE_NAMES_UPPER_CAMEL_CASE
19+
- MAX_LINE_LENGTH
20+
- INDENT
21+
- FILE_NAMES_LOWER_SNAKE_CASE
22+
- IMPORTS_SORTED
23+
- PACKAGE_NAME_LOWER_CASE
24+
- ORDER
25+
- SERVICES_HAVE_COMMENT
26+
- RPCS_HAVE_COMMENT
27+
- PROTO3_FIELDS_AVOID_REQUIRED
28+
- PROTO3_GROUPS_AVOID
29+
- SYNTAX_CONSISTENT
30+
- RPC_NAMES_CASE
31+
- QUOTE_CONSISTENT
32+
33+
# Linter rules option.
34+
rules_option:
35+
# MAX_LINE_LENGTH rule option.
36+
max_line_length:
37+
# Enforces a maximum line length.
38+
max_chars: 80
39+
# Specifies the character count for tab characters.
40+
tab_chars: 2
41+
42+
# INDENT rule option.
43+
indent:
44+
# Available styles are 4(4-spaces), 2(2-spaces) or tab.
45+
style: 4
46+
# Specifies if it should stop considering and inserting new lines at the appropriate positions.
47+
# when the inner elements are on the same line. Default is false.
48+
not_insert_newline: true
49+
50+
# QUOTE_CONSISTENT rule option.
51+
quote_consistent:
52+
# Available quote are "double" or "single".
53+
quote: double
54+
55+
# ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH rule option.
56+
enum_field_names_zero_value_end_with:
57+
suffix: INVALID
58+
59+
# SERVICE_NAMES_END_WITH rule option.
60+
service_names_end_with:
61+
text: Service
62+
63+
# REPEATED_FIELD_NAMES_PLURALIZED rule option.
64+
## The spec for each rules follows the implementation of https://github.com/gertd/go-pluralize.
65+
## Plus, you can refer to this rule's test code.
66+
repeated_field_names_pluralized:
67+
uncountable_rules:
68+
- paper
69+
irregular_rules:
70+
Irregular: Regular

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ lint: docker-tools
280280
@$(call print, "Linting source.")
281281
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
282282

283+
#? protolint: Lint proto files using protolint
284+
protolint:
285+
@$(call print, "Linting proto files.")
286+
docker run --rm --volume "$$(pwd):/workspace" --workdir /workspace yoheimuta/protolint lint lnrpc/
287+
283288
#? tidy-module: Run `go mod` tidy for all modules
284289
tidy-module:
285290
echo "Running 'go mod tidy' for all modules"

lnrpc/devrpc/dev.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22

3-
import "lightning.proto";
4-
53
package devrpc;
64

5+
import "lightning.proto";
6+
77
option go_package = "github.com/lightningnetwork/lnd/lnrpc/devrpc";
88

99
/*

lnrpc/invoicesrpc/invoices.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22

3-
import "lightning.proto";
4-
53
package invoicesrpc;
64

5+
import "lightning.proto";
6+
77
option go_package = "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc";
88

99
/*

lnrpc/lnclipb/lncli.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22

3-
import "verrpc/verrpc.proto";
4-
53
package lnclipb;
64

5+
import "verrpc/verrpc.proto";
6+
77
option go_package = "github.com/lightningnetwork/lnd/lnrpc/lnclipb";
88

99
message VersionResponse {

lnrpc/peersrpc/peers.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22

3-
import "lightning.proto";
4-
53
package peersrpc;
64

5+
import "lightning.proto";
6+
77
option go_package = "github.com/lightningnetwork/lnd/lnrpc/peersrpc";
88

99
// Peers is a service that can be used to get information and interact

lnrpc/routerrpc/router.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22

3-
import "lightning.proto";
4-
53
package routerrpc;
64

5+
import "lightning.proto";
6+
77
option go_package = "github.com/lightningnetwork/lnd/lnrpc/routerrpc";
88

99
/*

lnrpc/walletrpc/walletkit.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
syntax = "proto3";
22

3+
package walletrpc;
4+
35
import "lightning.proto";
46
import "signrpc/signer.proto";
57

6-
package walletrpc;
7-
88
option go_package = "github.com/lightningnetwork/lnd/lnrpc/walletrpc";
99

1010
/*

lnrpc/walletunlocker.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
syntax = "proto3";
22

3-
import "lightning.proto";
4-
53
package lnrpc;
64

5+
import "lightning.proto";
6+
77
option go_package = "github.com/lightningnetwork/lnd/lnrpc";
88

99
/*

0 commit comments

Comments
 (0)