Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
changelog:
exclude:
labels:
- ignore-for-release
authors:
- dependabot
- dependabot[bot]
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func TestSimpleFailure(t *testing.T) {
{
RuleID: syntaxSpecifiedRuleID,
FileLocation: &checktest.ExpectedFileLocation{
FileName: "simple.proto",
EndColumn: 15,
FileName: "simple.proto",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions check/module_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<none>",
FileLocation: &checktest.ExpectedFileLocation{FileName: "b.proto", EndLine: 4, EndColumn: 12},
FileLocation: &checktest.ExpectedFileLocation{FileName: "b.proto"},
},
},
}.Run(t)
Expand Down
5 changes: 5 additions & 0 deletions check/response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions check/response_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Loading