Skip to content

Commit 85cf983

Browse files
getting build to pass
1 parent 477f28f commit 85cf983

File tree

4 files changed

+113
-13
lines changed

4 files changed

+113
-13
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
runtimes:
2+
3+
4+
5+
6+
7+
tools:
8+
9+
10+
11+
12+
13+
14+
15+
16+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"runs": [
4+
{
5+
"results": [
6+
{
7+
"level": "error",
8+
"locations": [
9+
{
10+
"physicalLocation": {
11+
"artifactLocation": {
12+
"uri": "src/test_file.py"
13+
},
14+
"region": {
15+
"startColumn": 24,
16+
"startLine": 12
17+
}
18+
}
19+
}
20+
],
21+
"message": {
22+
"text": "Argument `Literal['one']` is not assignable to parameter `a` with type `int` in function `add_numbers`"
23+
},
24+
"ruleId": "bad-argument-type"
25+
},
26+
{
27+
"level": "error",
28+
"locations": [
29+
{
30+
"physicalLocation": {
31+
"artifactLocation": {
32+
"uri": "test_file.py"
33+
},
34+
"region": {
35+
"startColumn": 25,
36+
"startLine": 14
37+
}
38+
}
39+
}
40+
],
41+
"message": {
42+
"text": "Function declared to return `int` but is missing an explicit `return`"
43+
},
44+
"ruleId": "bad-return"
45+
},
46+
{
47+
"level": "error",
48+
"locations": [
49+
{
50+
"physicalLocation": {
51+
"artifactLocation": {
52+
"uri": "src/test_file.py"
53+
},
54+
"region": {
55+
"startColumn": 12,
56+
"startLine": 20
57+
}
58+
}
59+
}
60+
],
61+
"message": {
62+
"text": "Returned type `Literal[123]` is not assignable to declared return type `str`"
63+
},
64+
"ruleId": "bad-return"
65+
}
66+
],
67+
"tool": {
68+
"driver": {
69+
"informationUri": "https://pyrefly.org",
70+
"name": "Pyrefly",
71+
"rules": null,
72+
"version": "0.22.0"
73+
}
74+
}
75+
}
76+
],
77+
"version": "2.1.0"
78+
}

plugins/tools/pyrefly/test/expected.sarif

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
{
1111
"physicalLocation": {
1212
"artifactLocation": {
13-
"uri": "src/test_file.py"
13+
"uri": "test_file.py"
1414
},
1515
"region": {
16-
"startLine": 12,
17-
"startColumn": 24
16+
"startColumn": 24,
17+
"startLine": 12
1818
}
1919
}
2020
}
@@ -30,11 +30,11 @@
3030
{
3131
"physicalLocation": {
3232
"artifactLocation": {
33-
"uri": "src/test_file.py"
33+
"uri": "test_file.py"
3434
},
3535
"region": {
36-
"startLine": 14,
37-
"startColumn": 25
36+
"startColumn": 25,
37+
"startLine": 14
3838
}
3939
}
4040
}
@@ -50,11 +50,11 @@
5050
{
5151
"physicalLocation": {
5252
"artifactLocation": {
53-
"uri": "src/test_file.py"
53+
"uri": "test_file.py"
5454
},
5555
"region": {
56-
"startLine": 20,
57-
"startColumn": 12
56+
"startColumn": 12,
57+
"startLine": 20
5858
}
5959
}
6060
}

utils/sarif.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7+
"path/filepath"
78
)
89

910
// PylintIssue represents a single issue in Pylint's JSON output
@@ -21,8 +22,8 @@ type PylintIssue struct {
2122

2223
// SarifReport represents the SARIF report structure
2324
type SarifReport struct {
24-
Version string `json:"version"`
2525
Schema string `json:"$schema"`
26+
Version string `json:"version"`
2627
Runs []Run `json:"runs"`
2728
}
2829

@@ -300,11 +301,12 @@ func ConvertPyreflyToSarif(pyreflyOutput []byte) []byte {
300301
}
301302
var root pyreflyRoot
302303
var sarifReport SarifReport
304+
cwd, _ := os.Getwd()
303305
if err := json.Unmarshal(pyreflyOutput, &root); err != nil {
304306
// If parsing fails, return empty SARIF report with Pyrefly metadata
305307
sarifReport = SarifReport{
306-
Version: "2.1.0",
307308
Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
309+
Version: "2.1.0",
308310
Runs: []Run{
309311
{
310312
Tool: Tool{
@@ -320,8 +322,8 @@ func ConvertPyreflyToSarif(pyreflyOutput []byte) []byte {
320322
}
321323
} else {
322324
sarifReport = SarifReport{
323-
Version: "2.1.0",
324325
Schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
326+
Version: "2.1.0",
325327
Runs: []Run{
326328
{
327329
Tool: Tool{
@@ -336,6 +338,10 @@ func ConvertPyreflyToSarif(pyreflyOutput []byte) []byte {
336338
},
337339
}
338340
for _, issue := range root.Errors {
341+
relPath := issue.Path
342+
if rel, err := filepath.Rel(cwd, issue.Path); err == nil {
343+
relPath = rel
344+
}
339345
result := Result{
340346
RuleID: issue.Name,
341347
Level: "error", // Pyrefly only reports errors
@@ -346,7 +352,7 @@ func ConvertPyreflyToSarif(pyreflyOutput []byte) []byte {
346352
{
347353
PhysicalLocation: PhysicalLocation{
348354
ArtifactLocation: ArtifactLocation{
349-
URI: issue.Path,
355+
URI: relPath,
350356
},
351357
Region: Region{
352358
StartLine: issue.Line,

0 commit comments

Comments
 (0)