@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.
- package/LICENSE +21 -0
- package/README.md +37 -83
- package/extensions/structured-return/config/registry.ts +4 -36
- package/extensions/structured-return/index.ts +105 -90
- package/extensions/structured-return/native.ts +223 -0
- package/extensions/structured-return/parsers/ava-text.ts +2 -168
- package/extensions/structured-return/parsers/bandit-json.ts +2 -79
- package/extensions/structured-return/parsers/black-text.ts +2 -73
- package/extensions/structured-return/parsers/cargo-build.ts +2 -78
- package/extensions/structured-return/parsers/cargo-test.ts +2 -135
- package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
- package/extensions/structured-return/parsers/clang-text.ts +2 -60
- package/extensions/structured-return/parsers/dbt-json.ts +2 -135
- package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
- package/extensions/structured-return/parsers/eslint-json.ts +2 -38
- package/extensions/structured-return/parsers/go-test-json.ts +2 -138
- package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
- package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
- package/extensions/structured-return/parsers/isort-text.ts +2 -63
- package/extensions/structured-return/parsers/javac-text.ts +2 -82
- package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
- package/extensions/structured-return/parsers/junit-xml.ts +2 -325
- package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
- package/extensions/structured-return/parsers/minitest-text.ts +2 -107
- package/extensions/structured-return/parsers/mocha-json.ts +2 -83
- package/extensions/structured-return/parsers/mypy-json.ts +2 -79
- package/extensions/structured-return/parsers/node-test-text.ts +2 -92
- package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
- package/extensions/structured-return/parsers/prettier-text.ts +2 -66
- package/extensions/structured-return/parsers/pylint-json.ts +2 -63
- package/extensions/structured-return/parsers/pyright-json.ts +2 -82
- package/extensions/structured-return/parsers/rspec-json.ts +2 -75
- package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
- package/extensions/structured-return/parsers/ruff-json.ts +2 -36
- package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
- package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
- package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
- package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
- package/extensions/structured-return/parsers/tidy-text.ts +2 -66
- package/extensions/structured-return/parsers/tsc-text.ts +2 -46
- package/extensions/structured-return/parsers/unittest-text.ts +2 -125
- package/extensions/structured-return/parsers/utils.ts +28 -0
- package/extensions/structured-return/parsers/vale-json.ts +2 -79
- package/extensions/structured-return/parsers/vitest-json.ts +2 -59
- package/extensions/structured-return/storage/log-store.ts +0 -15
- package/extensions/structured-return/types.ts +1 -14
- package/native/Cargo.lock +193 -0
- package/native/Cargo.toml +21 -0
- package/native/THIRD-PARTY-LICENSES.txt +3660 -0
- package/native/bin/darwin-arm64/build.json +7 -0
- package/native/bin/darwin-arm64/structured-return-native +0 -0
- package/native/bin/darwin-x64/build.json +7 -0
- package/native/bin/darwin-x64/structured-return-native +0 -0
- package/native/bin/linux-arm64-musl/build.json +7 -0
- package/native/bin/linux-arm64-musl/structured-return-native +0 -0
- package/native/bin/linux-x64-musl/build.json +7 -0
- package/native/bin/linux-x64-musl/structured-return-native +0 -0
- package/native/src/common.rs +118 -0
- package/native/src/main.rs +55 -0
- package/native/src/parsers/ava_text.rs +125 -0
- package/native/src/parsers/bandit_json.rs +120 -0
- package/native/src/parsers/black_text.rs +45 -0
- package/native/src/parsers/cargo_build.rs +96 -0
- package/native/src/parsers/cargo_test.rs +140 -0
- package/native/src/parsers/checkstyle_xml.rs +137 -0
- package/native/src/parsers/clang_text.rs +39 -0
- package/native/src/parsers/compiler_helpers.rs +74 -0
- package/native/src/parsers/dbt_json.rs +243 -0
- package/native/src/parsers/dotnet_build_text.rs +50 -0
- package/native/src/parsers/eslint_json.rs +58 -0
- package/native/src/parsers/go_test_json.rs +346 -0
- package/native/src/parsers/hadolint_json.rs +37 -0
- package/native/src/parsers/htmlhint_json.rs +71 -0
- package/native/src/parsers/isort_text.rs +22 -0
- package/native/src/parsers/javac_text.rs +49 -0
- package/native/src/parsers/json_support.rs +287 -0
- package/native/src/parsers/jsonlint_text.rs +50 -0
- package/native/src/parsers/junit_xml.rs +430 -0
- package/native/src/parsers/markdownlint_json.rs +68 -0
- package/native/src/parsers/minitest_text.rs +91 -0
- package/native/src/parsers/mocha_json.rs +75 -0
- package/native/src/parsers/mod.rs +119 -0
- package/native/src/parsers/mypy_json.rs +93 -0
- package/native/src/parsers/node_test_text.rs +106 -0
- package/native/src/parsers/npm_audit_json.rs +119 -0
- package/native/src/parsers/prettier_text.rs +34 -0
- package/native/src/parsers/pylint_json.rs +44 -0
- package/native/src/parsers/pyright_json.rs +88 -0
- package/native/src/parsers/rspec_json.rs +84 -0
- package/native/src/parsers/rubocop_json.rs +46 -0
- package/native/src/parsers/ruff_json.rs +30 -0
- package/native/src/parsers/shellcheck_json.rs +40 -0
- package/native/src/parsers/stylelint_json.rs +46 -0
- package/native/src/parsers/swiftc_text.rs +38 -0
- package/native/src/parsers/tail_fallback.rs +51 -0
- package/native/src/parsers/test_helpers.rs +172 -0
- package/native/src/parsers/tidy_text.rs +77 -0
- package/native/src/parsers/tsc_text.rs +28 -0
- package/native/src/parsers/unittest_text.rs +125 -0
- package/native/src/parsers/vale_json.rs +66 -0
- package/native/src/parsers/vitest_json.rs +71 -0
- package/native/src/parsers/xml_support.rs +241 -0
- package/native/src/runner.rs +252 -0
- package/package.json +21 -7
- package/scripts/build-native.mjs +73 -0
- package/scripts/native-artifacts.mjs +69 -0
- package/skills/structured-return/SKILL.md +103 -249
- package/extensions/structured-return/config/project-config.ts +0 -10
- package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
|
@@ -0,0 +1,46 @@
|
|
|
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() {
|
|
11
|
+
return Ok(lint_result("rubocop", 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("rubocop", ctx)),
|
|
16
|
+
};
|
|
17
|
+
let mut failures = Vec::new();
|
|
18
|
+
for file_entry in required_array(report.get("files"), "files")? {
|
|
19
|
+
let file = relative_absolute(&ctx.cwd, required_string(file_entry.get("path"), "path")?);
|
|
20
|
+
for item in required_array(file_entry.get("offenses"), "offenses")? {
|
|
21
|
+
let rule = required_string(item.get("cop_name"), "cop_name")?;
|
|
22
|
+
let message = required_string(item.get("message"), "message")?;
|
|
23
|
+
let prefix = format!("{rule}:");
|
|
24
|
+
let message = message
|
|
25
|
+
.strip_prefix(&prefix)
|
|
26
|
+
.map(str::trim_start)
|
|
27
|
+
.unwrap_or(message);
|
|
28
|
+
let location = item
|
|
29
|
+
.get("location")
|
|
30
|
+
.filter(|v| !v.is_null())
|
|
31
|
+
.ok_or("location is missing")?;
|
|
32
|
+
let line = location.get("line");
|
|
33
|
+
let mut out = Map::new();
|
|
34
|
+
out.insert(
|
|
35
|
+
"id".into(),
|
|
36
|
+
json!(format!("{}:{}:{}", file, js_string(line), rule)),
|
|
37
|
+
);
|
|
38
|
+
out.insert("file".into(), json!(file));
|
|
39
|
+
copy_field(&mut out, "line", line);
|
|
40
|
+
out.insert("message".into(), json!(message));
|
|
41
|
+
out.insert("rule".into(), json!(rule));
|
|
42
|
+
failures.push(Value::Object(out));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
Ok(lint_result("rubocop", failures, ctx))
|
|
46
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
use super::json_support::{
|
|
2
|
+
array, copy_field, js_string, lint_result, read_json, relative_input, required_string,
|
|
3
|
+
};
|
|
4
|
+
use crate::common::Context;
|
|
5
|
+
use serde_json::{json, Map, Value};
|
|
6
|
+
|
|
7
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
8
|
+
let items = read_json(&ctx.stdout_path, json!([]))?;
|
|
9
|
+
let mut failures = Vec::new();
|
|
10
|
+
for item in array(&items) {
|
|
11
|
+
let file = relative_input(&ctx.cwd, required_string(item.get("filename"), "filename")?);
|
|
12
|
+
let line = item.get("location").and_then(|v| v.get("row"));
|
|
13
|
+
let mut out = Map::new();
|
|
14
|
+
out.insert(
|
|
15
|
+
"id".into(),
|
|
16
|
+
json!(format!(
|
|
17
|
+
"{}:{}:{}",
|
|
18
|
+
file,
|
|
19
|
+
js_string(line),
|
|
20
|
+
js_string(item.get("code"))
|
|
21
|
+
)),
|
|
22
|
+
);
|
|
23
|
+
out.insert("file".into(), json!(file));
|
|
24
|
+
copy_field(&mut out, "line", line);
|
|
25
|
+
copy_field(&mut out, "message", item.get("message"));
|
|
26
|
+
copy_field(&mut out, "rule", item.get("code"));
|
|
27
|
+
failures.push(Value::Object(out));
|
|
28
|
+
}
|
|
29
|
+
Ok(lint_result("ruff", failures, ctx))
|
|
30
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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("shellcheck", 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("shellcheck", ctx)),
|
|
16
|
+
};
|
|
17
|
+
let mut failures = Vec::new();
|
|
18
|
+
for item in required_array(Some(&data), "shellcheck items")? {
|
|
19
|
+
let file = relative_absolute(&ctx.cwd, required_string(item.get("file"), "file")?);
|
|
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
|
+
format!("SC{}", js_string(item.get("code")))
|
|
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!("SC{}", js_string(item.get("code")))),
|
|
36
|
+
);
|
|
37
|
+
failures.push(Value::Object(out));
|
|
38
|
+
}
|
|
39
|
+
Ok(lint_result("shellcheck", failures, ctx))
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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("stylelint", 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("stylelint", ctx)),
|
|
16
|
+
};
|
|
17
|
+
let mut failures = Vec::new();
|
|
18
|
+
for file_entry in required_array(Some(&report), "stylelint results")? {
|
|
19
|
+
let file = relative_absolute(
|
|
20
|
+
&ctx.cwd,
|
|
21
|
+
required_string(file_entry.get("source"), "source")?,
|
|
22
|
+
);
|
|
23
|
+
for warning in required_array(file_entry.get("warnings"), "warnings")? {
|
|
24
|
+
let text = required_string(warning.get("text"), "text")?;
|
|
25
|
+
let rule = warning.get("rule");
|
|
26
|
+
let suffix = format!(" ({})", js_string(rule));
|
|
27
|
+
let message = text.strip_suffix(&suffix).unwrap_or(text);
|
|
28
|
+
let mut out = Map::new();
|
|
29
|
+
out.insert(
|
|
30
|
+
"id".into(),
|
|
31
|
+
json!(format!(
|
|
32
|
+
"{}:{}:{}",
|
|
33
|
+
file,
|
|
34
|
+
js_string(warning.get("line")),
|
|
35
|
+
js_string(rule)
|
|
36
|
+
)),
|
|
37
|
+
);
|
|
38
|
+
out.insert("file".into(), json!(file));
|
|
39
|
+
copy_field(&mut out, "line", warning.get("line"));
|
|
40
|
+
out.insert("message".into(), json!(message));
|
|
41
|
+
copy_field(&mut out, "rule", rule);
|
|
42
|
+
failures.push(Value::Object(out));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
Ok(lint_result("stylelint", failures, ctx))
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
use super::compiler_helpers::{number, regex, relative_if_absolute, status, trim};
|
|
2
|
+
use crate::common::{read_file, result, Context};
|
|
3
|
+
use serde_json::{json, Value};
|
|
4
|
+
use std::collections::HashSet;
|
|
5
|
+
|
|
6
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
7
|
+
let stderr = read_file(&ctx.stderr_path)?;
|
|
8
|
+
let issue = regex(r"^(.+?):(\d+):\d+:\s+(error|warning):\s+(.+)$");
|
|
9
|
+
let driver_issue = regex(r"^(?:(?:swiftc|<unknown>:0):\s*)?error:\s+(.+)$");
|
|
10
|
+
let mut seen = HashSet::new();
|
|
11
|
+
let mut failures = Vec::new();
|
|
12
|
+
for line in trim(&stderr).lines() {
|
|
13
|
+
if let Some(m) = driver_issue.captures(line) {
|
|
14
|
+
if seen.insert(m[1].to_owned()) {
|
|
15
|
+
failures.push(json!({"id":&m[1],"message":&m[1]}));
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
let Some(m) = issue.captures(line) else {
|
|
20
|
+
continue;
|
|
21
|
+
};
|
|
22
|
+
if &m[3] != "error" {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
let file = relative_if_absolute(&ctx.cwd, &m[1]);
|
|
26
|
+
let id = format!("{file}:{}:{}", &m[2], &m[4]);
|
|
27
|
+
if !seen.insert(id.clone()) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
failures.push(json!({"id":id,"file":file,"line":number(&m[2]),"message":&m[4]}));
|
|
31
|
+
}
|
|
32
|
+
let summary = if failures.is_empty() {
|
|
33
|
+
"no errors".into()
|
|
34
|
+
} else {
|
|
35
|
+
format!("{} errors", failures.len())
|
|
36
|
+
};
|
|
37
|
+
Ok(result("swiftc", status(&failures), summary, failures, ctx))
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
use crate::common::Context;
|
|
2
|
+
use serde_json::{json, Value};
|
|
3
|
+
use std::fs::File;
|
|
4
|
+
use std::io::{Read, Seek, SeekFrom};
|
|
5
|
+
|
|
6
|
+
/// Read only the bytes needed for JS `split(/\r?\n/).slice(-200).join("\n")`.
|
|
7
|
+
/// A single very long line still needs to be returned completely, as before.
|
|
8
|
+
pub fn read_tail(path: &str) -> Result<String, String> {
|
|
9
|
+
let mut file = match File::open(path) {
|
|
10
|
+
Ok(file) => file,
|
|
11
|
+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(String::new()),
|
|
12
|
+
Err(error) => return Err(format!("{path}: {error}")),
|
|
13
|
+
};
|
|
14
|
+
let mut offset = file
|
|
15
|
+
.metadata()
|
|
16
|
+
.map_err(|error| format!("{path}: {error}"))?
|
|
17
|
+
.len();
|
|
18
|
+
let mut chunks = Vec::new();
|
|
19
|
+
let mut newline_count = 0;
|
|
20
|
+
while offset > 0 && newline_count < 200 {
|
|
21
|
+
let size = offset.min(64 * 1024) as usize;
|
|
22
|
+
offset -= size as u64;
|
|
23
|
+
file.seek(SeekFrom::Start(offset))
|
|
24
|
+
.map_err(|error| format!("{path}: {error}"))?;
|
|
25
|
+
let mut chunk = vec![0; size];
|
|
26
|
+
file.read_exact(&mut chunk)
|
|
27
|
+
.map_err(|error| format!("{path}: {error}"))?;
|
|
28
|
+
newline_count += chunk.iter().filter(|&&byte| byte == b'\n').count();
|
|
29
|
+
chunks.push(chunk);
|
|
30
|
+
}
|
|
31
|
+
let size = chunks.iter().map(Vec::len).sum();
|
|
32
|
+
let mut bytes = Vec::with_capacity(size);
|
|
33
|
+
for chunk in chunks.into_iter().rev() {
|
|
34
|
+
bytes.extend(chunk);
|
|
35
|
+
}
|
|
36
|
+
let start = bytes
|
|
37
|
+
.iter()
|
|
38
|
+
.enumerate()
|
|
39
|
+
.rev()
|
|
40
|
+
.filter(|(_, byte)| **byte == b'\n')
|
|
41
|
+
.nth(199)
|
|
42
|
+
.map(|(index, _)| index + 1)
|
|
43
|
+
.unwrap_or(0);
|
|
44
|
+
Ok(String::from_utf8_lossy(&bytes[start..]).replace("\r\n", "\n"))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
48
|
+
Ok(json!({"tool":"unknown","status":"error",
|
|
49
|
+
"summary":"no parser matched; returning tail + log path",
|
|
50
|
+
"logPath":ctx.log_path,"rawTail":read_tail(&ctx.log_path)?}))
|
|
51
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
use crate::common::Context;
|
|
2
|
+
use regex::Regex;
|
|
3
|
+
use serde_json::{json, Map, Value};
|
|
4
|
+
|
|
5
|
+
pub fn without_failures(tool: &str, status: &str, summary: &str, ctx: &Context) -> Value {
|
|
6
|
+
json!({"tool":tool,"status":status,"summary":summary,"logPath":ctx.log_path})
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
pub fn optional(out: &mut Map<String, Value>, key: &str, value: Option<&Value>) {
|
|
10
|
+
if let Some(value) = value {
|
|
11
|
+
out.insert(key.to_owned(), value.clone());
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pub fn text(value: Option<&Value>, name: &str) -> Result<String, String> {
|
|
16
|
+
value
|
|
17
|
+
.and_then(Value::as_str)
|
|
18
|
+
.map(str::to_owned)
|
|
19
|
+
.ok_or_else(|| format!("{name} must be a string"))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub fn number(value: Option<&Value>) -> f64 {
|
|
23
|
+
match value {
|
|
24
|
+
None => f64::NAN,
|
|
25
|
+
Some(Value::Null) => 0.0,
|
|
26
|
+
Some(Value::Bool(v)) => {
|
|
27
|
+
if *v {
|
|
28
|
+
1.0
|
|
29
|
+
} else {
|
|
30
|
+
0.0
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
Some(Value::Number(v)) => v.as_f64().unwrap_or(f64::NAN),
|
|
34
|
+
Some(Value::String(v)) => {
|
|
35
|
+
if v.trim().is_empty() {
|
|
36
|
+
0.0
|
|
37
|
+
} else {
|
|
38
|
+
v.trim().parse().unwrap_or(f64::NAN)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
Some(_) => f64::NAN,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
pub fn number_text(value: f64) -> String {
|
|
46
|
+
if value.is_nan() {
|
|
47
|
+
"NaN".to_owned()
|
|
48
|
+
} else if value == 0.0 {
|
|
49
|
+
"0".to_owned()
|
|
50
|
+
} else if value == f64::INFINITY {
|
|
51
|
+
"Infinity".to_owned()
|
|
52
|
+
} else if value == f64::NEG_INFINITY {
|
|
53
|
+
"-Infinity".to_owned()
|
|
54
|
+
} else {
|
|
55
|
+
value.to_string()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// JavaScript interpolation is intentionally retained, including the legacy
|
|
60
|
+
// "[object Object]" representation of assertion values in Mocha reports.
|
|
61
|
+
pub fn js_string(value: Option<&Value>) -> String {
|
|
62
|
+
match value {
|
|
63
|
+
None => "undefined".to_owned(),
|
|
64
|
+
Some(Value::Null) => "null".to_owned(),
|
|
65
|
+
Some(Value::String(s)) => s.clone(),
|
|
66
|
+
Some(Value::Number(n)) => number_text(n.as_f64().unwrap_or(f64::NAN)),
|
|
67
|
+
Some(Value::Bool(b)) => b.to_string(),
|
|
68
|
+
Some(Value::Array(a)) => a
|
|
69
|
+
.iter()
|
|
70
|
+
.map(|v| {
|
|
71
|
+
if v.is_null() {
|
|
72
|
+
String::new()
|
|
73
|
+
} else {
|
|
74
|
+
js_string(Some(v))
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.collect::<Vec<_>>()
|
|
78
|
+
.join(","),
|
|
79
|
+
Some(Value::Object(_)) => "[object Object]".to_owned(),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Stack traces use canonical local file URLs for ESM. Accept only an empty
|
|
84
|
+
// authority or localhost: a remote file host is not a local filesystem path.
|
|
85
|
+
fn local_file_url(url: &str) -> Option<String> {
|
|
86
|
+
let rest = url.strip_prefix("file://")?;
|
|
87
|
+
let slash = rest.find('/')?;
|
|
88
|
+
let (host, path) = rest.split_at(slash);
|
|
89
|
+
if !host.is_empty() && !host.eq_ignore_ascii_case("localhost") {
|
|
90
|
+
return None;
|
|
91
|
+
}
|
|
92
|
+
let path = path.split(['?', '#']).next()?;
|
|
93
|
+
let bytes = path.as_bytes();
|
|
94
|
+
let mut decoded = Vec::with_capacity(bytes.len());
|
|
95
|
+
let mut index = 0;
|
|
96
|
+
while index < bytes.len() {
|
|
97
|
+
if bytes[index] == b'%' {
|
|
98
|
+
let high = (*bytes.get(index + 1)? as char).to_digit(16)?;
|
|
99
|
+
let low = (*bytes.get(index + 2)? as char).to_digit(16)?;
|
|
100
|
+
let byte = (high * 16 + low) as u8;
|
|
101
|
+
// Encoded separators are not valid local file-URL path segments.
|
|
102
|
+
if byte == b'/' || byte == 0 || (cfg!(windows) && byte == b'\\') {
|
|
103
|
+
return None;
|
|
104
|
+
}
|
|
105
|
+
decoded.push(byte);
|
|
106
|
+
index += 3;
|
|
107
|
+
} else {
|
|
108
|
+
decoded.push(bytes[index]);
|
|
109
|
+
index += 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let decoded = String::from_utf8(decoded).ok()?;
|
|
113
|
+
#[cfg(windows)]
|
|
114
|
+
let decoded = {
|
|
115
|
+
let bytes = decoded.as_bytes();
|
|
116
|
+
if bytes.len() >= 4
|
|
117
|
+
&& bytes[0] == b'/'
|
|
118
|
+
&& bytes[1].is_ascii_alphabetic()
|
|
119
|
+
&& bytes[2] == b':'
|
|
120
|
+
&& bytes[3] == b'/'
|
|
121
|
+
{
|
|
122
|
+
decoded[1..].to_owned()
|
|
123
|
+
} else {
|
|
124
|
+
return None;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
Some(decoded)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
pub fn stack_location(stack: Option<&Value>) -> Result<Option<(String, u64)>, String> {
|
|
131
|
+
let Some(stack) = stack.filter(|v| crate::common::truthy(v)) else {
|
|
132
|
+
return Ok(None);
|
|
133
|
+
};
|
|
134
|
+
let stack = stack.as_str().ok_or("stack must be a string")?;
|
|
135
|
+
// Take the final line/column suffix before decoding the URL. The path
|
|
136
|
+
// can contain ')' and the module URL can have a query or fragment.
|
|
137
|
+
let with_parens = Regex::new(r"^\s*at\s+.+?\s+\((.+):([0-9]+):[0-9]+\)\s*$").unwrap();
|
|
138
|
+
let bare = Regex::new(r"^\s*at\s+(.+):([0-9]+):[0-9]+\s*$").unwrap();
|
|
139
|
+
let extension = Regex::new(r"\.(?:[jt]sx?|mjs|cjs)$").unwrap();
|
|
140
|
+
for line in stack.split('\n') {
|
|
141
|
+
if let Some(m) = with_parens.captures(line).or_else(|| bare.captures(line)) {
|
|
142
|
+
let file = if m[1].starts_with("file://") {
|
|
143
|
+
let Some(local) = local_file_url(&m[1]) else {
|
|
144
|
+
continue;
|
|
145
|
+
};
|
|
146
|
+
local
|
|
147
|
+
} else {
|
|
148
|
+
m[1].to_owned()
|
|
149
|
+
};
|
|
150
|
+
if extension.is_match(&file)
|
|
151
|
+
&& !file.contains("node_modules")
|
|
152
|
+
&& !file.contains("node:")
|
|
153
|
+
{
|
|
154
|
+
return Ok(Some((file, m[2].parse().map_err(|e| format!("{e}"))?)));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
Ok(None)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
pub fn relative_if_absolute(cwd: &str, file: &str) -> String {
|
|
162
|
+
if std::path::Path::new(file).is_absolute() {
|
|
163
|
+
crate::common::relative(cwd, file)
|
|
164
|
+
} else {
|
|
165
|
+
file.to_owned()
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Test reporters emit paths relative to the command directory.
|
|
170
|
+
pub fn relative_direct(cwd: &str, file: &str) -> String {
|
|
171
|
+
crate::common::relative(cwd, file)
|
|
172
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
use super::compiler_helpers::{number, regex, 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 stderr = read_file(&ctx.stderr_path)?;
|
|
7
|
+
let issue = regex(r"^line (\d+) column \d+ - (Warning|Error): (.+)$");
|
|
8
|
+
let summary_pattern = regex(r"^(\d+) warnings?, (\d+) errors? were found");
|
|
9
|
+
let modern_summary = regex(r"^Tidy found \d+ warnings? and \d+ errors?[!.]?$");
|
|
10
|
+
let files: Vec<_> = ctx
|
|
11
|
+
.argv
|
|
12
|
+
.iter()
|
|
13
|
+
.skip(1)
|
|
14
|
+
.filter(|arg| !arg.starts_with('-'))
|
|
15
|
+
.map(String::as_str)
|
|
16
|
+
.collect();
|
|
17
|
+
let mut file_index = 0;
|
|
18
|
+
let mut failures = Vec::new();
|
|
19
|
+
let mut warnings = 0_f64;
|
|
20
|
+
let mut errors = 0_f64;
|
|
21
|
+
let mut observed_warnings = 0_f64;
|
|
22
|
+
let mut observed_errors = 0_f64;
|
|
23
|
+
let mut has_summary = false;
|
|
24
|
+
for line in trim(&stderr).lines() {
|
|
25
|
+
if let Some(m) = issue.captures(line) {
|
|
26
|
+
let file = files.get(file_index).copied().unwrap_or("input");
|
|
27
|
+
if &m[2] == "Error" {
|
|
28
|
+
observed_errors += 1.0;
|
|
29
|
+
} else {
|
|
30
|
+
observed_warnings += 1.0;
|
|
31
|
+
}
|
|
32
|
+
failures.push(json!({"id":format!("{file}:{}:{}",&m[1],&m[3]),"file":file,
|
|
33
|
+
"line":number(&m[1]),"message":&m[3],"rule":m[2].to_lowercase()}));
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if let Some(m) = summary_pattern.captures(line) {
|
|
37
|
+
has_summary = true;
|
|
38
|
+
warnings = m[1].parse().unwrap_or(f64::INFINITY);
|
|
39
|
+
errors = m[2].parse().unwrap_or(f64::INFINITY);
|
|
40
|
+
file_index += 1;
|
|
41
|
+
} else if modern_summary.is_match(line) || line == "No warnings or errors were found." {
|
|
42
|
+
file_index += 1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Classic Tidy's error totals can carry over to later files. Count the
|
|
46
|
+
// diagnostic records in a multi-file run, not the last or summed totals.
|
|
47
|
+
// Preserve the single-file summary override and missing-summary fallback.
|
|
48
|
+
if files.len() > 1 || !has_summary {
|
|
49
|
+
warnings = observed_warnings;
|
|
50
|
+
errors = observed_errors;
|
|
51
|
+
}
|
|
52
|
+
let mut parts = Vec::new();
|
|
53
|
+
if errors > 0.0 {
|
|
54
|
+
parts.push(format!(
|
|
55
|
+
"{errors} error{}",
|
|
56
|
+
if errors == 1.0 { "" } else { "s" }
|
|
57
|
+
));
|
|
58
|
+
}
|
|
59
|
+
if warnings > 0.0 {
|
|
60
|
+
parts.push(format!(
|
|
61
|
+
"{warnings} warning{}",
|
|
62
|
+
if warnings == 1.0 { "" } else { "s" }
|
|
63
|
+
));
|
|
64
|
+
}
|
|
65
|
+
let summary = if parts.is_empty() {
|
|
66
|
+
"no issues found".into()
|
|
67
|
+
} else {
|
|
68
|
+
parts.join(", ")
|
|
69
|
+
};
|
|
70
|
+
Ok(result(
|
|
71
|
+
"tidy",
|
|
72
|
+
if errors > 0.0 { "fail" } else { "pass" },
|
|
73
|
+
summary,
|
|
74
|
+
failures,
|
|
75
|
+
ctx,
|
|
76
|
+
))
|
|
77
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
use super::compiler_helpers::{number, regex, relative_if_absolute, 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 raw = read_file(&ctx.stdout_path)?;
|
|
7
|
+
let pattern = regex(r"^(.+?)\((\d+),(\d+)\):\s+error\s+(TS\d+):\s+(.+)$");
|
|
8
|
+
let global_pattern = regex(r"^error\s+(TS\d+):\s+(.+)$");
|
|
9
|
+
let mut failures = Vec::new();
|
|
10
|
+
for line in trim(&raw).split('\n') {
|
|
11
|
+
// SR-002: split CRLF lines without leaving a CR in the diagnostic text.
|
|
12
|
+
let line = line.strip_suffix('\r').unwrap_or(line);
|
|
13
|
+
if let Some(m) = pattern.captures(line) {
|
|
14
|
+
let file = relative_if_absolute(&ctx.cwd, &m[1]);
|
|
15
|
+
failures.push(json!({"id":format!("{file}:{}:{}",&m[2],&m[4]),"file":file,
|
|
16
|
+
"line":number(&m[2]),"message":&m[5],"rule":&m[4]}));
|
|
17
|
+
} else if let Some(m) = global_pattern.captures(line) {
|
|
18
|
+
// SR-003: config/command errors have a TS code but no source location.
|
|
19
|
+
failures.push(json!({"id":&m[1],"message":&m[2],"rule":&m[1]}));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let summary = if failures.is_empty() {
|
|
23
|
+
"no type errors".to_owned()
|
|
24
|
+
} else {
|
|
25
|
+
format!("{} type errors", failures.len())
|
|
26
|
+
};
|
|
27
|
+
Ok(result("tsc", status(&failures), summary, failures, ctx))
|
|
28
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
use super::test_helpers::relative_if_absolute;
|
|
2
|
+
use crate::common::{read_file, result, Context};
|
|
3
|
+
use regex::Regex;
|
|
4
|
+
use serde_json::{json, Map, Value};
|
|
5
|
+
use std::collections::HashSet;
|
|
6
|
+
|
|
7
|
+
pub fn parse(ctx: &Context) -> Result<Value, String> {
|
|
8
|
+
let stderr = read_file(&ctx.stderr_path)?;
|
|
9
|
+
let stderr = stderr.trim();
|
|
10
|
+
if stderr.is_empty() {
|
|
11
|
+
return Ok(result("unittest", "pass", "no output", Vec::new(), ctx));
|
|
12
|
+
}
|
|
13
|
+
// Only the terminal runner footer owns totals/status, never traceback text.
|
|
14
|
+
let footer_re = Regex::new(
|
|
15
|
+
r"(?m)^Ran\s+([0-9]+)\s+tests? in [^\n]+\n\s*\n(OK|FAILED)(?: \(([^\n)]*)\))?\s*\z",
|
|
16
|
+
)
|
|
17
|
+
.unwrap();
|
|
18
|
+
let footer = footer_re.captures(stderr);
|
|
19
|
+
let skip_re = Regex::new(r"(?:^|,\s*)skipped=([0-9]+)(?:,|$)").unwrap();
|
|
20
|
+
let total = footer
|
|
21
|
+
.as_ref()
|
|
22
|
+
.map(|m| m[1].parse::<i64>().unwrap_or(0))
|
|
23
|
+
.unwrap_or(0);
|
|
24
|
+
let skipped = footer
|
|
25
|
+
.as_ref()
|
|
26
|
+
.and_then(|m| m.get(3))
|
|
27
|
+
.and_then(|counts| skip_re.captures(counts.as_str()))
|
|
28
|
+
.map(|m| m[1].parse::<i64>().unwrap_or(0))
|
|
29
|
+
.unwrap_or(0);
|
|
30
|
+
if footer.as_ref().is_some_and(|m| &m[2] == "OK") {
|
|
31
|
+
return Ok(result(
|
|
32
|
+
"unittest",
|
|
33
|
+
"pass",
|
|
34
|
+
format!("{} passed", (total - skipped).max(0)),
|
|
35
|
+
Vec::new(),
|
|
36
|
+
ctx,
|
|
37
|
+
));
|
|
38
|
+
}
|
|
39
|
+
let split_re = Regex::new(r"={50,}").unwrap();
|
|
40
|
+
let header_re = Regex::new(r"(ERROR|FAIL):\s+(\S+)\s+\(([^)]+)\)").unwrap();
|
|
41
|
+
let file_re = Regex::new(r#"File\s+"([^"]+)",\s+line\s+([0-9]+)"#).unwrap();
|
|
42
|
+
let dashed_re = Regex::new(r"^-{10,}").unwrap();
|
|
43
|
+
let ran_line_re = Regex::new(r"^Ran\s+[0-9]+\s+test").unwrap();
|
|
44
|
+
let assertion_re = Regex::new(r"AssertionError:\s*(.+)").unwrap();
|
|
45
|
+
let mut failures = Vec::new();
|
|
46
|
+
let mut failed_methods = HashSet::new();
|
|
47
|
+
let trace_output = footer
|
|
48
|
+
.as_ref()
|
|
49
|
+
.map(|m| &stderr[..m.get(0).unwrap().start()])
|
|
50
|
+
.unwrap_or(stderr);
|
|
51
|
+
for block in split_re.split(trace_output) {
|
|
52
|
+
let Some(header) = header_re.captures(block) else {
|
|
53
|
+
continue;
|
|
54
|
+
};
|
|
55
|
+
failed_methods.insert((header[2].to_owned(), header[3].to_owned()));
|
|
56
|
+
let lines: Vec<_> = block.split('\n').collect();
|
|
57
|
+
let mut location = None;
|
|
58
|
+
for line in &lines {
|
|
59
|
+
if let Some(m) = file_re.captures(line) {
|
|
60
|
+
location = Some((m[1].to_owned(), m[2].parse::<u64>().unwrap_or(0)));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let mut past_header = false;
|
|
64
|
+
let mut trace = Vec::new();
|
|
65
|
+
for line in &lines {
|
|
66
|
+
let line = line.trim();
|
|
67
|
+
if !past_header {
|
|
68
|
+
if dashed_re.is_match(line) {
|
|
69
|
+
past_header = true;
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if dashed_re.is_match(line)
|
|
74
|
+
|| ran_line_re.is_match(line)
|
|
75
|
+
|| line.starts_with("FAILED")
|
|
76
|
+
|| line.starts_with("OK")
|
|
77
|
+
{
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
if !line.is_empty() {
|
|
81
|
+
trace.push(line);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let error_line = trace.last().copied().unwrap_or("test failed");
|
|
85
|
+
let message = assertion_re
|
|
86
|
+
.captures(error_line)
|
|
87
|
+
.map(|m| m[1].to_owned())
|
|
88
|
+
.unwrap_or_else(|| error_line.to_owned());
|
|
89
|
+
let mut failure = Map::new();
|
|
90
|
+
failure.insert("id".to_owned(), json!(&header[2]));
|
|
91
|
+
if let Some((file, line)) = location {
|
|
92
|
+
if !file.is_empty() {
|
|
93
|
+
failure.insert(
|
|
94
|
+
"file".to_owned(),
|
|
95
|
+
json!(relative_if_absolute(&ctx.cwd, &file)),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
failure.insert("line".to_owned(), json!(line));
|
|
99
|
+
}
|
|
100
|
+
failure.insert("message".to_owned(), json!(message));
|
|
101
|
+
failure.insert(
|
|
102
|
+
"rule".to_owned(),
|
|
103
|
+
json!(if &header[1] == "ERROR" {
|
|
104
|
+
"error"
|
|
105
|
+
} else {
|
|
106
|
+
"assertion"
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
failures.push(Value::Object(failure));
|
|
110
|
+
}
|
|
111
|
+
let failed = failed_methods.len() as i64;
|
|
112
|
+
let passed = (total - failed - skipped).max(0);
|
|
113
|
+
let is_failure = failed > 0 || footer.as_ref().is_some_and(|m| &m[2] == "FAILED");
|
|
114
|
+
Ok(result(
|
|
115
|
+
"unittest",
|
|
116
|
+
if is_failure { "fail" } else { "pass" },
|
|
117
|
+
if is_failure {
|
|
118
|
+
format!("{failed} failed, {passed} passed")
|
|
119
|
+
} else {
|
|
120
|
+
format!("{passed} passed")
|
|
121
|
+
},
|
|
122
|
+
failures,
|
|
123
|
+
ctx,
|
|
124
|
+
))
|
|
125
|
+
}
|