Skip to main content

reStructuredText ドキュメントの検査・修正 CLI ツール

インストール

動作には Python 3.14 以上と docutils 0.22 以上 0.23 未満が必要である。 uv でセットアップする

uv sync

基本的な使い方

全サブコマンドに共通する呼び出しパターンは以下のとおりである

uv run wabun-rst-ulint <subcommand> [--check|--fix] <paths...>

paths にはファイルまたはディレクトリを指定する。 ディレクトリを指定した場合は .rst ファイルを再帰的に検索する

--check--fix は相互排他のオプションである。 --check は違反の検出のみを行い、違反があれば終了コード 1 で終了する。 --fix は検出された違反を自動修正する。 どちらも指定しない場合は --check と同じ動作になる

サブコマンド

サブコマンド

検査対象

inline-spacing

インライン記法の外部境界スペース

strong-spacing

強調表示前後の半角スペース

heading-width

セクションタイトル装飾行の表示幅

sentence-breaks

句点と改行のスタイルルール

inline-spacing

インライン記法(インラインリテラル、role 参照、名前付き参照、匿名参照、内部ターゲット、 interpreted text)の外部境界にある半角スペースの過不足を検出・修正する

対象となる根拠は 2 種類ある

  1. 認識の修復 — 日本語文字に直接隣接するインライン記法は docutils が正しく認識できず、 markup が黙って通常のテキストとして描画される

  2. 和文の視認性 — docutils が正しく認識する場合でも、和文組版として境界を分離するために 半角スペースを補う。 CJK 句読点の直前、中黒の前後、隣接する role の間がこれにあたる

それぞれの例を示す(左が入力、右が --fix の出力):

1. 認識の修復
   値は``foo``です          →  値は ``foo`` です

2. 和文の視認性
   これは :term:`X`。       →  これは :term:`X` 。
   中黒・:term:`X`・区切り  →  中黒・ :term:`X` ・区切り
   :ref:`a`:ref:`b` です    →  :ref:`a` :ref:`b` です

2 の適用範囲は Issue #22 で確定した。 旧 role_visible_spacing は 2 を適用し、旧 role_spacing と旧 inline_markup は 同じ構文を無変更としていたため、1 つの classifier へ統合した時点で衝突していた。 inline-spacing は 2 を採用する

uv run wabun-rst-ulint inline-spacing docs/
uv run wabun-rst-ulint inline-spacing --fix docs/

strong-spacing

強調表示の前後に半角スペースがない箇所を検出・修正する。 二重アスタリスクの strong emphasis ( **...** )のみを対象とし、 単一アスタリスクの emphasis ( *...* )は対象外である

uv run wabun-rst-ulint strong-spacing --fix source/

heading-width

セクションタイトルの下線・上下線の表示幅がタイトルと一致しない場合を検出・修正する。 日本語全角文字は表示幅 2 として計算する

共通オプションに加え、以下の追加オプションを持つ

オプション

説明

--diff

修正案を unified diff 形式で標準エラー出力に表示する(ファイルは書き換えない)。 --check / --fix と相互排他

--backup-suffix SUFFIX

--fix の前に元ファイルのバックアップを作成する。 --fix との併用が必須。空文字列、パスセパレータ、 .. は指定できない

--follow-symlinks

シンボリックリンクを検査対象に含める(既定ではスキップ)。 --fix とは併用不可

使用例

uv run wabun-rst-ulint heading-width --diff docs/
uv run wabun-rst-ulint heading-width --fix --backup-suffix .bak docs/

sentence-breaks

句点と改行に関するスタイルルールを検出・修正する。 本文中の句点の後ろで改行されていない箇所、およびテキストブロック末尾の不要な句点を検出する

追加オプションとして --follow-symlinks を持つ。 I/O エラーが発生した場合は終了コード 2 を返す(他のサブコマンドは終了コード 1)

uv run wabun-rst-ulint sentence-breaks --fix docs/

Issue #14 での破壊的変更

以下の 6 コマンドは削除された。エイリアスおよび非推奨警告は提供しないため、 旧コマンド名を指定した場合は終了コード 2 で拒否される

旧コマンド

移行先

literal-spacing

inline-spacing に統合

role-spacing

inline-spacing に統合

role-visible-spacing

inline-spacing に統合

inline-markup

inline-spacing に統合

section-underline

heading-width に改称

kuten

sentence-breaks に改称

ディレクトリの再帰検索

