Skip to content

Commit 09e6f51

Browse files
authored
feat(191): allow proto3 and newer editions (#120)
1 parent 6acf132 commit 09e6f51

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

rules/aep0191/proto_version.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ import (
1818
"github.com/aep-dev/api-linter/lint"
1919
"github.com/aep-dev/api-linter/locations"
2020
"github.com/jhump/protoreflect/desc"
21+
"google.golang.org/protobuf/types/descriptorpb"
2122
)
2223

23-
// APIs must use proto3.
24+
// APIs must use proto3 or newer edition.
2425
var syntax = &lint.FileRule{
2526
Name: lint.NewRuleName(191, "proto-version"),
2627
RuleType: lint.NewRuleType(lint.MustRule),
2728
LintFile: func(f *desc.FileDescriptor) []lint.Problem {
28-
if !f.IsProto3() {
29+
if !f.IsProto3() && f.Edition() < descriptorpb.Edition_EDITION_PROTO3 {
2930
return []lint.Problem{{
30-
Message: "All API proto files must use proto3 syntax.",
31-
Suggestion: "syntax = \"proto3\";",
31+
Message: "All API proto files must use proto3 or newer edition.",
32+
Suggestion: "edition = \"2023\";",
3233
Descriptor: f,
3334
Location: locations.FileSyntax(f),
3435
}}

rules/aep0191/proto_version_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,30 @@ import (
1919

2020
"github.com/aep-dev/api-linter/rules/internal/testutils"
2121
"github.com/jhump/protoreflect/desc/builder"
22+
"google.golang.org/protobuf/types/descriptorpb"
2223
)
2324

2425
func TestSyntax(t *testing.T) {
2526
// Set up the two permutations.
2627
tests := []struct {
2728
testName string
28-
isProto3 bool
29+
edition descriptorpb.Edition
2930
problems testutils.Problems
3031
}{
31-
{"Valid", true, testutils.Problems{}},
32-
{"Invalid", false, testutils.Problems{{Suggestion: `syntax = "proto3";`}}},
32+
{"Valid (proto3)", descriptorpb.Edition_EDITION_PROTO3, testutils.Problems{}},
33+
{"Valid (2023)", descriptorpb.Edition_EDITION_2023, testutils.Problems{}},
34+
{"Valid (2024)", descriptorpb.Edition_EDITION_2024, testutils.Problems{}},
35+
{"Invalid (proto2)", descriptorpb.Edition_EDITION_PROTO2, testutils.Problems{{Suggestion: `edition = "2023";`}}},
3336
}
3437

3538
// Run each permutation as an individual test.
3639
for _, test := range tests {
3740
t.Run(test.testName, func(t *testing.T) {
3841
// Build an appropriate file descriptor.
39-
f, err := builder.NewFile("library.proto").SetProto3(test.isProto3).Build()
42+
f, err := builder.NewFile("library.proto").SetEdition(test.edition).Build()
4043
if err != nil {
4144
t.Fatalf("Could not build file descriptor.")
4245
}
43-
4446
// Lint the file, and ensure we got the expected problems.
4547
if diff := test.problems.SetDescriptor(f).Diff(syntax.Lint(f)); diff != "" {
4648
t.Error(diff)

0 commit comments

Comments
 (0)