Skip to content

Commit 5a2b694

Browse files
committed
Add pre-commit hook protolint for Protocol Buffer files
Run `protolint -fix` to autofix some linter errors Add `.protolint.yaml` config file and disable all rules for `comments` https://github.com/yoheimuta/protolint Hook usage listed here: https://github.com/yoheimuta/protolint?tab=readme-ov-file#version-control-integration Here is the style guide: https://protobuf.dev/programming-guides/style/ Next link is an example config file: https://github.com/yoheimuta/protolint/blob/master/_example/config/.protolint.yaml Also updated `proto_to_ruby.cpp`
1 parent 93a7e5e commit 5a2b694

4 files changed

Lines changed: 195 additions & 167 deletions

File tree

.github/linters/.protolint.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# Lint directives.
3+
lint:
4+
# Linter rules.
5+
# Run `protolint list` to see all available rules.
6+
rules:
7+
# Set the default to all linters.
8+
all_default: true
9+
# The specific linters to remove.
10+
remove:
11+
- ENUM_FIELDS_HAVE_COMMENT
12+
- ENUMS_HAVE_COMMENT
13+
- FIELDS_HAVE_COMMENT
14+
- FILE_HAS_COMMENT
15+
- MESSAGES_HAVE_COMMENT
16+
# Linter rules option.
17+
rules_option:
18+
# SYNTAX_CONSISTENT rule option.
19+
syntax_consistent:
20+
# Default is proto3.
21+
version: proto2

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ repos:
115115
args: [--config=.github/linters/mlc_config.json, -q]
116116
types: [markdown]
117117
files: \.md$
118+
- repo: https://github.com/yoheimuta/protolint
119+
rev: v0.55.2
120+
hooks:
121+
- id: protolint
122+
name: run protolint
123+
description: lint Protocol Buffer Files
124+
files: \.proto$
125+
args: [-config_path=.github/linters/.protolint.yaml]
118126
- repo: https://github.com/shellcheck-py/shellcheck-py
119127
rev: v0.10.0.1
120128
hooks:

