================
@@ -289,8 +291,65 @@ def _clean_clang_tidy_output(self, output: str) -> str:
         return ""
 
 
+class Doc8LintHelper(LintHelper):
+    name: Final = "doc8"
+    friendly_name: Final = "RST documentation linter"
 
-ALL_LINTERS = (ClangTidyLintHelper(),)
+    def instructions(self, files_to_lint: Iterable[str], args: LintArgs) -> 
str:
+        return f"doc8 -q {' '.join(files_to_lint)}"
+
+    def filter_changed_files(self, changed_files: Sequence[str]) -> 
Sequence[str]:
+        filtered_files: List[str] = []
+        for filepath in changed_files:
+            _, ext = os.path.splitext(filepath)
+            if ext != ".rst":
+                continue
+            if not self._should_lint_file(filepath):
+                continue
+            if os.path.exists(filepath):
+                filtered_files.append(filepath)
+        return filtered_files
+
+    def _should_lint_file(self, filepath: str) -> bool:
+        return filepath.startswith("clang-tools-extra/docs/clang-tidy/")
+
+    def run_linter_tool(self, files_to_lint: Iterable[str], args: LintArgs) -> 
str:
+        if not files_to_lint:
+            return ""
+
+        doc8_cmd = [args.doc8_binary, "-q"]
+        doc8_cmd.extend(files_to_lint)
+
+        if args.verbose:
+            print(f"Running doc8: {' '.join(doc8_cmd)}")
+
+        proc = subprocess.run(
+            doc8_cmd,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            text=True,
+            check=False,
+        )
+
+        if proc.returncode == 0:
+            return ""
+
+        output = proc.stdout.strip()
+        error_output = proc.stderr.strip()
+
+        parts: List[str] = []
+        if output:
----------------
EugeneZelenko wrote:

I think walrus operator should be used, just to reduce amount of code. Same for 
error output.

https://github.com/llvm/llvm-project/pull/172123
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to