跳转到内容

TBL-005 列间约束

验证当某列满足 when 的条件时,另一列也满足 then 的约束。这是按行评估的条件型规则。违例以 error 报告。

像「StatusstableApprover 列必须非空」、「TypeexternalURL 列必须以 https:// 开头」这样的行内条件型一致性,仅靠允许值或正则表达式无法表达。本规则用于表示这类列与列之间的关系。

字段类型必填说明
whenobject条件(详见下表)
thenobject约束(详见下表)
sectionstring将验证范围限定为指定章节下的表格
filesstring应用此规则的文件 glob
字段类型说明
columnstring判定条件的列
equalsstring值与该字符串相等时
oneOfstring[]值包含在该数组中时
matchesstring值匹配正则表达式时

equals / oneOf / matches 三选一指定。

字段类型说明
columnstring施加约束的列
notEmptyboolean值非空
equalsstring值相等
oneOfstring[]值在其中
matchesstring值匹配

notEmpty / equals / oneOf / matches 四选一。

| ID | Status | Approver |
| ------ | ------ | -------- |
| REQ-01 | stable | alice |
| REQ-02 | stable | |

设置 when: { column: "Status", equals: "stable" }then: { column: "Approver", notEmpty: true } 时,stableApprover 为空的行会判定为违例。

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 }
}
}