oss-fuzz/proto_to_ruby.cpp

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,79 +34,79 @@ void protoConverter::visit(ArrType const& x)
3434
void protoConverter::visit(Array const& x)
3535
{
3636
switch (x.arr_func()) {
37-
case Array::FLATTEN:
37+
case Array::ARR_METHODS_FLATTEN:
3838
visit(x.arr_arg());
3939
m_output << ".flatten";
4040
break;
41-
case Array::COMPACT:
41+
case Array::ARR_METHODS_COMPACT:
4242
visit(x.arr_arg());
4343
m_output << ".compact";
4444
break;
45-
case Array::FETCH:
45+
case Array::ARR_METHODS_FETCH:
4646
visit(x.arr_arg());
4747
m_output << ".fetch";
4848
break;
49-
case Array::FILL:
49+
case Array::ARR_METHODS_FILL:
5050
visit(x.arr_arg());
5151
m_output << ".fill";
5252
break;
53-
case Array::ROTATE:
53+
case Array::ARR_METHODS_ROTATE:
5454
visit(x.arr_arg());
5555
m_output << ".rotate";
5656
break;
57-
case Array::ROTATE_E:
57+
case Array::ARR_METHODS_ROTATE_E:
5858
visit(x.arr_arg());
5959
m_output << ".rotate!";
6060
break;
61-
case Array::DELETEIF:
61+
case Array::ARR_METHODS_DELETEIF:
6262
visit(x.arr_arg());
6363
m_output << ".delete_if";
6464
break;
65-
case Array::INSERT:
65+
case Array::ARR_METHODS_INSERT:
6666
visit(x.arr_arg());
6767
m_output << ".insert";
6868
break;
69-
case Array::BSEARCH:
69+
case Array::ARR_METHODS_BSEARCH:
7070
visit(x.arr_arg());
7171
m_output << ".bsearch";
7272
break;
73-
case Array::KEEPIF:
73+
case Array::ARR_METHODS_KEEPIF:
7474
visit(x.arr_arg());
7575
m_output << ".keep_if";
7676
break;
77-
case Array::SELECT:
77+
case Array::ARR_METHODS_SELECT:
7878
visit(x.arr_arg());
7979
m_output << ".select";
8080
break;
81-
case Array::VALUES_AT:
81+
case Array::ARR_METHODS_VALUES_AT:
8282
visit(x.arr_arg());
8383
m_output << ".values_at";
8484
break;
85-
case Array::BLOCK:
85+
case Array::ARR_METHODS_BLOCK:
8686
visit(x.arr_arg());
8787
m_output << ".index";
8888
break;
89-
case Array::DIG:
89+
case Array::ARR_METHODS_DIG:
9090
visit(x.arr_arg());
9191
m_output << ".dig";
9292
break;
93-
case Array::SLICE:
93+
case Array::ARR_METHODS_SLICE:
9494
visit(x.arr_arg());
9595
m_output << ".slice";
9696
break;
97-
case Array::PERM:
97+
case Array::ARR_METHODS_PERM:
9898
visit(x.arr_arg());
9999
m_output << ".permutation";
100100
break;
101-
case Array::COMB:
101+
case Array::ARR_METHODS_COMB:
102102
visit(x.arr_arg());
103103
m_output << ".combination";
104104
break;
105-
case Array::ASSOC:
105+
case Array::ARR_METHODS_ASSOC:
106106
visit(x.arr_arg());
107107
m_output << ".assoc";
108108
break;
109-
case Array::RASSOC:
109+
case Array::ARR_METHODS_RASSOC:
110110
visit(x.arr_arg());
111111
m_output << ".rassoc";
112112
break;
@@ -130,21 +130,21 @@ void protoConverter::visit(BinaryOp const& x)
130130
m_output << "(";
131131
visit(x.left());
132132
switch (x.op()) {
133-
case BinaryOp::ADD: m_output << " + "; break;
134-
case BinaryOp::SUB: m_output << " - "; break;
135-
case BinaryOp::MUL: m_output << " * "; break;
136-
case BinaryOp::DIV: m_output << " / "; break;
137-
case BinaryOp::MOD: m_output << " % "; break;
138-
case BinaryOp::XOR: m_output << " ^ "; break;
139-
case BinaryOp::AND: m_output << " and "; break;
140-
case BinaryOp::OR: m_output << " or "; break;
141-
case BinaryOp::EQ: m_output << " == "; break;
142-
case BinaryOp::NE: m_output << " != "; break;
143-
case BinaryOp::LE: m_output << " <= "; break;
144-
case BinaryOp::GE: m_output << " >= "; break;
145-
case BinaryOp::LT: m_output << " < "; break;
146-
case BinaryOp::GT: m_output << " > "; break;
147-
case BinaryOp::RS: m_output << " >> "; break;
133+
case BinaryOp::OP_ADD_UNSPECIFIED: m_output << " + "; break;
134+
case BinaryOp::OP_SUB: m_output << " - "; break;
135+
case BinaryOp::OP_MUL: m_output << " * "; break;
136+
case BinaryOp::OP_DIV: m_output << " / "; break;
137+
case BinaryOp::OP_MOD: m_output << " % "; break;
138+
case BinaryOp::OP_XOR: m_output << " ^ "; break;
139+
case BinaryOp::OP_AND: m_output << " and "; break;
140+
case BinaryOp::OP_OR: m_output << " or "; break;
141+
case BinaryOp::OP_EQ: m_output << " == "; break;
142+
case BinaryOp::OP_NE: m_output << " != "; break;
143+
case BinaryOp::OP_LE: m_output << " <= "; break;
144+
case BinaryOp::OP_GE: m_output << " >= "; break;
145+
case BinaryOp::OP_LT: m_output << " < "; break;
146+
case BinaryOp::OP_GT: m_output << " > "; break;
147+
case BinaryOp::OP_RS: m_output << " >> "; break;
148148
}
149149
visit(x.right());
150150
m_output << ")";
@@ -197,10 +197,10 @@ void protoConverter::visit(Function const& x)
197197

198198
void protoConverter::visit(HashType const& x)
199199
{
200-
if (x.keyval_size() > 0) {
201-
int i = x.keyval_size();
200+
if (x.keyvals_size() > 0) {
201+
int i = x.keyvals_size();
202202
m_output << "{";
203-
for (auto &e : x.keyval()) {
203+
for (auto &e : x.keyvals()) {
204204
i--;
205205
if (i == 0) {
206206
visit(e);
@@ -235,10 +235,10 @@ void protoConverter::visit(KVPair const& x)
235235
void protoConverter::visit(MathConst const& x)
236236
{
237237
switch (x.math_const()) {
238-
case MathConst::PI:
238+
case MathConst::MATH_CONST_LIT_PI_UNSPECIFIED:
239239
m_output << "Math::PI";
240240
break;
241-
case MathConst::E:
241+
case MathConst::MATH_CONST_LIT_E:
242242
m_output << "Math::E";
243243
break;
244244
}
@@ -247,52 +247,52 @@ void protoConverter::visit(MathConst const& x)
247247
void protoConverter::visit(MathOps const& x)
248248
{
249249
switch (x.math_op()) {
250-
case MathOps::CBRT:
250+
case MathOps::MOPS_CBRT:
251251
m_output << "Math.cbrt(";
252252
visit(x.math_arg());
253253
m_output << ")";
254254
break;
255-
case MathOps::COS:
255+
case MathOps::MOPS_COS:
256256
m_output << "Math.cos(";
257257
visit(x.math_arg());
258258
m_output << ")";
259259
break;
260-
case MathOps::ERF:
260+
case MathOps::MOPS_ERF:
261261
m_output << "Math.erf(";
262262
visit(x.math_arg());
263263
m_output << ")";
264264
break;
265-
case MathOps::ERFC:
265+
case MathOps::MOPS_ERFC:
266266
m_output << "Math.erfc(";
267267
visit(x.math_arg());
268268
m_output << ")";
269269
break;
270-
case MathOps::LOG:
270+
case MathOps::MOPS_LOG:
271271
m_output << "Math.log(";
272272
visit(x.math_arg());
273273
m_output << ")";
274274
break;
275-
case MathOps::LOG10:
275+
case MathOps::MOPS_LOG10:
276276
m_output << "Math.log10(";
277277
visit(x.math_arg());
278278
m_output << ")";
279279
break;
280-
case MathOps::LOG2:
280+
case MathOps::MOPS_LOG2:
281281
m_output << "Math.log2(";
282282
visit(x.math_arg());
283283
m_output << ")";
284284
break;
285-
case MathOps::SIN:
285+
case MathOps::MOPS_SIN:
286286
m_output << "Math.sin(";
287287
visit(x.math_arg());
288288
m_output << ")";
289289
break;
290-
case MathOps::SQRT:
290+
case MathOps::MOPS_SQRT:
291291
m_output << "Math.sqrt(";
292292
visit(x.math_arg());
293293
m_output << ")";
294294
break;
295-
case MathOps::TAN:
295+
case MathOps::MOPS_TAN:
296296
m_output << "Math.tan(";
297297
visit(x.math_arg());
298298
m_output << ")";
@@ -318,7 +318,7 @@ void protoConverter::visit(MathType const& x)
318318
void protoConverter::visit(ObjectSpace const& x)
319319
{
320320
switch (x.os_func()) {
321-
case ObjectSpace::COUNT:
321+
case ObjectSpace::OS_METHODS_COUNT:
322322
m_output << "ObjectSpace.count_objects";
323323
break;
324324
}
@@ -386,34 +386,34 @@ void protoConverter::visit(StringExtNoArg const& x)
386386
{
387387
m_output << "\"" << removeSpecial(x.str_arg()) << "\"";
388388
switch (x.str_op()) {
389-
case StringExtNoArg::DUMP:
389+
case StringExtNoArg::STR_EXT_OP_DUMP_UNSPECIFIED:
390390
m_output << ".dump";
391391
break;
392-
case StringExtNoArg::STRIP:
392+
case StringExtNoArg::STR_EXT_OP_STRIP:
393393
m_output << ".strip";
394394
break;
395-
case StringExtNoArg::LSTRIP:
395+
case StringExtNoArg::STR_EXT_OP_LSTRIP:
396396
m_output << ".lstrip";
397397
break;
398-
case StringExtNoArg::RSTRIP:
398+
case StringExtNoArg::STR_EXT_OP_RSTRIP:
399399
m_output << ".rstrip";
400400
break;
401-
case StringExtNoArg::STRIPE:
401+
case StringExtNoArg::STR_EXT_OP_STRIPE:
402402
m_output << ".strip!";
403403
break;
404-
case StringExtNoArg::LSTRIPE:
404+
case StringExtNoArg::STR_EXT_OP_LSTRIPE:
405405
m_output << ".lstrip!";
406406
break;
407-
case StringExtNoArg::RSTRIPE:
407+
case StringExtNoArg::STR_EXT_OP_RSTRIPE:
408408
m_output << ".rstrip!";
409409
break;
410-
case StringExtNoArg::SWAPCASE:
410+
case StringExtNoArg::STR_EXT_OP_SWAPCASE:
411411
m_output << ".swapcase";
412412
break;
413-
case StringExtNoArg::SWAPCASEE:
413+
case StringExtNoArg::STR_EXT_OP_SWAPCASEE:
414414
m_output << ".swapcase!";
415415
break;
416-
case StringExtNoArg::SQUEEZE:
416+
case StringExtNoArg::STR_EXT_OP_SQUEEZE:
417417
m_output << ".squeeze";
418418
break;
419419
}
@@ -433,10 +433,10 @@ void protoConverter::visit(Ternary const& x)
433433
void protoConverter::visit(Time const& x)
434434
{
435435
switch (x.t_func()) {
436-
case Time::AT:
436+
case Time::TMETHODS_AT:
437437
m_output << "Time.at";
438438
break;
439-
case Time::GM:
439+
case Time::TMETHODS_GM:
440440
m_output << "Time.gm";
441441
break;
442442
}

0 commit comments

Comments
 (0)