@turingcode/cli 0.2.3 → 0.2.4
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/dist/features/table/check.js +11 -7
- package/package.json +1 -1
|
@@ -49,17 +49,21 @@ function valueOf(v, col, missing) {
|
|
|
49
49
|
return v === "true";
|
|
50
50
|
return v;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Rows of a table keyed by its header; the label is the primary key, or `#n`. A row with the wrong
|
|
54
|
+
* number of cells is kept (it still counts, and its values can be referenced), with cells by position.
|
|
55
|
+
*/
|
|
53
56
|
function rowsOf(t, table, name, missing) {
|
|
54
57
|
const parsed = t.tables.get(name);
|
|
55
58
|
const key = table ? keyColumns(table) : [];
|
|
56
59
|
const columns = new Map((table?.columns ?? []).map(c => [c.name, c]));
|
|
57
|
-
return parsed.rows.
|
|
58
|
-
const cells = Object.fromEntries(parsed.header.
|
|
60
|
+
return parsed.rows.map((r, k) => {
|
|
61
|
+
const cells = Object.fromEntries(parsed.header.flatMap((h, i) => (r[i] === undefined ? [] : [[h, r[i]]])));
|
|
59
62
|
const names = new Set([...parsed.header, ...columns.keys()]);
|
|
60
63
|
const doc = Object.fromEntries([...names].map(n => [n, valueOf(cells[n], columns.get(n), missing)]));
|
|
61
64
|
const keyValues = key.map(c => cells[c] ?? "");
|
|
62
|
-
|
|
65
|
+
const label = key.length && keyValues.every(v => !missing(v)) ? keyValues.join("/") : `#${k + 1}`;
|
|
66
|
+
return { label, cells, doc, shapeError: r.length !== parsed.header.length };
|
|
63
67
|
});
|
|
64
68
|
}
|
|
65
69
|
/**
|
|
@@ -205,7 +209,7 @@ export function tableCheck(input) {
|
|
|
205
209
|
continue;
|
|
206
210
|
const hooks = hooksFor(t, true);
|
|
207
211
|
for (const col of t.columns.filter(c => c.match)) {
|
|
208
|
-
runParts({ [col.name]: col.match }, tableRows, hooks, r => r.doc[col.name] === null || !!badCells.get(r)?.has(col.name), (f, r) => diags.push(diag(f.code, f.message, { table: t.name, row: r.label, column: f.column }, f.found, f.expected)));
|
|
212
|
+
runParts({ [col.name]: col.match }, tableRows, hooks, r => r.shapeError || r.doc[col.name] === null || !!badCells.get(r)?.has(col.name), (f, r) => diags.push(diag(f.code, f.message, { table: t.name, row: r.label, column: f.column }, f.found, f.expected)));
|
|
209
213
|
}
|
|
210
214
|
(t.rules ?? []).forEach((rule, i) => checkRule(rule, `${t.name}.rules[${i}]`, t));
|
|
211
215
|
}
|
|
@@ -236,7 +240,7 @@ export function tableCheck(input) {
|
|
|
236
240
|
}
|
|
237
241
|
return;
|
|
238
242
|
}
|
|
239
|
-
runParts(rule.require, matching, hooks,
|
|
243
|
+
runParts(rule.require, matching, hooks, r => r.shapeError, (f, r) => diags.push(diag(f.code, f.message, { ...where, row: r.label, column: f.column }, f.found, rule.description ?? f.expected, severity)));
|
|
240
244
|
}
|
|
241
245
|
}
|
|
242
246
|
/**
|
|
@@ -299,7 +303,7 @@ function checkStructure(c, doc, missing, out) {
|
|
|
299
303
|
const tableRows = rowsOf(doc, t, t.name, missing);
|
|
300
304
|
const key = keyColumns(t);
|
|
301
305
|
const seenKeys = new Set();
|
|
302
|
-
for (const r of tableRows) {
|
|
306
|
+
for (const r of tableRows.filter(row => !row.shapeError)) {
|
|
303
307
|
const at = (column) => ({ table: t.name, row: r.label, column });
|
|
304
308
|
for (const col of t.columns.filter(col => header.includes(col.name))) {
|
|
305
309
|
const v = r.cells[col.name];
|
package/package.json
CHANGED