Skip to content

Commit b018fd9

Browse files
author
James Socol
committed
fix(gh-1071): Fix file location in github output
Use the lint.FileLocationFromPBLocation method to get the correct problem locations for the GitHub Actions formatter, rather than re-implementing the conversion from PB location to file location.
1 parent f919ce8 commit b018fd9

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

cmd/api-linter/github_actions.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,8 @@ func formatGitHubActionOutput(responses []lint.Response) []byte {
3333

3434
fmt.Fprintf(&buf, "::error file=%s", response.FilePath)
3535
if problem.Location != nil {
36-
// Some findings are *line level* and only have start positions but no
37-
// starting column. Construct a switch fallthrough to emit as many of
38-
// the location indicators are included.
39-
switch len(problem.Location.Span) {
40-
case 4:
41-
fmt.Fprintf(&buf, ",endColumn=%d", problem.Location.Span[3])
42-
fallthrough
43-
case 3:
44-
fmt.Fprintf(&buf, ",endLine=%d", problem.Location.Span[2])
45-
fallthrough
46-
case 2:
47-
fmt.Fprintf(&buf, ",col=%d", problem.Location.Span[1])
48-
fallthrough
49-
case 1:
50-
fmt.Fprintf(&buf, ",line=%d", problem.Location.Span[0])
51-
}
36+
location := lint.FileLocationFromPBLocation(problem.Location)
37+
fmt.Fprintf(&buf, ",line=%d,col=%d,endLine=%d,endColumn=%d", location.Start.Line, location.Start.Column, location.End.Line, location.End.Column)
5238
}
5339

5440
// GitHub uses :: as control characters (which are also used to delimit

cmd/api-linter/github_actions_test.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,11 @@ func TestFormatGitHubActionOutput(t *testing.T) {
5353
Span: []int32{5, 6, 7},
5454
},
5555
},
56-
{
57-
RuleID: "line::col",
58-
Message: "Line and column",
59-
Location: &descriptorpb.SourceCodeInfo_Location{
60-
Span: []int32{5, 6},
61-
},
62-
},
63-
{
64-
RuleID: "line",
65-
Message: "Line only",
66-
Location: &descriptorpb.SourceCodeInfo_Location{
67-
Span: []int32{5},
68-
},
69-
},
7056
},
7157
},
7258
},
73-
want: `::error file=example.proto,endColumn=8,endLine=7,col=6,line=5,title=line։։col։։endLine։։endColumn::line, column, endline, and endColumn
74-
::error file=example.proto,endLine=7,col=6,line=5,title=line։։col։։endLine::Line, column, and endline
75-
::error file=example.proto,col=6,line=5,title=line։։col::Line and column
76-
::error file=example.proto,line=5,title=line::Line only
59+
want: `::error file=example.proto,line=6,col=7,endLine=8,endColumn=8,title=line։։col։։endLine։։endColumn::line, column, endline, and endColumn
60+
::error file=example.proto,line=6,col=7,endLine=6,endColumn=7,title=line։։col։։endLine::Line, column, and endline
7761
`,
7862
},
7963
{
@@ -98,8 +82,8 @@ func TestFormatGitHubActionOutput(t *testing.T) {
9882
},
9983
},
10084
},
101-
want: `::error file=example.proto,endColumn=4,endLine=3,col=2,line=1,title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
102-
::error file=example.proto,endColumn=8,endLine=7,col=6,line=5,title=core։։naming_formats։։field_names::multi\nline\ncomment\n\nhttps://linter.aip.dev/naming_formats/field_names
85+
want: `::error file=example.proto,line=2,col=3,endLine=4,endColumn=4,title=core։։naming_formats։։field_names::\n\nhttps://linter.aip.dev/naming_formats/field_names
86+
::error file=example.proto,line=6,col=7,endLine=8,endColumn=8,title=core։։naming_formats։։field_names::multi\nline\ncomment\n\nhttps://linter.aip.dev/naming_formats/field_names
10387
`,
10488
},
10589
{

0 commit comments

Comments
 (0)