-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Feat): Parser prettier failure messages (#589)
Co-authored-by: Chris Clearwater <[email protected]>
- Loading branch information
1 parent
e6ed22c
commit 3b669eb
Showing
10 changed files
with
225 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
plugins | ||
user_trunk.yaml | ||
user.yaml | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { linterFmtTest } from "tests"; | ||
import { linterCheckTest, linterFmtTest } from "tests"; | ||
import { TrunkLintDriver } from "tests/driver"; | ||
|
||
// Grab the root .prettierrc.yaml | ||
const preCheck = (driver: TrunkLintDriver) => { | ||
driver.writeFile( | ||
".trunk/configs/.prettierrc.yaml", | ||
`printWidth: 100 | ||
proseWrap: always` | ||
proseWrap: always`, | ||
); | ||
}; | ||
|
||
// TODO(Tyler): We will eventually need to add a couple more test cases involving other file types. | ||
linterFmtTest({ linterName: "prettier", preCheck }); | ||
linterCheckTest({ linterName: "prettier", preCheck }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import re | ||
import sys | ||
|
||
|
||
def to_result_sarif(path: str, description: str, line: int = 0, column: int = 0): | ||
return { | ||
"level": "error", | ||
"locations": [ | ||
{ | ||
"physicalLocation": { | ||
"artifactLocation": { | ||
"uri": path, | ||
}, | ||
"region": { | ||
"startColumn": column, | ||
"startLine": line, | ||
}, | ||
} | ||
} | ||
], | ||
"message": { | ||
"text": description, | ||
}, | ||
"ruleId": "SyntaxError", | ||
} | ||
|
||
|
||
def main(argv): | ||
if len(argv) < 2: | ||
print("Usage: trivy_to_sarif.py <exit_code>)") | ||
sys.exit(1) | ||
|
||
if argv[1] == "0": | ||
results = [] | ||
sarif = { | ||
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", | ||
"version": "2.1.0", | ||
"runs": [{"results": results}], | ||
} | ||
|
||
print(json.dumps(sarif, indent=2)) | ||
sys.exit(0) | ||
|
||
first_line = sys.stdin.readline() | ||
m = re.match(r"\[error\] (.*): SyntaxError:(.*)\((\d+):(\d+)\)", first_line) | ||
if m is None: | ||
print("Unexpected output from prettier") | ||
sys.exit(int(argv[1])) | ||
|
||
results = [] | ||
results.append(to_result_sarif(m[1], m[2], int(m[3]), int(m[4]))) | ||
|
||
sarif = { | ||
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", | ||
"version": "2.1.0", | ||
"runs": [{"results": results}], | ||
} | ||
|
||
print(json.dumps(sarif, indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
invoice : 34843 | ||
date : 2001-01-23 | ||
] | ||
bill-to: &id001 | ||
given : Chris | ||
family : Dumars | ||
address: | ||
lines: | | ||
458 Walkman Dr. | ||
Suite #292 | ||
city : Royal Oak | ||
state : MI | ||
postal : 48046 | ||
ship-to: *id001 | ||
product: | ||
- | ||
|
||
sku : BL394D | ||
? quantity | ||
: 4 | ||
description : Basketball | ||
? price | ||
: 450.00 | ||
|
||
|
||
- | ||
sku : BL4438H | ||
quantity : 1 | ||
description: Super Hoop | ||
price : 2392.00 | ||
|
||
|
||
tax : 251.42 | ||
total : 4443.52 | ||
comments: > | ||
Late afternoon is best. | ||
Backup contact is Nancy | ||
Billsmer @ 338-4338. |
30 changes: 30 additions & 0 deletions
30
linters/prettier/test_data/prettier_v2.6.2_basic.check.shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing linter prettier test basic 1`] = ` | ||
{ | ||
"issues": [], | ||
"lintActions": [ | ||
{ | ||
"command": "format", | ||
"fileGroupName": "yaml", | ||
"linter": "prettier", | ||
"paths": [ | ||
"test_data/basic.in.yaml", | ||
], | ||
"verb": "TRUNK_VERB_FMT", | ||
}, | ||
], | ||
"taskFailures": [], | ||
"unformattedFiles": [ | ||
{ | ||
"column": "1", | ||
"file": "test_data/basic.in.yaml", | ||
"issueClass": "ISSUE_CLASS_UNFORMATTED", | ||
"level": "LEVEL_HIGH", | ||
"line": "1", | ||
"linter": "prettier", | ||
"message": "Incorrect formatting, autoformat by running 'trunk fmt'", | ||
}, | ||
], | ||
} | ||
`; |
31 changes: 31 additions & 0 deletions
31
linters/prettier/test_data/prettier_v2.6.2_error.check.shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing linter prettier test error 1`] = ` | ||
{ | ||
"issues": [ | ||
{ | ||
"code": "SyntaxError", | ||
"column": "1", | ||
"file": "test_data/error.in.yaml", | ||
"level": "LEVEL_HIGH", | ||
"line": "4", | ||
"linter": "prettier", | ||
"message": "Implicit map keys need to be followed by map values", | ||
"targetType": "yaml", | ||
}, | ||
], | ||
"lintActions": [ | ||
{ | ||
"command": "format", | ||
"fileGroupName": "yaml", | ||
"linter": "prettier", | ||
"paths": [ | ||
"test_data/error.in.yaml", | ||
], | ||
"verb": "TRUNK_VERB_FMT", | ||
}, | ||
], | ||
"taskFailures": [], | ||
"unformattedFiles": [], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing formatter prettier test error 1`] = ` | ||
"--- | ||
invoice : 34843 | ||
date : 2001-01-23 | ||
] | ||
bill-to: &id001 | ||
given : Chris | ||
family : Dumars | ||
address: | ||
lines: | | ||
458 Walkman Dr. | ||
Suite #292 | ||
city : Royal Oak | ||
state : MI | ||
postal : 48046 | ||
ship-to: *id001 | ||
product: | ||
- | ||
|
||
sku : BL394D | ||
? quantity | ||
: 4 | ||
description : Basketball | ||
? price | ||
: 450.00 | ||
|
||
|
||
- | ||
sku : BL4438H | ||
quantity : 1 | ||
description: Super Hoop | ||
price : 2392.00 | ||
|
||
|
||
tax : 251.42 | ||
total : 4443.52 | ||
comments: > | ||
Late afternoon is best. | ||
Backup contact is Nancy | ||
Billsmer @ 338-4338. | ||
" | ||
`; |