@robhowley/pi-structured-return 1.10.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -83
  3. package/extensions/structured-return/config/registry.ts +4 -36
  4. package/extensions/structured-return/index.ts +105 -90
  5. package/extensions/structured-return/native.ts +223 -0
  6. package/extensions/structured-return/parsers/ava-text.ts +2 -168
  7. package/extensions/structured-return/parsers/bandit-json.ts +2 -79
  8. package/extensions/structured-return/parsers/black-text.ts +2 -73
  9. package/extensions/structured-return/parsers/cargo-build.ts +2 -78
  10. package/extensions/structured-return/parsers/cargo-test.ts +2 -135
  11. package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
  12. package/extensions/structured-return/parsers/clang-text.ts +2 -60
  13. package/extensions/structured-return/parsers/dbt-json.ts +2 -135
  14. package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
  15. package/extensions/structured-return/parsers/eslint-json.ts +2 -38
  16. package/extensions/structured-return/parsers/go-test-json.ts +2 -138
  17. package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
  18. package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
  19. package/extensions/structured-return/parsers/isort-text.ts +2 -63
  20. package/extensions/structured-return/parsers/javac-text.ts +2 -82
  21. package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
  22. package/extensions/structured-return/parsers/junit-xml.ts +2 -325
  23. package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
  24. package/extensions/structured-return/parsers/minitest-text.ts +2 -107
  25. package/extensions/structured-return/parsers/mocha-json.ts +2 -83
  26. package/extensions/structured-return/parsers/mypy-json.ts +2 -79
  27. package/extensions/structured-return/parsers/node-test-text.ts +2 -92
  28. package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
  29. package/extensions/structured-return/parsers/prettier-text.ts +2 -66
  30. package/extensions/structured-return/parsers/pylint-json.ts +2 -63
  31. package/extensions/structured-return/parsers/pyright-json.ts +2 -82
  32. package/extensions/structured-return/parsers/rspec-json.ts +2 -75
  33. package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
  34. package/extensions/structured-return/parsers/ruff-json.ts +2 -36
  35. package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
  36. package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
  37. package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
  38. package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
  39. package/extensions/structured-return/parsers/tidy-text.ts +2 -66
  40. package/extensions/structured-return/parsers/tsc-text.ts +2 -46
  41. package/extensions/structured-return/parsers/unittest-text.ts +2 -125
  42. package/extensions/structured-return/parsers/utils.ts +28 -0
  43. package/extensions/structured-return/parsers/vale-json.ts +2 -79
  44. package/extensions/structured-return/parsers/vitest-json.ts +2 -59
  45. package/extensions/structured-return/storage/log-store.ts +0 -15
  46. package/extensions/structured-return/types.ts +1 -14
  47. package/native/Cargo.lock +193 -0
  48. package/native/Cargo.toml +21 -0
  49. package/native/THIRD-PARTY-LICENSES.txt +3660 -0
  50. package/native/bin/darwin-arm64/build.json +7 -0
  51. package/native/bin/darwin-arm64/structured-return-native +0 -0
  52. package/native/bin/darwin-x64/build.json +7 -0
  53. package/native/bin/darwin-x64/structured-return-native +0 -0
  54. package/native/bin/linux-arm64-musl/build.json +7 -0
  55. package/native/bin/linux-arm64-musl/structured-return-native +0 -0
  56. package/native/bin/linux-x64-musl/build.json +7 -0
  57. package/native/bin/linux-x64-musl/structured-return-native +0 -0
  58. package/native/src/common.rs +118 -0
  59. package/native/src/main.rs +55 -0
  60. package/native/src/parsers/ava_text.rs +125 -0
  61. package/native/src/parsers/bandit_json.rs +120 -0
  62. package/native/src/parsers/black_text.rs +45 -0
  63. package/native/src/parsers/cargo_build.rs +96 -0
  64. package/native/src/parsers/cargo_test.rs +140 -0
  65. package/native/src/parsers/checkstyle_xml.rs +137 -0
  66. package/native/src/parsers/clang_text.rs +39 -0
  67. package/native/src/parsers/compiler_helpers.rs +74 -0
  68. package/native/src/parsers/dbt_json.rs +243 -0
  69. package/native/src/parsers/dotnet_build_text.rs +50 -0
  70. package/native/src/parsers/eslint_json.rs +58 -0
  71. package/native/src/parsers/go_test_json.rs +346 -0
  72. package/native/src/parsers/hadolint_json.rs +37 -0
  73. package/native/src/parsers/htmlhint_json.rs +71 -0
  74. package/native/src/parsers/isort_text.rs +22 -0
  75. package/native/src/parsers/javac_text.rs +49 -0
  76. package/native/src/parsers/json_support.rs +287 -0
  77. package/native/src/parsers/jsonlint_text.rs +50 -0
  78. package/native/src/parsers/junit_xml.rs +430 -0
  79. package/native/src/parsers/markdownlint_json.rs +68 -0
  80. package/native/src/parsers/minitest_text.rs +91 -0
  81. package/native/src/parsers/mocha_json.rs +75 -0
  82. package/native/src/parsers/mod.rs +119 -0
  83. package/native/src/parsers/mypy_json.rs +93 -0
  84. package/native/src/parsers/node_test_text.rs +106 -0
  85. package/native/src/parsers/npm_audit_json.rs +119 -0
  86. package/native/src/parsers/prettier_text.rs +34 -0
  87. package/native/src/parsers/pylint_json.rs +44 -0
  88. package/native/src/parsers/pyright_json.rs +88 -0
  89. package/native/src/parsers/rspec_json.rs +84 -0
  90. package/native/src/parsers/rubocop_json.rs +46 -0
  91. package/native/src/parsers/ruff_json.rs +30 -0
  92. package/native/src/parsers/shellcheck_json.rs +40 -0
  93. package/native/src/parsers/stylelint_json.rs +46 -0
  94. package/native/src/parsers/swiftc_text.rs +38 -0
  95. package/native/src/parsers/tail_fallback.rs +51 -0
  96. package/native/src/parsers/test_helpers.rs +172 -0
  97. package/native/src/parsers/tidy_text.rs +77 -0
  98. package/native/src/parsers/tsc_text.rs +28 -0
  99. package/native/src/parsers/unittest_text.rs +125 -0
  100. package/native/src/parsers/vale_json.rs +66 -0
  101. package/native/src/parsers/vitest_json.rs +71 -0
  102. package/native/src/parsers/xml_support.rs +241 -0
  103. package/native/src/runner.rs +252 -0
  104. package/package.json +21 -7
  105. package/scripts/build-native.mjs +73 -0
  106. package/scripts/native-artifacts.mjs +69 -0
  107. package/skills/structured-return/SKILL.md +103 -249
  108. package/extensions/structured-return/config/project-config.ts +0 -10
  109. package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
  110. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
