Repository navigation
ci: add Markdown docstring check #1393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Aaron ("AJ") Steers (aaronsteers)
merged 1 commit into
release-candidate/v1
from
devin/1792118241-docstring-markdown-check
Oct 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/usr/bin/env -S uv run --script --python 3.13 | ||
| # /// script | ||
| # requires-python = ">=3.11,<3.14" | ||
| # dependencies = [] | ||
| # /// | ||
| """Fail on reStructuredText syntax in docstrings. | ||
|
|
||
| pdoc renders docstrings as Markdown, so RST reaches readers verbatim: ``Foo`` | ||
| shows up with literal backticks and `:meth:` roles as literal text. | ||
|
|
||
| Only `*.py` files are checked, so standalone `*.uv` scripts -- this one | ||
| included -- are exempt and may use RST syntax in their own docstrings. | ||
|
|
||
| Standalone: uv resolves the interpreter from the metadata below and no | ||
| dependencies beyond the standard library are needed, so this runs without the | ||
| project environment. | ||
|
|
||
| ```bash | ||
| ./scripts/check_docstring_markdown.uv # defaults to _DEFAULT_PACKAGE | ||
| ./scripts/check_docstring_markdown.uv my_package/errors.py | ||
| uv run scripts/check_docstring_markdown.uv # same, without the executable bit | ||
| ``` | ||
|
|
||
| Exits 1 with a `file:line: message` report per violation. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Package scanned when no path argument is given, relative to the project root | ||
| # (this script's parent directory's parent). Adapt per repo. | ||
| _DEFAULT_PACKAGE = "airbyte" | ||
|
|
||
| # Double backticks, excluding a run of three or more (fence delimiters). | ||
| _DOUBLE_BACKTICK = re.compile(r"(?<!`)``(?!`)") | ||
| _RST_ROLE = re.compile(r":(?:meth|func|class|mod|attr|obj|exc|data|ref|doc):`") | ||
| _RST_FIELD = re.compile(r"^\s*:(?:param|parameter|arg|argument|type|returns?|rtype|raises|yields?|ivar|cvar|vartype)\b", re.MULTILINE) | ||
|
|
||
| _CHECKS = ( | ||
| (_DOUBLE_BACKTICK, "double backticks -- use single backticks for inline code"), | ||
| (_RST_ROLE, "reStructuredText role -- use a plain backticked reference"), | ||
| (_RST_FIELD, "reStructuredText field list -- use a Google-style `Args:` / `Returns:` / `Raises:` section"), | ||
| ) | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def _docstrings(tree: ast.Module) -> list[ast.Constant]: | ||
| """Every docstring node in *tree*, module and definitions alike.""" | ||
| nodes: list[ast.Constant] = [] | ||
| for node in ast.walk(tree): | ||
| if not isinstance(node, ast.Module | ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef): | ||
| continue | ||
| body = node.body | ||
| if body and isinstance(body[0], ast.Expr) and isinstance(body[0].value, ast.Constant) and isinstance(body[0].value.value, str): | ||
| nodes.append(body[0].value) | ||
|
aaronsteers marked this conversation as resolved.
|
||
| return nodes | ||
|
|
||
|
|
||
| def _offset_to_line(text: str, offset: int, start_line: int) -> int: | ||
| return start_line + text.count("\n", 0, offset) | ||
|
|
||
|
|
||
| def check_file(path: Path) -> list[str]: | ||
| """Violations in *path*, formatted as `file:line: message`.""" | ||
| source = path.read_text(encoding="utf-8") | ||
| try: | ||
| tree = ast.parse(source, filename=str(path)) | ||
| except SyntaxError as exc: | ||
| return [f"{path}:{exc.lineno or 0}: could not parse file ({exc.msg})"] | ||
|
|
||
| seen: set[tuple[int, str]] = set() | ||
| for node in _docstrings(tree): | ||
| # Constant.lineno is the opening quote; the body starts on that line. | ||
| for pattern, message in _CHECKS: | ||
| for match in pattern.finditer(node.value): | ||
| # One report per line and rule: a backtick pair matches twice. | ||
| seen.add((_offset_to_line(node.value, match.start(), node.lineno), message)) | ||
| return [f"{path}:{line}: {message}" for line, message in sorted(seen)] | ||
|
|
||
|
|
||
| def iter_python_files(targets: list[Path]) -> list[Path]: | ||
| files: list[Path] = [] | ||
| for target in targets: | ||
| if target.is_dir(): | ||
| files.extend(sorted(p for p in target.rglob("*.py") if "generated" not in p.parts)) | ||
| elif target.suffix == ".py": | ||
| files.append(target) | ||
| return files | ||
|
|
||
|
|
||
| def main(argv: list[str]) -> int: | ||
| root = Path(__file__).resolve().parent.parent | ||
| targets = [Path(arg) for arg in argv] or [root / _DEFAULT_PACKAGE] | ||
| violations = [v for path in iter_python_files(targets) for v in check_file(path)] | ||
|
|
||
| if violations: | ||
| print(f"Found {len(violations)} reStructuredText docstring violation(s):", file=sys.stderr) | ||
| for violation in violations: | ||
| print(violation, file=sys.stderr) | ||
| print( | ||
| "\nDocstrings are rendered as Markdown by pdoc. See CONTRIBUTING.md.", | ||
| file=sys.stderr, | ||
| ) | ||
| return 1 | ||
|
|
||
| print("✓ no reStructuredText syntax found in docstrings") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main(sys.argv[1:])) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Code examples falsely fail docstring checks
When a fenced Markdown example contains
``,_DOUBLE_BACKTICKflags it as invalid inline markup. Valid examples then fail CI despite containing no RST formatting.Learn more
_DOUBLE_BACKTICKmatches pairs anywhere in a docstring. Markdown code fences can contain arbitrary source code, including doubled backticks, without using reStructuredText formatting. The checker already permits three-backtick delimiters, but still scans the example inside them.Example: A docstring with a fenced Python block containing
print('``')reports a double-backtick violation and exits 1, although the fenced block is valid Markdown.Recommended fix: Exclude fenced code blocks before searching for inline RST syntax. Cover both backtick and tilde Markdown fences in tests.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid edge case, but nothing in the codebase triggers it. The checker passes on
release-candidate/v1, so no current docstring has a fenced example containing double backticks. This script is a verbatim copy of the ai-skills checker (only_DEFAULT_PACKAGEand the hint path differ). Skipping fenced blocks should therefore go into ai-skills first and then be re-copied here, so the two copies don't drift. Not opening a follow-up for now. If a real docstring ever hits this, the CI failure will name the file and line.Written by Devin