dsh-tablelint 0.1.2 → 0.2.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/README.md +10 -0
- package/package.json +1 -1
- package/src/index.js +10 -1
package/README.md
CHANGED
|
@@ -37,4 +37,14 @@ Exit codes: `0` clean, `1` findings, `2` usage or read error. In DSH the same fu
|
|
|
37
37
|
|
|
38
38
|
Part of [dsh-verify-kit](https://github.com/zjukop3/dsh-verify-kit): five small deterministic checks, each one verb, each runnable without DSH.
|
|
39
39
|
|
|
40
|
+
## What it decides
|
|
41
|
+
|
|
42
|
+
Markdown 表格的形状是否完整:错位行、分隔行与表头列数不符、重复表头、空表。每条发现带行号。
|
|
43
|
+
|
|
44
|
+
## Honest scope
|
|
45
|
+
|
|
46
|
+
这是表格形状检查,不是数值核对:它证明**表格渲染不会塌**,不能证明表里的数与正文一致——那是 numberlint 的邻居。
|
|
47
|
+
|
|
48
|
+
Part of [dsh-verify-kit](https://github.com/zjukop3/dsh-verify-kit): generic deliverable defects, each one verb, each runnable without DSH.
|
|
49
|
+
|
|
40
50
|
MIT.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-tablelint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Markdown table check for generated reports: rows with the wrong cell count, a delimiter row that disagrees with the header, duplicate or empty headers, and tables with no rows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -81,7 +81,16 @@ export function lintTables(text) {
|
|
|
81
81
|
for (const duplicate of new Set(duplicates)) {
|
|
82
82
|
findings.push({ level: 'warn', rule: 'duplicate-header', message: `line ${table.line}: two columns are both named "${duplicate}"` })
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
// A blank FIRST header cell is a deliberate pattern, not a defect: either the
|
|
85
|
+
// table is a two-column layout card (`| | |` with an empty header row) or the
|
|
86
|
+
// first column holds bold row labels. Two real third-party READMEs tripped
|
|
87
|
+
// this, both on purpose. A blank header anywhere else still names nothing.
|
|
88
|
+
const emptyAt = table.header.map((cell, index) => (cell === '' ? index : -1)).filter(index => index >= 0)
|
|
89
|
+
// Two shapes are deliberate: every header cell blank (`| | |` — a layout card),
|
|
90
|
+
// and only the first blank (bold row labels). Everything else names nothing.
|
|
91
|
+
const allBlank = emptyAt.length === table.header.length
|
|
92
|
+
const blankFirstOnly = emptyAt.length > 0 && emptyAt.every(index => index === 0)
|
|
93
|
+
if (emptyAt.length > 0 && !allBlank && !blankFirstOnly) {
|
|
85
94
|
findings.push({ level: 'warn', rule: 'empty-header', message: `line ${table.line}: a column has no header` })
|
|
86
95
|
}
|
|
87
96
|
for (const row of table.rows) {
|