@@ -0,0 +1,119 @@
1
+ use crate::common::Context;
2
+ use serde_json::Value;
3
+ mod ava_text;
4
+ mod bandit_json;
5
+ mod black_text;
6
+ mod cargo_build;
7
+ mod cargo_test;
8
+ mod checkstyle_xml;
9
+ mod clang_text;
10
+ mod compiler_helpers;
11
+ mod dbt_json;
12
+ mod dotnet_build_text;
13
+ mod eslint_json;
14
+ mod go_test_json;
15
+ mod hadolint_json;
16
+ mod htmlhint_json;
17
+ mod isort_text;
18
+ mod javac_text;
19
+ mod json_support;
20
+ mod jsonlint_text;
21
+ mod junit_xml;
22
+ mod markdownlint_json;
23
+ mod minitest_text;
24
+ mod mocha_json;
25
+ mod mypy_json;
26
+ mod node_test_text;
27
+ mod npm_audit_json;
28
+ mod prettier_text;
29
+ mod pylint_json;
30
+ mod pyright_json;
31
+ mod rspec_json;
32
+ mod rubocop_json;
33
+ mod ruff_json;
34
+ mod shellcheck_json;
35
+ mod stylelint_json;
36
+ mod swiftc_text;
37
+ mod tail_fallback;
38
+ mod test_helpers;
39
+ mod tidy_text;
40
+ mod tsc_text;
41
+ mod unittest_text;
42
+ mod vale_json;
43
+ mod vitest_json;
44
+ mod xml_support;
45
+ pub fn parse(id: &str, ctx: &Context) -> Result<Value, String> {
46
+ match id {
47
+ "ava-text" => ava_text::parse(ctx),
48
+ "bandit-json" => bandit_json::parse(ctx),
49
+ "black-text" => black_text::parse(ctx),
50
+ "cargo-build" => cargo_build::parse(ctx),
51
+ "cargo-test" => cargo_test::parse(ctx),
52
+ "checkstyle-xml" => checkstyle_xml::parse(ctx),
53
+ "clang-text" => clang_text::parse(ctx),
54
+ "dbt-json" => dbt_json::parse(ctx),
55
+ "dotnet-build-text" => dotnet_build_text::parse(ctx),
56
+ "eslint-json" => eslint_json::parse(ctx),
57
+ "go-test-json" => go_test_json::parse(ctx),
58
+ "hadolint-json" => hadolint_json::parse(ctx),
59
+ "htmlhint-json" => htmlhint_json::parse(ctx),
60
+ "isort-text" => isort_text::parse(ctx),
61
+ "javac-text" => javac_text::parse(ctx),
62
+ "jsonlint-text" => jsonlint_text::parse(ctx),
63
+ "junit-xml" => junit_xml::parse(ctx),
64
+ "markdownlint-json" => markdownlint_json::parse(ctx),
65
+ "minitest-text" => minitest_text::parse(ctx),
66
+ "mocha-json" => mocha_json::parse(ctx),
67
+ "mypy-json" => mypy_json::parse(ctx),
68
+ "node-test-text" => node_test_text::parse(ctx),
69
+ "npm-audit-json" => npm_audit_json::parse(ctx),
70
+ "prettier-text" => prettier_text::parse(ctx),
71
+ "pylint-json" => pylint_json::parse(ctx),
72
+ "pyright-json" => pyright_json::parse(ctx),
73
+ "rspec-json" => rspec_json::parse(ctx),
74
+ "rubocop-json" => rubocop_json::parse(ctx),
75
+ "ruff-json" => ruff_json::parse(ctx),
76
+ "shellcheck-json" => shellcheck_json::parse(ctx),
77
+ "stylelint-json" => stylelint_json::parse(ctx),
78
+ "swiftc-text" => swiftc_text::parse(ctx),
79
+ "tail-fallback" => tail_fallback::parse(ctx),
80
+ "tidy-text" => tidy_text::parse(ctx),
81
+ "tsc-text" => tsc_text::parse(ctx),
82
+ "unittest-text" => unittest_text::parse(ctx),
83
+ "vale-json" => vale_json::parse(ctx),
84
+ "vitest-json" => vitest_json::parse(ctx),
85
+ _ => Err(format!("unknown parser: {id}")),
86
+ }
87
+ }
88
+
89
+ #[cfg(test)]
90
+ mod tests {
91
+ use super::*;
92
+ use std::fs;
93
+
94
+ #[test]
95
+ fn junit_derives_missing_counts_and_preserves_empty_failures() {
96
+ let directory = std::env::temp_dir().join(format!("sr-rust-test-{}", std::process::id()));
97
+ fs::create_dir_all(&directory).unwrap();
98
+ let report = directory.join("junit.xml");
99
+ fs::write(
100
+ &report,
101
+ "<testsuite><testcase name=\"broken\"><failure/></testcase></testsuite>",
102
+ )
103
+ .unwrap();
104
+ let ctx = Context {
105
+ command: String::new(),
106
+ argv: vec![],
107
+ cwd: directory.to_string_lossy().into_owned(),
108
+ artifact_paths: vec![report.to_string_lossy().into_owned()],
109
+ stdout_path: String::new(),
110
+ stderr_path: String::new(),
111
+ log_path: String::new(),
112
+ };
113
+ let parsed = parse("junit-xml", &ctx).unwrap();
114
+ fs::remove_dir_all(directory).unwrap();
115
+ assert_eq!(parsed["status"], "fail");
116
+ assert_eq!(parsed["summary"], "1 failed, 0 passed");
117
+ assert_eq!(parsed["failures"].as_array().unwrap().len(), 1);
118
+ }
119
+ }
@@ -0,0 +1,93 @@
1
+ use super::compiler_helpers::{relative_if_absolute, status, trim};
2
+ use crate::common::{read_file, result, string, truthy, Context};
3
+ use serde_json::{Map, Value};
4
+ use std::collections::HashMap;
5
+
6
+ fn location(item: &Value, ctx: &Context) -> Result<(String, String), String> {
7
+ let file = item
8
+ .get("file")
9
+ .and_then(Value::as_str)
10
+ .ok_or("mypy file is not a string")?;
11
+ let file = relative_if_absolute(&ctx.cwd, file);
12
+ let line = item
13
+ .get("line")
14
+ .map(string)
15
+ .unwrap_or_else(|| "undefined".into());
16
+ Ok((file.clone(), format!("{file}:{line}")))
17
+ }
18
+
19
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
20
+ let raw = read_file(&ctx.stderr_path)?;
21
+ let mut items = Vec::new();
22
+ for line in trim(&raw).split('\n') {
23
+ if trim(line).is_empty() {
24
+ continue;
25
+ }
26
+ if let Ok(item) = super::json_support::parse_json(trim(line)) {
27
+ if item.is_null() {
28
+ return Err("Cannot read properties of null (reading 'severity')".into());
29
+ }
30
+ items.push(item);
31
+ }
32
+ }
33
+ let mut notes: HashMap<String, Vec<String>> = HashMap::new();
34
+ for item in &items {
35
+ if item.get("severity").and_then(Value::as_str) != Some("note") {
36
+ continue;
37
+ }
38
+ let (_, key) = location(item, ctx)?;
39
+ let message = item
40
+ .get("message")
41
+ .filter(|value| !value.is_null())
42
+ .map(string)
43
+ .unwrap_or_default();
44
+ notes.entry(key).or_default().push(message);
45
+ }
46
+ let mut failures = Vec::new();
47
+ for item in &items {
48
+ if item.get("severity").and_then(Value::as_str) != Some("error") {
49
+ continue;
50
+ }
51
+ let (file, key) = location(item, ctx)?;
52
+ let code = item.get("code").filter(|value| !value.is_null());
53
+ let hint = item
54
+ .get("hint")
55
+ .filter(|value| !value.is_null())
56
+ .cloned()
57
+ .or_else(|| notes.get(&key).map(|notes| Value::String(notes.join("; "))));
58
+ let mut failure = Map::new();
59
+ failure.insert(
60
+ "id".into(),
61
+ Value::String(format!(
62
+ "{key}:{}",
63
+ code.map(string).unwrap_or_else(|| "error".into())
64
+ )),
65
+ );
66
+ failure.insert("file".into(), Value::String(file));
67
+ if let Some(line) = item.get("line") {
68
+ failure.insert("line".into(), line.clone());
69
+ }
70
+ if let Some(hint) = hint.as_ref().filter(|hint| truthy(hint)) {
71
+ let message = item
72
+ .get("message")
73
+ .map(string)
74
+ .unwrap_or_else(|| "undefined".into());
75
+ failure.insert(
76
+ "message".into(),
77
+ Value::String(format!("{message} ({})", string(hint))),
78
+ );
79
+ } else if let Some(message) = item.get("message") {
80
+ failure.insert("message".into(), message.clone());
81
+ }
82
+ if let Some(code) = code {
83
+ failure.insert("rule".into(), code.clone());
84
+ }
85
+ failures.push(Value::Object(failure));
86
+ }
87
+ let summary = if failures.is_empty() {
88
+ "no type errors".into()
89
+ } else {
90
+ format!("{} type errors", failures.len())
91
+ };
92
+ Ok(result("mypy", status(&failures), summary, failures, ctx))
93
+ }
@@ -0,0 +1,106 @@
1
+ use super::test_helpers::relative_direct;
2
+ use crate::common::{read_file, result, Context};
3
+ use regex::Regex;
4
+ use serde_json::{json, Map, Value};
5
+
6
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
7
+ let combined = read_file(&ctx.stdout_path)? + "\n" + &read_file(&ctx.stderr_path)?;
8
+ if combined.trim().is_empty() {
9
+ return Ok(result(
10
+ "node:test",
11
+ "pass",
12
+ "no tests found",
13
+ Vec::new(),
14
+ ctx,
15
+ ));
16
+ }
17
+ let pass_re = Regex::new(r"(?m)^ℹ pass ([0-9]+)").unwrap();
18
+ let fail_re = Regex::new(r"(?m)^ℹ fail ([0-9]+)").unwrap();
19
+ let passed = pass_re
20
+ .captures(&combined)
21
+ .map(|m| m[1].parse::<u64>().unwrap_or(0))
22
+ .unwrap_or(0);
23
+ let failed = fail_re
24
+ .captures(&combined)
25
+ .map(|m| m[1].parse::<u64>().unwrap_or(0))
26
+ .unwrap_or(0);
27
+ let section = combined.split("✖ failing tests:").nth(1).unwrap_or("");
28
+ let split_re = Regex::new(r"(?m)^test at ").unwrap();
29
+ let at_re = Regex::new(r"^test at (.+?):([0-9]+):[0-9]+").unwrap();
30
+ let name_re = Regex::new(r"(?m)^✖ (.+?) \(").unwrap();
31
+ let strict_re = Regex::new(r"Expected values to be strictly equal:\s*\n\s*\n\s*(.+)").unwrap();
32
+ let falsy_re =
33
+ Regex::new(r"The expression evaluated to a falsy value:\s*\n\s*\n\s*(.+)").unwrap();
34
+ let error_re = Regex::new(r"(?m)^\s+([A-Za-z0-9_]*Error\b.*?)$").unwrap();
35
+ let code_re = Regex::new(r"\s*\[ERR_[A-Za-z0-9_]+\]:\s*").unwrap();
36
+ let type_re = Regex::new(r"^[A-Za-z0-9_]+Error: ").unwrap();
37
+ let mut starts = vec![0];
38
+ starts.extend(
39
+ split_re
40
+ .find_iter(section)
41
+ .map(|m| m.start())
42
+ .filter(|position| *position != 0),
43
+ );
44
+ starts.push(section.len());
45
+ let mut failures = Vec::new();
46
+ for boundaries in starts.windows(2) {
47
+ let block = &section[boundaries[0]..boundaries[1]];
48
+ if block.trim().is_empty() {
49
+ continue;
50
+ }
51
+ let location = at_re.captures(block).map(|m| {
52
+ (
53
+ relative_direct(&ctx.cwd, &m[1]),
54
+ m[2].parse::<u64>().unwrap_or(0),
55
+ )
56
+ });
57
+ let name = name_re
58
+ .captures(block)
59
+ .map(|m| m[1].to_owned())
60
+ .unwrap_or_else(|| "unknown test".to_owned());
61
+ let message = if let Some(m) = strict_re.captures(block) {
62
+ format!("Expected values to be strictly equal: {}", m[1].trim())
63
+ } else if let Some(m) = falsy_re.captures(block) {
64
+ format!("The expression evaluated to a falsy value: {}", m[1].trim())
65
+ } else if let Some(m) = error_re.captures(block) {
66
+ type_re
67
+ .replace(&code_re.replace(&m[1], ": "), "")
68
+ .into_owned()
69
+ } else {
70
+ name
71
+ };
72
+ let mut failure = Map::new();
73
+ failure.insert(
74
+ "id".to_owned(),
75
+ json!(location
76
+ .as_ref()
77
+ .map(|(file, line)| format!("{file}:{line}"))
78
+ .unwrap_or_else(|| "undefined:undefined".to_owned())),
79
+ );
80
+ if let Some((file, line)) = location {
81
+ failure.insert("file".to_owned(), json!(file));
82
+ failure.insert("line".to_owned(), json!(line));
83
+ }
84
+ failure.insert("message".to_owned(), json!(message));
85
+ failures.push(Value::Object(failure));
86
+ }
87
+ let mut parts = Vec::new();
88
+ if failed > 0 {
89
+ parts.push(format!("{failed} failed"));
90
+ }
91
+ if passed > 0 {
92
+ parts.push(format!("{passed} passed"));
93
+ }
94
+ let summary = if parts.is_empty() {
95
+ "tests completed".to_owned()
96
+ } else {
97
+ parts.join(", ")
98
+ };
99
+ Ok(result(
100
+ "node:test",
101
+ if failed > 0 { "fail" } else { "pass" },
102
+ summary,
103
+ failures,
104
+ ctx,
105
+ ))
106
+ }
@@ -0,0 +1,119 @@
1
+ use super::json_support::{
2
+ copy_field, entries, is_one, js_string, null_object, number, parse_error, required_array,
3
+ };
4
+ use crate::common::{read_file, result, trim, truthy, Context};
5
+ use serde_json::{json, Map, Value};
6
+
7
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
8
+ let source = read_file(&ctx.stdout_path)?;
9
+ if trim(&source).is_empty() {
10
+ return Ok(result(
11
+ "npm audit",
12
+ "pass",
13
+ "no vulnerabilities found",
14
+ Vec::new(),
15
+ ctx,
16
+ ));
17
+ }
18
+ let report: Value = match super::json_support::parse_json(trim(&source)) {
19
+ Ok(v) => v,
20
+ Err(_) => return Ok(parse_error("npm audit", ctx)),
21
+ };
22
+ if let Some(error) = report.get("error").filter(|value| truthy(value)) {
23
+ let code = error
24
+ .get("code")
25
+ .filter(|value| truthy(value))
26
+ .map(|value| js_string(Some(value)));
27
+ let message = error
28
+ .get("summary")
29
+ .filter(|value| truthy(value))
30
+ .or_else(|| error.get("message").filter(|value| truthy(value)))
31
+ .map(|value| js_string(Some(value)))
32
+ .or_else(|| {
33
+ error
34
+ .as_str()
35
+ .filter(|text| !text.is_empty())
36
+ .map(str::to_owned)
37
+ });
38
+ let mut summary = "npm audit error".to_owned();
39
+ if let Some(code) = code {
40
+ summary.push(' ');
41
+ summary.push_str(&code);
42
+ }
43
+ if let Some(message) = message {
44
+ summary.push_str(": ");
45
+ summary.push_str(&message);
46
+ }
47
+ return Ok(result("npm audit", "error", summary, Vec::new(), ctx));
48
+ }
49
+ null_object(&report, "vulnerabilities")?;
50
+ let empty = json!({});
51
+ let vulnerabilities = report
52
+ .get("vulnerabilities")
53
+ .filter(|v| !v.is_null())
54
+ .unwrap_or(&empty);
55
+ let mut failures = Vec::new();
56
+ for (package, vulnerability) in entries(vulnerabilities)? {
57
+ let mut titles = Vec::new();
58
+ for via in required_array(vulnerability.get("via"), "via")? {
59
+ if via.is_string() {
60
+ continue;
61
+ }
62
+ null_object(via, "title")?;
63
+ if let Some(title) = via.get("title").filter(|v| truthy(v)) {
64
+ titles.push(js_string(Some(title)));
65
+ }
66
+ }
67
+ let message = if titles.is_empty() {
68
+ format!(
69
+ "{} severity vulnerability",
70
+ js_string(vulnerability.get("severity"))
71
+ )
72
+ } else {
73
+ titles.join("; ")
74
+ };
75
+ let mut out = Map::new();
76
+ out.insert("id".into(), json!(package));
77
+ out.insert("file".into(), json!(package));
78
+ out.insert("message".into(), json!(message));
79
+ copy_field(&mut out, "rule", vulnerability.get("severity"));
80
+ failures.push(Value::Object(out));
81
+ }
82
+ let metadata = report
83
+ .get("metadata")
84
+ .and_then(|v| v.get("vulnerabilities"))
85
+ .filter(|v| !v.is_null())
86
+ .unwrap_or(&empty);
87
+ let parts: Vec<_> = ["critical", "high", "moderate", "low", "info"]
88
+ .iter()
89
+ .filter_map(|name| {
90
+ metadata
91
+ .get(*name)
92
+ .filter(|v| truthy(v))
93
+ .map(|v| format!("{} {name}", js_string(Some(v))))
94
+ })
95
+ .collect();
96
+ let count = json!(failures.len());
97
+ let total = metadata
98
+ .get("total")
99
+ .filter(|v| !v.is_null())
100
+ .unwrap_or(&count);
101
+ let failed = number(Some(total)) > 0.0;
102
+ let summary = if failed {
103
+ format!(
104
+ "{} vulnerabilit{} ({})",
105
+ js_string(Some(total)),
106
+ if is_one(Some(total)) { "y" } else { "ies" },
107
+ parts.join(", ")
108
+ )
109
+ } else {
110
+ "no vulnerabilities found".into()
111
+ };
112
+ Ok(result(
113
+ "npm audit",
114
+ if failed { "fail" } else { "pass" },
115
+ summary,
116
+ failures,
117
+ ctx,
118
+ ))
119
+ }
@@ -0,0 +1,34 @@
1
+ use super::compiler_helpers::{node_relative, regex, status, trim};
2
+ use crate::common::{read_file, result, Context};
3
+ use serde_json::{json, Value};
4
+
5
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
6
+ let combined = read_file(&ctx.stdout_path)? + "\n" + &read_file(&ctx.stderr_path)?;
7
+ let warning = regex(r"^\[warn\] (.+)$");
8
+ let footer = regex(
9
+ r"^Code style issues found in (?:the above file|\d+ files)\. Run Prettier with --write to fix\.$",
10
+ );
11
+ let mut failures = Vec::new();
12
+ for line in trim(&combined).lines() {
13
+ let Some(m) = warning.captures(line) else {
14
+ continue;
15
+ };
16
+ if footer.is_match(&m[1]) || &m[1] == "Run Prettier with --write to fix." {
17
+ continue;
18
+ }
19
+ let file = node_relative(&ctx.cwd, &m[1])?;
20
+ failures.push(json!({"id":file,"file":file,"message":"needs formatting"}));
21
+ }
22
+ let summary = match failures.len() {
23
+ 0 => "all files formatted".into(),
24
+ 1 => "1 file has formatting issues".into(),
25
+ count => format!("{count} files have formatting issues"),
26
+ };
27
+ Ok(result(
28
+ "prettier",
29
+ status(&failures),
30
+ summary,
31
+ failures,
32
+ ctx,
33
+ ))
34
+ }
@@ -0,0 +1,44 @@
1
+ use super::json_support::{
2
+ copy_field, js_string, lint_result, parse_error, relative_absolute, required_array,
3
+ required_string,
4
+ };
5
+ use crate::common::{read_file, trim, Context};
6
+ use serde_json::{json, Map, Value};
7
+
8
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
9
+ let source = read_file(&ctx.stdout_path)?;
10
+ if trim(&source).is_empty() || trim(&source) == "[]" {
11
+ return Ok(lint_result("pylint", Vec::new(), ctx));
12
+ }
13
+ let data: Value = match super::json_support::parse_json(trim(&source)) {
14
+ Ok(value) => value,
15
+ Err(_) => return Ok(parse_error("pylint", ctx)),
16
+ };
17
+ let mut failures = Vec::new();
18
+ for item in required_array(Some(&data), "pylint items")? {
19
+ let file = relative_absolute(&ctx.cwd, required_string(item.get("path"), "path")?);
20
+ let mut out = Map::new();
21
+ out.insert(
22
+ "id".into(),
23
+ json!(format!(
24
+ "{}:{}:{}",
25
+ file,
26
+ js_string(item.get("line")),
27
+ js_string(item.get("message-id"))
28
+ )),
29
+ );
30
+ out.insert("file".into(), json!(file));
31
+ copy_field(&mut out, "line", item.get("line"));
32
+ copy_field(&mut out, "message", item.get("message"));
33
+ out.insert(
34
+ "rule".into(),
35
+ json!(format!(
36
+ "{}({})",
37
+ js_string(item.get("message-id")),
38
+ js_string(item.get("symbol"))
39
+ )),
40
+ );
41
+ failures.push(Value::Object(out));
42
+ }
43
+ Ok(lint_result("pylint", failures, ctx))
44
+ }
@@ -0,0 +1,88 @@
1
+ use super::json_support::{
2
+ add_one, copy_field, is_one, js_string, null_object, parse_error, relative_input,
3
+ required_array, required_string,
4
+ };
5
+ use crate::common::{read_file, result, trim, truthy, Context};
6
+ use serde_json::{json, Map, Value};
7
+
8
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
9
+ let source = read_file(&ctx.stdout_path)?;
10
+ if trim(&source).is_empty() {
11
+ return Ok(result("pyright", "pass", "no type errors", Vec::new(), ctx));
12
+ }
13
+ let report: Value = match super::json_support::parse_json(trim(&source)) {
14
+ Ok(v) => v,
15
+ Err(_) => return Ok(parse_error("pyright", ctx)),
16
+ };
17
+ null_object(&report, "generalDiagnostics")?;
18
+ let diagnostics = match report.get("generalDiagnostics").filter(|v| !v.is_null()) {
19
+ Some(v) => required_array(Some(v), "generalDiagnostics")?,
20
+ None => &[],
21
+ };
22
+ let mut failures = Vec::new();
23
+ for item in diagnostics {
24
+ null_object(item, "severity")?;
25
+ if item.get("severity").and_then(Value::as_str) != Some("error") {
26
+ continue;
27
+ }
28
+ let file = relative_input(&ctx.cwd, required_string(item.get("file"), "file")?);
29
+ let line = if let Some(range) = item.get("range").filter(|v| truthy(v)) {
30
+ let start = range.get("start").ok_or("range.start is missing")?;
31
+ null_object(start, "line")?;
32
+ Some(add_one(start.get("line")))
33
+ } else {
34
+ None
35
+ };
36
+ let message = required_string(item.get("message"), "message")?
37
+ .split('\n')
38
+ .next()
39
+ .unwrap_or("");
40
+ let rule = item.get("rule").filter(|v| !v.is_null());
41
+ let mut out = Map::new();
42
+ let line_id = if line.as_ref().is_some_and(Value::is_null) {
43
+ "NaN".into()
44
+ } else {
45
+ js_string(line.as_ref())
46
+ };
47
+ out.insert(
48
+ "id".into(),
49
+ json!(format!(
50
+ "{}:{}:{}",
51
+ file,
52
+ line_id,
53
+ rule.map(|v| js_string(Some(v)))
54
+ .unwrap_or_else(|| "error".into())
55
+ )),
56
+ );
57
+ out.insert("file".into(), json!(file));
58
+ copy_field(&mut out, "line", line.as_ref());
59
+ out.insert("message".into(), json!(message));
60
+ copy_field(&mut out, "rule", item.get("rule"));
61
+ failures.push(Value::Object(out));
62
+ }
63
+ let mut parts = Vec::new();
64
+ if let Some(summary) = report.get("summary").filter(|v| truthy(v)) {
65
+ for (field, name) in [("errorCount", "error"), ("warningCount", "warning")] {
66
+ if let Some(value) = summary.get(field).filter(|v| truthy(v)) {
67
+ parts.push(format!(
68
+ "{} {}{}",
69
+ js_string(Some(value)),
70
+ name,
71
+ if is_one(Some(value)) { "" } else { "s" }
72
+ ));
73
+ }
74
+ }
75
+ }
76
+ let summary = if parts.is_empty() {
77
+ "no type errors".into()
78
+ } else {
79
+ parts.join(", ")
80
+ };
81
+ Ok(result(
82
+ "pyright",
83
+ if failures.is_empty() { "pass" } else { "fail" },
84
+ summary,
85
+ failures,
86
+ ctx,
87
+ ))
88
+ }
@@ -0,0 +1,84 @@
1
+ use super::test_helpers::{js_string, number, number_text, optional, text, without_failures};
2
+ use crate::common::{read_file, relative, result, trim, truthy, Context};
3
+ use serde_json::{json, Map, Value};
4
+
5
+ pub fn parse(ctx: &Context) -> Result<Value, String> {
6
+ let stdout = read_file(&ctx.stdout_path)?;
7
+ let stdout = trim(&stdout);
8
+ let report: Value = if stdout.is_empty() {
9
+ Value::Null
10
+ } else {
11
+ super::json_support::parse_json(stdout).map_err(|e| e.to_string())?
12
+ };
13
+ if !truthy(&report) {
14
+ return Ok(without_failures("rspec", "error", "no output", ctx));
15
+ }
16
+ let examples = report
17
+ .get("examples")
18
+ .and_then(Value::as_array)
19
+ .ok_or("RSpec examples must be an array")?;
20
+ let mut failures = Vec::new();
21
+ for example in examples
22
+ .iter()
23
+ .filter(|e| e.get("status").and_then(Value::as_str) == Some("failed"))
24
+ {
25
+ let mut failure = Map::new();
26
+ optional(&mut failure, "id", example.get("id"));
27
+ failure.insert(
28
+ "file".to_owned(),
29
+ json!(relative(
30
+ &ctx.cwd,
31
+ &text(example.get("file_path"), "file_path")?
32
+ )),
33
+ );
34
+ optional(&mut failure, "line", example.get("line_number"));
35
+ if let Some(exception) = example.get("exception").filter(|v| truthy(v)) {
36
+ let message = text(exception.get("message"), "exception.message")?;
37
+ let paragraph = message
38
+ .trim()
39
+ .split('\n')
40
+ .take_while(|line| !line.trim().is_empty())
41
+ .map(str::trim)
42
+ .collect::<Vec<_>>()
43
+ .join(" / ");
44
+ failure.insert("message".to_owned(), json!(paragraph));
45
+ } else {
46
+ optional(&mut failure, "message", example.get("full_description"));
47
+ }
48
+ failures.push(Value::Object(failure));
49
+ }
50
+ let summary = report
51
+ .get("summary")
52
+ .filter(|v| !v.is_null())
53
+ .ok_or("RSpec summary is missing")?;
54
+ let failed = summary.get("failure_count");
55
+ let passed = number(summary.get("example_count"))
56
+ - number(failed)
57
+ - number(summary.get("pending_count"));
58
+ let outside = number(summary.get("errors_outside_of_examples_count"));
59
+ let mut parts = Vec::new();
60
+ if number(failed) > 0.0 {
61
+ parts.push(format!("{} failed", js_string(failed)));
62
+ }
63
+ if outside > 0.0 {
64
+ parts.push(format!(
65
+ "{} error{} outside examples",
66
+ number_text(outside),
67
+ if outside == 1.0 { "" } else { "s" }
68
+ ));
69
+ let message = report
70
+ .get("summary_line")
71
+ .and_then(Value::as_str)
72
+ .filter(|message| !message.trim().is_empty())
73
+ .unwrap_or("error outside examples");
74
+ failures.push(json!({"id":"runner","message":message}));
75
+ }
76
+ parts.push(format!("{} passed", number_text(passed)));
77
+ let status = if number(failed) > 0.0 || outside > 0.0 {
78
+ "fail"
79
+ } else {
80
+ "pass"
81
+ };
82
+ let summary = parts.join(", ");
83
+ Ok(result("rspec", status, summary, failures, ctx))
84
+ }