Skip to content

Commit 6d737fb

Browse files
committed
🧪 Start linting YAML/JSON code blocks in docs
This uses a third-party Sphinx extension now [[1]]. In the future, though, we should explore using the solution from ansible-documentation [[2]]. [1]: https://github.com/kai687/sphinxawesome-codelinter [2]: ansible/ansible-documentation#2385
1 parent 3280f3b commit 6d737fb

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

‎.github/workflows/ci-cd.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ jobs:
515515
- pre-commit
516516
- metadata-validation
517517
- build-docs
518+
- codelinter-docs
518519
- coverage-docs
519520
- doctest-docs
520521
- linkcheck-docs

‎.github/workflows/pip-tools.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ jobs:
8787
lock-file-env:
8888
- build-dists
8989
- build-docs
90+
- codelinter-docs
9091
- coverage-docs
9192
- doctest-docs
9293
- linkcheck-docs
@@ -106,6 +107,8 @@ jobs:
106107
lock-file-extra-input: pyproject.toml
107108
- lock-file-env: build-docs
108109
lock-file-extra-input: ''
110+
- lock-file-env: codelinter-docs
111+
lock-file-extra-input: ''
109112
- lock-file-env: coverage-docs
110113
lock-file-extra-input: ''
111114
- lock-file-env: doctest-docs

‎dependencies/direct/build-docs.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ Sphinx # main docs framework
66
sphinx-autodoc-typehints # gets function param types from annotations
77
sphinx-issues # Sphinx roles providing support for linking GitHub
88
sphinx-tabs # Sphinx directives providing support for HTML tabs
9+
sphinxawesome-codelinter # lints snippets of embedded code
910
sphinxcontrib-apidoc # automatic API pages generator
11+
yamllint # called by `sphinxawesome-codelinter`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build-docs.in

‎docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
'sphinx_autodoc_typehints', # gets function param types from annotations
7777
'sphinx_issues', # implements `:issue:`, `:pr:` and other GH-related roles
7878
'sphinx_tabs.tabs',
79+
'sphinxawesome.codelinter', # checks code blocks with linters
7980
'sphinxcontrib.apidoc',
8081

8182
# In-tree extensions:
@@ -135,6 +136,13 @@
135136
typehints_use_signature = True
136137
typehints_use_signature_return = True
137138

139+
# -- Options for sphinxawesome.codelinter extension --------------------------
140+
141+
codelinter_languages = {
142+
'json': 'python -Im json.tool',
143+
'yaml': 'python -Im yamllint -',
144+
}
145+
138146
# -- Options for sphinxcontrib.apidoc extension ------------------------------
139147

140148
apidoc_excluded_paths = []

‎tox.ini

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,40 @@ pass_env =
398398
READTHEDOCS* # Present @ RTD
399399

400400

401+
[testenv:codelinter-docs]
402+
allowlist_externals =
403+
{[testenv:build-docs]allowlist_externals}
404+
description = Lint code snippets in docs
405+
changedir = {[testenv:build-docs]changedir}
406+
commands_pre =
407+
# Retrieve possibly missing commits:
408+
-git fetch --unshallow
409+
-git fetch --tags
410+
411+
# Clean up sphinxcontrib-apidoc generated RST files:
412+
-git clean -x -f -- 'pkg{/}*.rst'
413+
commands =
414+
{envpython} \
415+
{[python-cli-options]byte-errors} \
416+
{[python-cli-options]max-isolation} \
417+
{[python-cli-options]warnings-to-errors} \
418+
-m sphinx \
419+
-j auto \
420+
{tty:--color} \
421+
-a \
422+
-n \
423+
-W --keep-going \
424+
-b codelinter \
425+
-d '{temp_dir}{/}.doctrees' \
426+
. \
427+
{posargs:{envtmpdir}{/}codelinter}
428+
commands_post =
429+
deps =
430+
-r{toxinidir}{/}dependencies{/}direct{/}{envname}.in
431+
pass_env =
432+
{[testenv:build-docs]pass_env}
433+
434+
401435
[testenv:coverage-docs]
402436
allowlist_externals =
403437
{[testenv:build-docs]allowlist_externals}

0 commit comments

Comments
 (0)