TBL-005 列间约束
验证当某列满足 when 的条件时,另一列也满足 then 的约束。这是按行评估的条件型规则。违例以 error 报告。
像「Status 为 stable 时 Approver 列必须非空」、「Type 为 external 时 URL 列必须以 https:// 开头」这样的行内条件型一致性,仅靠允许值或正则表达式无法表达。本规则用于表示这类列与列之间的关系。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
when | object | ✓ | 条件(详见下表) |
then | object | ✓ | 约束(详见下表) |
section | string | — | 将验证范围限定为指定章节下的表格 |
files | string | — | 应用此规则的文件 glob |
when(条件)
Section titled “when(条件)”| 字段 | 类型 | 说明 |
|---|---|---|
column | string | 判定条件的列 |
equals | string | 值与该字符串相等时 |
oneOf | string[] | 值包含在该数组中时 |
matches | string | 值匹配正则表达式时 |
equals / oneOf / matches 三选一指定。
then(约束)
Section titled “then(约束)”| 字段 | 类型 | 说明 |
|---|---|---|
column | string | 施加约束的列 |
notEmpty | boolean | 值非空 |
equals | string | 值相等 |
oneOf | string[] | 值在其中 |
matches | string | 值匹配 |
notEmpty / equals / oneOf / matches 四选一。
| ID | Status | Approver || ------ | ------ | -------- || REQ-01 | stable | alice || REQ-02 | stable | |设置 when: { column: "Status", equals: "stable" }、then: { column: "Approver", notEmpty: true } 时,stable 但 Approver 为空的行会判定为违例。
docs/requirements.md line 4 error Row where Status="stable": column "Approver" must not be empty TBL-005| ID | Status | Approver || ------ | ------ | -------- || REQ-01 | stable | alice || REQ-02 | stable | bob |{ "rule": "tbl005", "options": { "when": { "column": "Status", "equals": "stable" }, "then": { "column": "Approver", "notEmpty": true } }}- TBL-003 允许值 — 单列值的约束
- TBL-004 单元格模式 — 单列模式的约束