#!/usr/bin/env python3 """Lint TSL codegen function-doc markdown against the house standard. The standard lives in tools/tsl-codegen/STANDARD.md. Each `## `sig`` / `### `sig`` heading starts one function entry. Rules split into hard errors (CI-blocking) and soft warnings (style convergence over the ~12k existing entries). Hard errors: - missing/empty description (first prose line after the signature) - missing `返回:类型` - signature has parameters but the entry has no parameter table - signature has no parameters but a parameter table is present - parameter table header is not the fixed 参数 / 类型 / 说明 三列 Soft warnings: - optional-parameter wording not starting with `可选。` - malformed / empty `` line Exit status: 1 if any error (or, with --strict, any warning); else 0. Usage: python lint.py --file path/to/page.md python lint.py --dir path/to/codegen-dir python lint.py --dir path/to/codegen-dir --strict """ import argparse import re import sys from pathlib import Path # Entry heading: `## `sig`` or `### `sig``. Matches the index generator's rule # so the linter and the tsv agree on what a function entry is. ENTRY_RE = re.compile(r"^(#{2,3})(?!#)\s+`(.+?)`\s*$") RETURN_RE = re.compile(r"^返回[::]") TAGS_RE = re.compile(r"^\s*$") FENCE_RE = re.compile(r"^(```|~~~)") OPTIONAL_HINT_RE = re.compile(r"可选|可省略|省略") # Split a table row on unescaped pipes so `nil\|array` stays one cell. CELL_SPLIT_RE = re.compile(r"(?