Files
marqdo-lint/docs/RULES.md
T
cflmy 457cbbd807 feat: add document-structure rules and release contract
Implement the lint-owned part of the AI-readable documentation architecture
(marqdo-lint#13 / marqdo#55 §13) without adding document language or a second
parser. All rules read one public `check --emit` Analysis 3 projection.

New rules (25 total):
- MQD-ENTRY-001 (info): a manifest-backed or multi-module project entry is not
  `index.mq.md`; standalone single-file documents are never warned.
- MQD-STRUCT-001 (info): the same canonical heading name appears under several
  parents (valid, but bare anchors get numbered suffixes); points at
  units[].name/path/heading_span.
- MQD-REL-001 (info): a link resolves to a loaded module that the document did
  not import; states that links are static references, not imports/execution.

Also records the release/platform contract for marqdo-lint#9/#14: Linux x86_64
is the only supported platform (real v0.2.0 assets + local gates); macOS/Windows
stay UNVERIFIED/unsupported. Release assets and same-SHA CI requirements are
frozen in docs/RELEASE.md; publication remains a maintainer action (this repo's
CI only notifies the root reconcile). PROTOCOL_BASELINE now records the rc.6
candidate while keeping the rc.4+ accepted protocol floor for the still-rc.5 CI
image (tracked by #11).

No cross-repo dependency, no parser copy, no document syntax change.
2026-11-30 11:52:34 +08:00

4.4 KiB

规则与可复现样例

运行 marqdo-lint explain RULE_ID 可查看稳定 ID、损失、依据和建议。除安全 守卫外,表中条目均为人工修复。所有样例都可用当前冻结核心静态检查,路径相 对于仓库根目录。

规则 默认级别 报告示例 对照示例和验证
MQD-DOC-001 warning 直接返回且缺少入口说明 在首个载体前说明目标。运行 doc_001_and_doc_002_check_explanation_existence_and_position
MQD-DOC-002 info 返回附近没有结果或限制说明 在返回处说明单位或失败结果。同上
MQD-DOC-003 warning 复杂函数的叙述占比低于阈值 自然叙述达到门槛,短小平凡函数仅提示。运行 long_functions_use_warning_ratio_and_h3_reading_sections
MQD-DOC-004 info 长函数无小节 在完整控制块之间按业务阶段分段。同上
MQD-BRANCH-001 warning 同项包含 if/else 推荐分支
MQD-BRANCH-002 warning 不使用列表 或列表先写说明再写 if 让每个 if、else if 和 else 成为各自有序项的首个载体
MQD-BRANCH-003 warning 条件臂分属不同列表或中间有其他项 使用同一有序列表中的相邻兄弟项
MQD-BRANCH-004 info 非空分支的列表项中缺少解释 推荐分支 在臂内写原因
MQD-LOOP-001 warning 编号项承载 while 嵌套示例 的循环使用无序项
MQD-LOOP-002 info 循环项缺少叙述 嵌套示例 说明处理对象和终止条件
MQD-LOOP-003 warning 分支体或跳转脱离所属项,或子循环嵌套到错误的臂 依据真实列表子树缩进
MQD-CTRL-001 warning 循环 end 在项外,或分支 end 仍在分支项内 整个分支组只检查一个 end,放在列表后;循环 end 放在项末尾
MQD-PROSE-001 warning 句中的粗体、斜体或反引号成为执行载体 普通文字留在 Exec,富文本可进入 Knowledge
MQD-PROSE-002 info 已绑定的 I/O 调用或索引写入缺少相邻叙述 说明权限、后果或失败处理
MQD-PARAM-001 info 显式签名附近没有自然文字 说明单位、范围和用途
MQD-STYLE-001 info 用行内代码承载 return,或用斜体承载 else if 和循环跳转 推荐分支 用斜体表示返回,粗体表示赋值;读数扫描 用行内代码表示控制头、break 和 continue
MQD-ENTRY-001 info 项目级入口不是 index.mq.md(仅 manifest 或多模块项目) 为项目保留根 index.mq.md 导航入口。
MQD-STRUCT-001 info 同名标题出现在多个作用域(裸锚点会编号) 使用唯一标题名或完整 unit path。
MQD-REL-001 info 链接指向未被 import 的模块(静态引用≠执行) 需要执行目标时显式 import。
MQD-KNOW-001 warning 在两个执行段之间切出一段纯文字,或出现跨段控制 普通说明留在 Exec,同段关闭控制;公式和富文本可留在 Knowledge
MQD-LINK-001 error references[].state 为 missing、ambiguous、invalid 或 outside_scope 修正引用地址或目标;歧义时打印全部候选,不任选第一个
MQD-LINK-002 info references[].state 为 not_loaded 这是“未核验”,不是断链;需要时显式使用 --refs
MQD-LINK-003 info references[].state 为 external 外部 URI 不联网核验,仅供人工评审
MQD-CALL-001 info calls[].state 为 unresolved 动态/未绑定调用是诚实的未解析,不是错误
MQD-SAFETY-001 error AST、执行载荷或 Analysis 不等价,或无法取得可靠验证输入 放弃写回

自动检测可以判断结构、覆盖和位置。对叙述内容的业务正确性仍须由作者和评审 者判断。副作用识别只使用公开 Analysis 中已绑定的资源、外部执行、标准库 I/O、插件调用和索引写入;未知绑定和普通本地函数不被猜测为副作用。

渲染对照位于 examples/rendered。使用 cargo run --locked --example render_fixtures 按 marqdo.md.v1 重新生成。