Skip to content

Commit fd4f3ce

Browse files
kartbenmmahadevan108
authored andcommitted
scripts: compliance: add sphinx-lint linter
ReStructuredText can sometimes be tricky to get right, especially for folks that might be more familiar with Markdown. This adds a Sphinx/RST linter to the compliance check script to help catch common issues that can easily go unnoticed and cause rendering issues. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
1 parent 88983f7 commit fd4f3ce

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

.github/workflows/compliance.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
run: |
3939
pip3 install setuptools
4040
pip3 install wheel
41-
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint clang-format unidiff
41+
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint clang-format unidiff sphinx-lint
4242
pip3 install west
4343
4444
- name: west setup

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,5 @@ MaintainersFormat.txt
9191
ModulesMaintainers.txt
9292
Nits.txt
9393
Pylint.txt
94+
SphinxLint.txt
9495
YAMLLint.txt

scripts/ci/check_compliance.py

+43
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,49 @@ def run(self):
14951495
p.line, col=p.column, desc=p.desc)
14961496

14971497

1498+
class SphinxLint(ComplianceTest):
1499+
"""
1500+
SphinxLint
1501+
"""
1502+
1503+
name = "SphinxLint"
1504+
doc = "Check Sphinx/reStructuredText files with sphinx-lint."
1505+
path_hint = "<git-top>"
1506+
1507+
# Checkers added/removed to sphinx-lint's default set
1508+
DISABLE_CHECKERS = ["horizontal-tab", "missing-space-before-default-role"]
1509+
ENABLE_CHECKERS = ["default-role"]
1510+
1511+
def run(self):
1512+
for file in get_files():
1513+
if not file.endswith(".rst"):
1514+
continue
1515+
1516+
try:
1517+
# sphinx-lint does not expose a public API so interaction is done via CLI
1518+
subprocess.run(
1519+
f"sphinx-lint -d {','.join(self.DISABLE_CHECKERS)} -e {','.join(self.ENABLE_CHECKERS)} {file}",
1520+
check=True,
1521+
stdout=subprocess.PIPE,
1522+
stderr=subprocess.STDOUT,
1523+
shell=True,
1524+
cwd=GIT_TOP,
1525+
)
1526+
1527+
except subprocess.CalledProcessError as ex:
1528+
for line in ex.output.decode("utf-8").splitlines():
1529+
match = re.match(r"^(.*):(\d+): (.*)$", line)
1530+
1531+
if match:
1532+
self.fmtd_failure(
1533+
"error",
1534+
"SphinxLint",
1535+
match.group(1),
1536+
int(match.group(2)),
1537+
desc=match.group(3),
1538+
)
1539+
1540+
14981541
class KeepSorted(ComplianceTest):
14991542
"""
15001543
Check for blocks of code or config that should be kept sorted.

scripts/requirements-compliance.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ junitparser>=2
99
pylint>=3
1010
unidiff
1111
yamllint
12+
sphinx-lint

0 commit comments

Comments
 (0)