Skip to content

Commit 2b84502

Browse files
authored
Merge pull request #1044 from mohamedawnallah/introduce-protolint-to-workflow
multi: Introduce `protolint` to CI workflow and `make rpc-format` util
2 parents aec77d6 + 8560f34 commit 2b84502

File tree

6 files changed

+435
-234
lines changed

6 files changed

+435
-234
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
- name: compile code
5858
run: go install -v ./...
5959

60+
- name: Lint proto files
61+
run: make protolint
62+
6063
- name: run lint
6164
run: make lint
6265

.protolint.yml

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ fmt-check: fmt
126126
@$(call print, "Checking fmt results.")
127127
if test -n "$$(git status --porcelain)"; then echo "code not formatted correctly, please run `make fmt` again!"; git status; git diff; exit 1; fi
128128

129+
#? rpc-format: Format protobuf definition files
130+
rpc-format:
131+
@$(call print, "Formatting protos.")
132+
cd ./rpc; find . -name "*.proto" | xargs clang-format --style=file -i
133+
129134
#? lint: Lint source
130135
lint: $(LINT_BIN)
131136
@$(call print, "Linting source.")
@@ -141,6 +146,11 @@ rpc-check: rpc
141146
@$(call print, "Verifying protos.")
142147
if test -n "$$(git status --porcelain rpc/walletrpc/)"; then echo "Generated protobuf files are not up-to-date. Please run 'make rpc' and commit the changes."; git status; git diff rpc/walletrpc/; exit 1; fi
143148

149+
#? protolint: Lint proto files using protolint
150+
protolint:
151+
@$(call print, "Linting proto files.")
152+
docker run --rm --volume "$$(pwd):/workspace" --workdir /workspace yoheimuta/protolint lint rpc/
153+
144154
#? clean: Clean source
145155
clean:
146156
@$(call print, "Cleaning source.$(NC)")
@@ -166,9 +176,11 @@ tidy-module-check: tidy-module
166176
fmt-check \
167177
tidy-module \
168178
tidy-module-check \
179+
rpc-format \
169180
lint \
170181
rpc \
171182
rpc-check \
183+
protolint \
172184
clean
173185

174186
#? help: Get more info on make commands

rpc/.clang-format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
Language: Proto
3+
BasedOnStyle: Google
4+
IndentWidth: 4
5+
AllowShortFunctionsOnASingleLine: None
6+
SpaceBeforeParens: Always
7+
CompactNamespaces: false

0 commit comments

Comments
 (0)