サブコマンドによりディレクトリの再帰検索の動作が異なる

heading-widthsentence-breaks は管理用ディレクトリ( .git.venv__pycache__node_modules_build 等)を自動的に除外する。 シンボリックリンクは --follow-symlinks を指定した場合のみ検査対象に含める

inline-spacingstrong-spacing はディレクトリの除外を行わず、シンボリックリンクの制御オプションも持たない

出力先

sentence-breaks は検出結果を標準出力に書き込む。 それ以外の 3 コマンド( inline-spacingstrong-spacingheading-width )は 検出結果( heading-width--diff 出力を含む)を標準エラー出力に書き込む。 標準出力のみをリダイレクトしても、この 3 コマンドの結果は捕捉できない

終了コード

コード

意味

0

違反なし、または --fix による修正が成功

1

違反を検出、対象ファイルが見つからない、読み取り/書き込みエラー

2

引数エラー(全サブコマンド。未知のコマンド名や排他オプションの同時指定など argparse が拒否した場合)、 および sentence-breaks の I/O エラー

開発

テストを実行する

uv run pytest

lint を実行する

uv run task ruff

Release gate

inline replacement の release gate は、seed 1507 で固定した42件 (pairwise 32件、interaction 10件)の generated cases と、frozen full corpus を検証する。 generated cases は42件それぞれについて、凍結した期待出力(または no-write)と一致することを検査する。 frozen full corpus は127件(うち must_fix 57件)で、件数と must_fix 件数、および57件の owner command 出力はこの127件に対して検査する。CLI をツリー単位で実行する gate は、 transaction 失敗を注入する fixture 1件を意図的に除いた126件を materialize する。 CI は Python 3.14 上で imported docutils==0.22.4 を明示的に確認する。

隣接する interpreted text / role / reference と inline literal は、1回の inline-spacing --fix ですべての候補を修正しない場合がある。運用では推奨順 sentence-breaks -> inline-spacing -> strong-spacing -> heading-width を最大3巡し、 3巡目に変更がないことを確認する。release gate は、frozen full corpus が1巡目で fixed point に到達すること、および隣接ケースを含む代表ドキュメントが2巡目までに到達して 3巡目が no-op になることを検証する。

ローカルで CI と同じ gate を実行する

uv run --isolated --with 'docutils==0.22.4' --with 'pytest>=8' python -c 'import docutils; assert docutils.__version__ == "0.22.4"'
uv run --isolated --with 'docutils==0.22.4' --with 'pytest>=8' pytest -q
uvx ruff check src tests
uvx ruff format --check src tests
git diff --check origin/main...HEAD

空白エラーの検査は range 形式で実行する。checkout 直後の working tree は clean なので、 引数なしの git diff --check では何も検査できない。CI は pull_request イベントで PR base との merge-base 比較を実行し、PR が追加した行だけを検査する。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wabun_rst_ulint-0.0.0.tar.gz (48.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wabun_rst_ulint-0.0.0-py3-none-any.whl (57.2 kB view details)

Uploaded Python 3

File details

Details for the file wabun_rst_ulint-0.0.0.tar.gz.

File metadata

  • Download URL: wabun_rst_ulint-0.0.0.tar.gz
  • Upload date:
  • Size: 48.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wabun_rst_ulint-0.0.0.tar.gz
Algorithm Hash digest
SHA256 805df7d10635d99c35da4adaa51e63abe74654ead342a6db6b3a3d1127a88af9
MD5 cf5f72b4fb25d09661e4c725398e7435
BLAKE2b-256 2bb733dddcb4d2f036a1d54585d5367d34308a380bc0ce10d3649bbd6341e315

See more details on using hashes here.

Provenance

The following attestation bundles were made for wabun_rst_ulint-0.0.0.tar.gz:

Publisher: publish-to-pypi.yml on usaturn/wabun-rst-ulint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wabun_rst_ulint-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: wabun_rst_ulint-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 57.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for wabun_rst_ulint-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55cdf8b5fa08fe9ffbf0ebf94d022f21e9cc79d3795d520c542ce142f8aeec74
MD5 542365da03f9d03d901ab1d3faa099ec
BLAKE2b-256 bb04b83fd77ef67e4e69e5bc719962e8cbb9c3aaba9fea852ad632f2eb5ad456

See more details on using hashes here.

Provenance

The following attestation bundles were made for wabun_rst_ulint-0.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on usaturn/wabun-rst-ulint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.0.1

2 files

This release

0.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page