@robhowley/pi-structured-return 1.10.1 → 2.0.0
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 +33 -83
- package/extensions/structured-return/config/registry.ts +4 -30
- package/extensions/structured-return/index.ts +105 -76
- 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 +20 -6
- 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,287 @@
|
|
|
1
|
+
use crate::common::{read_file, trim, Context};
|
|
2
|
+
use serde_json::{json, Map, Value};
|
|
3
|
+
use std::borrow::Cow;
|
|
4
|
+
|
|
5
|
+
// JSON permits lone UTF-16 surrogates, but Rust strings cannot contain them.
|
|
6
|
+
// Replace only those code units with U+FFFD, without expanding the input or
|
|
7
|
+
// changing valid pairs, literal backslashes, or the original report on disk.
|
|
8
|
+
pub fn json_source(source: &str) -> Cow<'_, str> {
|
|
9
|
+
fn code_unit(bytes: &[u8], offset: usize) -> Option<u16> {
|
|
10
|
+
let escape = bytes.get(offset..offset + 6)?;
|
|
11
|
+
if !escape.starts_with(b"\\u") {
|
|
12
|
+
return None;
|
|
13
|
+
}
|
|
14
|
+
u16::from_str_radix(std::str::from_utf8(&escape[2..]).ok()?, 16).ok()
|
|
15
|
+
}
|
|
16
|
+
let bytes = source.as_bytes();
|
|
17
|
+
let mut normalized = None;
|
|
18
|
+
let mut i = 0;
|
|
19
|
+
while i < bytes.len() {
|
|
20
|
+
if bytes[i] != b'\\' {
|
|
21
|
+
i += 1;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if let Some(unit) = code_unit(bytes, i) {
|
|
25
|
+
if (0xD800..=0xDBFF).contains(&unit)
|
|
26
|
+
&& code_unit(bytes, i + 6).is_some_and(|low| (0xDC00..=0xDFFF).contains(&low))
|
|
27
|
+
{
|
|
28
|
+
i += 12;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (0xD800..=0xDFFF).contains(&unit) {
|
|
32
|
+
let output = normalized.get_or_insert_with(|| bytes.to_vec());
|
|
33
|
+
output[i + 2..i + 6].copy_from_slice(b"fffd");
|
|
34
|
+
}
|
|
35
|
+
i += 6;
|
|
36
|
+
} else {
|
|
37
|
+
// Skip an escaped backslash, quote, or other escape together.
|
|
38
|
+
i += 2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
match normalized {
|
|
42
|
+
Some(bytes) => Cow::Owned(String::from_utf8(bytes).unwrap()),
|
|
43
|
+
None => Cow::Borrowed(source),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn parse_json(source: &str) -> Result<Value, serde_json::Error> {
|
|
48
|
+
serde_json::from_str(&json_source(source))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
pub fn read_json(path: &str, empty: Value) -> Result<Value, String> {
|
|
52
|
+
let source = read_file(path)?;
|
|
53
|
+
if trim(&source).is_empty() {
|
|
54
|
+
return Ok(empty);
|
|
55
|
+
}
|
|
56
|
+
parse_json(trim(&source)).map_err(|e| format!("Invalid JSON: {e}"))
|
|
57
|
+
}
|
|
58
|
+
pub fn array(value: &Value) -> &[Value] {
|
|
59
|
+
value.as_array().map(Vec::as_slice).unwrap_or(&[])
|
|
60
|
+
}
|
|
61
|
+
pub fn required_array<'a>(value: Option<&'a Value>, label: &str) -> Result<&'a [Value], String> {
|
|
62
|
+
value
|
|
63
|
+
.and_then(Value::as_array)
|
|
64
|
+
.map(Vec::as_slice)
|
|
65
|
+
.ok_or_else(|| format!("{label} is not an array"))
|
|
66
|
+
}
|
|
67
|
+
pub fn required_string<'a>(value: Option<&'a Value>, label: &str) -> Result<&'a str, String> {
|
|
68
|
+
value
|
|
69
|
+
.and_then(Value::as_str)
|
|
70
|
+
.ok_or_else(|| format!("{label} is not a string"))
|
|
71
|
+
}
|
|
72
|
+
pub fn js_string(value: Option<&Value>) -> String {
|
|
73
|
+
match value {
|
|
74
|
+
None => "undefined".into(),
|
|
75
|
+
Some(Value::Null) => "null".into(),
|
|
76
|
+
Some(Value::String(s)) => s.clone(),
|
|
77
|
+
Some(Value::Number(n)) => num_string(n.as_f64().unwrap_or(f64::NAN)),
|
|
78
|
+
Some(Value::Array(a)) => a
|
|
79
|
+
.iter()
|
|
80
|
+
.map(|v| {
|
|
81
|
+
if v.is_null() {
|
|
82
|
+
String::new()
|
|
83
|
+
} else {
|
|
84
|
+
js_string(Some(v))
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
.collect::<Vec<_>>()
|
|
88
|
+
.join(","),
|
|
89
|
+
Some(Value::Object(_)) => "[object Object]".into(),
|
|
90
|
+
Some(v) => v.to_string(),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
pub fn number_text(text: &str) -> f64 {
|
|
94
|
+
let text = text.trim();
|
|
95
|
+
if text.is_empty() {
|
|
96
|
+
return 0.0;
|
|
97
|
+
}
|
|
98
|
+
if text == "Infinity" || text == "+Infinity" {
|
|
99
|
+
return f64::INFINITY;
|
|
100
|
+
}
|
|
101
|
+
if text == "-Infinity" {
|
|
102
|
+
return f64::NEG_INFINITY;
|
|
103
|
+
}
|
|
104
|
+
for (prefix, radix) in [
|
|
105
|
+
("0x", 16),
|
|
106
|
+
("0X", 16),
|
|
107
|
+
("0b", 2),
|
|
108
|
+
("0B", 2),
|
|
109
|
+
("0o", 8),
|
|
110
|
+
("0O", 8),
|
|
111
|
+
] {
|
|
112
|
+
if let Some(rest) = text.strip_prefix(prefix) {
|
|
113
|
+
return u64::from_str_radix(rest, radix)
|
|
114
|
+
.map(|n| n as f64)
|
|
115
|
+
.unwrap_or(f64::NAN);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if text.contains("inf") || text.contains("NaN") {
|
|
119
|
+
return f64::NAN;
|
|
120
|
+
}
|
|
121
|
+
text.parse().unwrap_or(f64::NAN)
|
|
122
|
+
}
|
|
123
|
+
pub fn number(value: Option<&Value>) -> f64 {
|
|
124
|
+
match value {
|
|
125
|
+
None => f64::NAN,
|
|
126
|
+
Some(Value::Null) => 0.0,
|
|
127
|
+
Some(Value::Bool(v)) => {
|
|
128
|
+
if *v {
|
|
129
|
+
1.0
|
|
130
|
+
} else {
|
|
131
|
+
0.0
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
Some(Value::Number(v)) => v.as_f64().unwrap_or(f64::NAN),
|
|
135
|
+
Some(v) => number_text(&js_string(Some(v))),
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
pub fn num_string(n: f64) -> String {
|
|
139
|
+
if n.is_nan() {
|
|
140
|
+
"NaN".into()
|
|
141
|
+
} else if n == f64::INFINITY {
|
|
142
|
+
"Infinity".into()
|
|
143
|
+
} else if n == f64::NEG_INFINITY {
|
|
144
|
+
"-Infinity".into()
|
|
145
|
+
} else if n == 0.0 {
|
|
146
|
+
"0".into()
|
|
147
|
+
} else if n.fract() == 0.0 {
|
|
148
|
+
format!("{n:.0}")
|
|
149
|
+
} else {
|
|
150
|
+
n.to_string()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
pub fn num_value(n: f64) -> Value {
|
|
154
|
+
serde_json::Number::from_f64(n)
|
|
155
|
+
.map(Value::Number)
|
|
156
|
+
.unwrap_or(Value::Null)
|
|
157
|
+
}
|
|
158
|
+
pub fn copy_field(out: &mut Map<String, Value>, name: &str, value: Option<&Value>) {
|
|
159
|
+
if let Some(v) = value {
|
|
160
|
+
out.insert(name.into(), v.clone());
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
pub fn optional_string(out: &mut Map<String, Value>, name: &str, value: Option<String>) {
|
|
164
|
+
if let Some(v) = value {
|
|
165
|
+
out.insert(name.into(), Value::String(v));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
pub fn no_output(tool: &str, ctx: &Context) -> Value {
|
|
169
|
+
json!({"tool":tool,"status":"error","summary":"no output","logPath":ctx.log_path})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
pub fn parse_error(tool: &str, ctx: &Context) -> Value {
|
|
173
|
+
json!({"tool":tool,"status":"error","summary":format!("failed to parse {tool} JSON output"),"logPath":ctx.log_path})
|
|
174
|
+
}
|
|
175
|
+
pub fn lint_result(tool: &str, failures: Vec<Value>, ctx: &Context) -> Value {
|
|
176
|
+
let failed = !failures.is_empty();
|
|
177
|
+
let summary = if failed {
|
|
178
|
+
format!("{} lint errors", failures.len())
|
|
179
|
+
} else {
|
|
180
|
+
"no lint errors".into()
|
|
181
|
+
};
|
|
182
|
+
crate::common::result(
|
|
183
|
+
tool,
|
|
184
|
+
if failed { "fail" } else { "pass" },
|
|
185
|
+
summary,
|
|
186
|
+
failures,
|
|
187
|
+
ctx,
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
/// Report paths are emitted relative to the command's working directory.
|
|
191
|
+
pub fn relative_input(cwd: &str, file: &str) -> String {
|
|
192
|
+
crate::common::relative(cwd, file)
|
|
193
|
+
}
|
|
194
|
+
pub fn relative_absolute(cwd: &str, file: &str) -> String {
|
|
195
|
+
if std::path::Path::new(file).is_absolute() {
|
|
196
|
+
crate::common::relative(cwd, file)
|
|
197
|
+
} else {
|
|
198
|
+
file.to_owned()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
pub fn null_object(value: &Value, label: &str) -> Result<(), String> {
|
|
202
|
+
if value.is_null() {
|
|
203
|
+
Err(format!("Cannot read properties of null ({label})"))
|
|
204
|
+
} else {
|
|
205
|
+
Ok(())
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
pub fn is_one(value: Option<&Value>) -> bool {
|
|
209
|
+
value.and_then(Value::as_f64) == Some(1.0)
|
|
210
|
+
}
|
|
211
|
+
pub fn add_one(value: Option<&Value>) -> Value {
|
|
212
|
+
match value {
|
|
213
|
+
Some(Value::String(s)) => json!(format!("{s}1")),
|
|
214
|
+
_ => num_value(number(value) + 1.0),
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
pub fn entries(value: &Value) -> Result<Vec<(String, &Value)>, String> {
|
|
218
|
+
match value {
|
|
219
|
+
Value::Object(map) => {
|
|
220
|
+
let mut integer = Vec::new();
|
|
221
|
+
let mut other = Vec::new();
|
|
222
|
+
for (key, value) in map {
|
|
223
|
+
if let Ok(n) = key.parse::<u32>() {
|
|
224
|
+
if n != u32::MAX && n.to_string() == *key {
|
|
225
|
+
integer.push((n, key.clone(), value));
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
other.push((key.clone(), value));
|
|
230
|
+
}
|
|
231
|
+
integer.sort_by_key(|(n, _, _)| *n);
|
|
232
|
+
let mut out: Vec<_> = integer.into_iter().map(|(_, k, v)| (k, v)).collect();
|
|
233
|
+
out.extend(other);
|
|
234
|
+
Ok(out)
|
|
235
|
+
}
|
|
236
|
+
Value::Array(values) => Ok(values
|
|
237
|
+
.iter()
|
|
238
|
+
.enumerate()
|
|
239
|
+
.map(|(i, v)| (i.to_string(), v))
|
|
240
|
+
.collect()),
|
|
241
|
+
Value::Null => Err("Cannot convert null to object".into()),
|
|
242
|
+
Value::String(_) => Err("String entries are not supported by this report schema".into()),
|
|
243
|
+
_ => Ok(Vec::new()),
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
#[cfg(test)]
|
|
248
|
+
mod tests {
|
|
249
|
+
use super::*;
|
|
250
|
+
|
|
251
|
+
#[test]
|
|
252
|
+
fn replaces_only_unpaired_surrogates() {
|
|
253
|
+
for (source, expected) in [
|
|
254
|
+
(r#""\ud800""#, "�"),
|
|
255
|
+
(r#""\uDFFF""#, "�"),
|
|
256
|
+
(r#""\ud800\ud801\udc00""#, "�𐐀"),
|
|
257
|
+
(r#""\udc00\ud800""#, "��"),
|
|
258
|
+
(r#""\ud83d\ude00""#, "😀"),
|
|
259
|
+
(r#""\\ud800""#, r"\ud800"),
|
|
260
|
+
(r#""\\\ud800""#, "\\�"),
|
|
261
|
+
(r#""\"\ud800""#, "\"�"),
|
|
262
|
+
(r#""café \u0061""#, "café a"),
|
|
263
|
+
] {
|
|
264
|
+
assert_eq!(parse_json(source).unwrap(), json!(expected), "{source}");
|
|
265
|
+
assert_eq!(json_source(source).len(), source.len());
|
|
266
|
+
}
|
|
267
|
+
assert!(matches!(json_source(r#""ordinary""#), Cow::Borrowed(_)));
|
|
268
|
+
assert_eq!(parse_json(r#"{"\ud800":"kept"}"#).unwrap()["�"], "kept");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#[test]
|
|
272
|
+
fn preserves_invalid_json_and_depth_rejection() {
|
|
273
|
+
for source in [
|
|
274
|
+
r#""\ud80""#,
|
|
275
|
+
r#""\ud80x""#,
|
|
276
|
+
r#""\x\ud800""#,
|
|
277
|
+
r#"["\ud800",]"#,
|
|
278
|
+
] {
|
|
279
|
+
assert!(parse_json(source).is_err(), "{source}");
|
|
280
|
+
}
|
|
281
|
+
let deep = format!("{}null{}", "[".repeat(140), "]".repeat(140));
|
|
282
|
+
assert!(parse_json(&deep)
|
|
283
|
+
.unwrap_err()
|
|
284
|
+
.to_string()
|
|
285
|
+
.contains("recursion limit"));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
use super::compiler_helpers::{number, 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 header = regex(r"^Error: Parse error on line (\d+):$");
|
|
8
|
+
let expecting = regex(r"^(Expecting .+)$");
|
|
9
|
+
let file = ctx
|
|
10
|
+
.argv
|
|
11
|
+
.iter()
|
|
12
|
+
.filter(|arg| !arg.starts_with('-') && *arg != "jsonlint" && *arg != "npx")
|
|
13
|
+
.last()
|
|
14
|
+
.map(String::as_str)
|
|
15
|
+
.unwrap_or("input");
|
|
16
|
+
let mut line_number = None;
|
|
17
|
+
let mut message = String::new();
|
|
18
|
+
for line in trim(&combined).lines() {
|
|
19
|
+
if let Some(m) = header.captures(line) {
|
|
20
|
+
line_number = Some(number(&m[1]));
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if let Some(m) = expecting.captures(line) {
|
|
24
|
+
message = m[1].to_owned();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let mut failures = Vec::new();
|
|
28
|
+
if let Some(line) = line_number {
|
|
29
|
+
// The source id interpolates the parsed Number, not the original digits.
|
|
30
|
+
let line_text = line
|
|
31
|
+
.as_f64()
|
|
32
|
+
.map(|line| line.to_string())
|
|
33
|
+
.unwrap_or_else(|| "Infinity".into());
|
|
34
|
+
failures.push(
|
|
35
|
+
json!({"id":format!("{file}:{line_text}"),"file":file,"line":line,
|
|
36
|
+
"message":if message.is_empty() {"parse error"} else {&message}}),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
Ok(result(
|
|
40
|
+
"jsonlint",
|
|
41
|
+
status(&failures),
|
|
42
|
+
if failures.is_empty() {
|
|
43
|
+
"valid JSON"
|
|
44
|
+
} else {
|
|
45
|
+
"parse error"
|
|
46
|
+
},
|
|
47
|
+
failures,
|
|
48
|
+
ctx,
|
|
49
|
+
))
|
|
50
|
+
}
|