Skip to content

[Tooling] Add RST single-backtick guardrail#7862

Closed
cutetocute wants to merge 6 commits intoPaddlePaddle:developfrom
StatefulDust:feat/rst-single-backtick-guardrail
Closed

[Tooling] Add RST single-backtick guardrail#7862
cutetocute wants to merge 6 commits intoPaddlePaddle:developfrom
StatefulDust:feat/rst-single-backtick-guardrail

Conversation

@cutetocute
Copy link
Contributor

@cutetocute cutetocute commented Mar 12, 2026

Summary

  • add a conservative RST checker for bare single-backtick interpreted text
  • skip valid role syntax such as :math:... and reference or link forms such as text_ and text <url>_
  • wire the checker into the existing pre-commit and prek path so codestyle-check picks it up automatically

Validation

  • use synthetic samples to confirm bare single backticks fail while :math:... and text <url>_ pass
  • run prek run --files ci_scripts/check_rst_single_backticks.py .pre-commit-config.yaml

Notes

  • this change only checks files passed into pre-commit, so it acts as a guardrail for touched RST files instead of requiring an all-at-once cleanup of existing docs
  • existing historical violations outside the touched file set are intentionally left for follow-up cleanup work

@paddle-bot
Copy link

paddle-bot bot commented Mar 12, 2026

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7862.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a pre-commit/prek guardrail to detect and reject “bare” single-backtick interpreted text in .rst files, while allowing common valid RST patterns (roles and link/reference forms).

Changes:

  • Introduce ci_scripts/check_rst_single_backticks.py to flag invalid single-backtick usage with file/line/column diagnostics.
  • Register a local pre-commit hook so the checker runs automatically on .rst files.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
ci_scripts/check_rst_single_backticks.py Implements the RST single-backtick detection and reporting logic.
.pre-commit-config.yaml Wires the checker into pre-commit as a local hook for .rst files.

You can also share your feedback on Copilot code review. Take the survey.

@cutetocute
Copy link
Contributor Author

Addressed the current review feedback in aee9255.

  • Switched the local hook from language: system + python3 to language: python + entry: python ... so pre-commit manages the interpreter more portably.
  • Updated the checker to skip indented content inside .. code-block:: / .. code:: directives and :: literal blocks, so literal text in code blocks is not flagged as invalid inline backticks.

Validation:

  • prek run --files ci_scripts/check_rst_single_backticks.py .pre-commit-config.yaml

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


You can also share your feedback on Copilot code review. Take the survey.

@cutetocute
Copy link
Contributor Author

Addressed the new review feedback in this update.

  • Added parsed-literal to the literal-block directive matcher, so indented content under .. parsed-literal:: is skipped by the checker.
  • This keeps guardrail behavior consistent with existing handling for .. code-block::, .. code::, and :: literal blocks.

Validation:

  • synthetic sample: backticks inside parsed-literal are ignored, while normal prose bad is still reported
  • prek run --files ci_scripts/check_rst_single_backticks.py

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

continue
if indent > pending_indent:
in_literal_block = True
block_indent = pending_indent
if in_literal_block:
if not stripped:
continue
if indent > block_indent:
@cutetocute
Copy link
Contributor Author

Addressed the latest literal-block indent review in this update.

  • Use the first literal content line indent as block_indent when entering a literal/code block.
  • Keep lines with indent >= block_indent inside the literal block; exit only when indent < block_indent (excluding blank lines).

Validation:

  • synthetic sample confirms same-indent literal lines are no longer treated as prose
  • prose lines after block dedent are still reported correctly
  • prek run --files ci_scripts/check_rst_single_backticks.py

@cutetocute
Copy link
Contributor Author

Extra validation note on the latest indent change:

  • Re-ran the checker over all .rst files with the updated implementation.
  • Also compared hit sets between the previous indent logic and the updated logic on the whole repo.
  • Result in current corpus: identical hit set (OLD=1088, NEW=1088, NEW_ONLY=0, OLD_ONLY=0).

So this update does not change current findings, but keeps literal-block handling semantically safer for edge-case indentation patterns.

@ooooo-create
Copy link
Collaborator

no plan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants