Commit fd4f3ce2 authored by Benjamin Cabé's avatar Benjamin Cabé Committed by Mahesh Mahadevan
Browse files

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: default avatarBenjamin Cabé <benjamin@zephyrproject.org>
parent 88983f71
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ jobs:
      run: |
        pip3 install setuptools
        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

    - name: west setup
+1 −0
Original line number Diff line number Diff line
@@ -91,4 +91,5 @@ MaintainersFormat.txt
ModulesMaintainers.txt
Nits.txt
Pylint.txt
SphinxLint.txt
YAMLLint.txt
+43 −0
Original line number Diff line number Diff line
@@ -1495,6 +1495,49 @@ class YAMLLint(ComplianceTest):
                                      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):
    """
    Check for blocks of code or config that should be kept sorted.
+1 −0
Original line number Diff line number Diff line
@@ -9,3 +9,4 @@ junitparser>=2
pylint>=3
unidiff
yamllint
sphinx-lint