diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..ffb2cc6 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,7 @@ +changelog: + exclude: + labels: + - ignore-for-release + authors: + - dependabot + - dependabot[bot] diff --git a/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go b/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go index 1ba5372..77f7f85 100644 --- a/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go +++ b/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go @@ -54,8 +54,7 @@ func TestSimpleFailure(t *testing.T) { { RuleID: syntaxSpecifiedRuleID, FileLocation: &checktest.ExpectedFileLocation{ - FileName: "simple.proto", - EndColumn: 15, + FileName: "simple.proto", }, }, }, diff --git a/check/module_name_test.go b/check/module_name_test.go index 142801e..35695be 100644 --- a/check/module_name_test.go +++ b/check/module_name_test.go @@ -65,12 +65,12 @@ func TestModuleName(t *testing.T) { { RuleID: ruleID, Message: "buf.build/acme/weather", - FileLocation: &checktest.ExpectedFileLocation{FileName: "a.proto", EndLine: 8, EndColumn: 1}, + FileLocation: &checktest.ExpectedFileLocation{FileName: "a.proto"}, }, { RuleID: ruleID, Message: "", - FileLocation: &checktest.ExpectedFileLocation{FileName: "b.proto", EndLine: 4, EndColumn: 12}, + FileLocation: &checktest.ExpectedFileLocation{FileName: "b.proto"}, }, }, }.Run(t) diff --git a/check/response_writer.go b/check/response_writer.go index 9859162..cbcdfc9 100644 --- a/check/response_writer.go +++ b/check/response_writer.go @@ -348,7 +348,12 @@ func getFileLocationForAddAnnotationOptions( // 1. an exact source location // 2. the first descendant source location // 3. the nearest ancestor source location +// +// An empty path refers to the whole file and has no source location. func nearestLocation(locations protoreflect.SourceLocations, path protoreflect.SourcePath) protoreflect.SourceLocation { + if len(path) == 0 { + return protoreflect.SourceLocation{} + } if loc := locations.ByPath(path); len(loc.Path) > 0 { return loc // exact match } diff --git a/check/response_writer_test.go b/check/response_writer_test.go index a91cda6..16e2a06 100644 --- a/check/response_writer_test.go +++ b/check/response_writer_test.go @@ -55,6 +55,11 @@ func TestSourceLocationFallback(t *testing.T) { const acNum = 2 // A.c const acdNum = 3 // C.d + writer.AddAnnotation( + check.WithMessage("File - no source path - no location"), + check.WithFileName(file), + ) + fooMsg := fileDescriptor.ProtoreflectFileDescriptor().Messages().ByName("Foo") foo := fileDescriptor.ProtoreflectFileDescriptor().SourceLocations().ByDescriptor(fooMsg).Path writer.AddAnnotation( @@ -103,6 +108,15 @@ func TestSourceLocationFallback(t *testing.T) { }}, }, ExpectedAnnotations: []checktest.ExpectedAnnotation{ + // File + { + RuleID: ruleID, + Message: "File - no source path - no location", + FileLocation: &checktest.ExpectedFileLocation{ + FileName: file, + }, + }, + // Foo { RuleID: ruleID,