Skip to content

Commit 33fd641

Browse files
authored
Allow expression-only custom protovalidate rules (#4152)
1 parent 643b24b commit 33fd641

File tree

4 files changed

+4
-14
lines changed

4 files changed

+4
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- Add `textDocument/documentSymbol` support for `buf lsp serve`.
1414
- Fix LSP navigation for cached modules which could cause import paths to become unresolvable.
1515
- Update default value of `--timeout` flag to 0, which results in no timeout by default.
16+
- Update `PROTOVALIDATE` lint rule to allow for custom rules that do not have `id` or `message`
17+
fields.
1618

1719
## [v1.59.0] - 2025-10-20
1820

private/bufpkg/bufcheck/bufcheckserver/internal/buflintvalidate/cel.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ func checkCEL(
145145
break
146146
}
147147
idToConstraintIndices[celID] = append(idToConstraintIndices[celID], i)
148-
} else {
149-
add(i, "%s has an empty %s.id. IDs should always be specified.", parentNameCapitalized, celName)
150148
}
151149
if len(strings.TrimSpace(celConstraint.GetExpression())) == 0 {
152150
add(i, "%s has an empty %s.expression. Expressions should always be specified.", parentNameCapitalized, celName)
@@ -155,14 +153,6 @@ func checkCEL(
155153
ast, compileIssues := celEnv.Compile(celConstraint.GetExpression())
156154
switch {
157155
case ast.OutputType().IsAssignableType(cel.BoolType):
158-
if celConstraint.GetMessage() == "" {
159-
add(
160-
i,
161-
"%s has an empty %s.message for an expression that evaluates to a boolean. If an expression evaluates to a boolean, a message should always be specified.",
162-
parentNameCapitalized,
163-
celName,
164-
)
165-
}
166156
case ast.OutputType().IsAssignableType(cel.StringType):
167157
if celConstraint.GetMessage() != "" {
168158
add(

private/bufpkg/bufcheck/lint_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,12 @@ func TestRunProtovalidate(t *testing.T) {
627627
bufanalysistesting.NewFileAnnotation(t, "cel_field.proto", 116, 5, 120, 6, "PROTOVALIDATE"),
628628
bufanalysistesting.NewFileAnnotation(t, "cel_field.proto", 156, 5, 160, 6, "PROTOVALIDATE"),
629629
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 22, 3, 26, 5, "PROTOVALIDATE"),
630-
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 28, 3, 32, 5, "PROTOVALIDATE"),
631630
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 34, 3, 38, 5, "PROTOVALIDATE"),
632631
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 40, 3, 44, 5, "PROTOVALIDATE"),
633632
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 46, 3, 50, 5, "PROTOVALIDATE"),
634633
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 52, 3, 56, 5, "PROTOVALIDATE"),
635634
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 58, 3, 62, 5, "PROTOVALIDATE"),
636635
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 58, 3, 62, 5, "PROTOVALIDATE"),
637-
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 64, 3, 68, 5, "PROTOVALIDATE"),
638636
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 70, 3, 74, 5, "PROTOVALIDATE"),
639637
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 76, 3, 80, 5, "PROTOVALIDATE"),
640638
bufanalysistesting.NewFileAnnotation(t, "cel_message.proto", 82, 5, 86, 7, "PROTOVALIDATE"),

private/bufpkg/bufcheck/testdata/lint/protovalidate/proto/cel_message.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ message MessageTest {
2424
message: "message",
2525
expression: "this == this"
2626
};
27-
// empty id
27+
// empty id UPDATE this is now OK
2828
option (buf.validate.message).cel = {
2929
id: "",
3030
message: "message",
@@ -60,7 +60,7 @@ message MessageTest {
6060
message: "uh",
6161
expression: "foo + bar",
6262
};
63-
// missing message with a bool expression
63+
// missing message with a bool expression UPDATE: this is now OK
6464
option (buf.validate.message).cel = {
6565
id: "id5",
6666
message: "",

0 commit comments

Comments
 (0)