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>
This commit is contained in:
parent
88983f71d8
commit
fd4f3ce246
4 changed files with 46 additions and 1 deletions
2
.github/workflows/compliance.yml
vendored
2
.github/workflows/compliance.yml
vendored
|
|
@ -38,7 +38,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
pip3 install setuptools
|
pip3 install setuptools
|
||||||
pip3 install wheel
|
pip3 install wheel
|
||||||
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint clang-format unidiff
|
pip3 install python-magic lxml junitparser gitlint pylint pykwalify yamllint clang-format unidiff sphinx-lint
|
||||||
pip3 install west
|
pip3 install west
|
||||||
|
|
||||||
- name: west setup
|
- name: west setup
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -91,4 +91,5 @@ MaintainersFormat.txt
|
||||||
ModulesMaintainers.txt
|
ModulesMaintainers.txt
|
||||||
Nits.txt
|
Nits.txt
|
||||||
Pylint.txt
|
Pylint.txt
|
||||||
|
SphinxLint.txt
|
||||||
YAMLLint.txt
|
YAMLLint.txt
|
||||||
|
|
|
||||||
|
|
@ -1495,6 +1495,49 @@ class YAMLLint(ComplianceTest):
|
||||||
p.line, col=p.column, desc=p.desc)
|
p.line, col=p.column, desc=p.desc)
|
||||||
|
|
||||||
|
|
||||||
|
class SphinxLint(ComplianceTest):
|
||||||
|
"""
|
||||||
|
SphinxLint
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "SphinxLint"
|
||||||
|
doc = "Check Sphinx/reStructuredText files with sphinx-lint."
|
||||||
|
path_hint = "<git-top>"
|
||||||
|
|
||||||
|
# Checkers added/removed to sphinx-lint's default set
|
||||||
|
DISABLE_CHECKERS = ["horizontal-tab", "missing-space-before-default-role"]
|
||||||
|
ENABLE_CHECKERS = ["default-role"]
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
for file in get_files():
|
||||||
|
if not file.endswith(".rst"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
# sphinx-lint does not expose a public API so interaction is done via CLI
|
||||||
|
subprocess.run(
|
||||||
|
f"sphinx-lint -d {','.join(self.DISABLE_CHECKERS)} -e {','.join(self.ENABLE_CHECKERS)} {file}",
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
shell=True,
|
||||||
|
cwd=GIT_TOP,
|
||||||
|
)
|
||||||
|
|
||||||
|
except subprocess.CalledProcessError as ex:
|
||||||
|
for line in ex.output.decode("utf-8").splitlines():
|
||||||
|
match = re.match(r"^(.*):(\d+): (.*)$", line)
|
||||||
|
|
||||||
|
if match:
|
||||||
|
self.fmtd_failure(
|
||||||
|
"error",
|
||||||
|
"SphinxLint",
|
||||||
|
match.group(1),
|
||||||
|
int(match.group(2)),
|
||||||
|
desc=match.group(3),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class KeepSorted(ComplianceTest):
|
class KeepSorted(ComplianceTest):
|
||||||
"""
|
"""
|
||||||
Check for blocks of code or config that should be kept sorted.
|
Check for blocks of code or config that should be kept sorted.
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,4 @@ junitparser>=2
|
||||||
pylint>=3
|
pylint>=3
|
||||||
unidiff
|
unidiff
|
||||||
yamllint
|
yamllint
|
||||||
|
sphinx-lint
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue