================
@@ -289,8 +291,61 @@ 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: Iterable[str]) ->
Sequence[str]:
+ return list(filter(self._should_lint_file, changed_files))
+
+ def _should_lint_file(self, filepath: str) -> bool:
+ return (
+ os.path.splitext(filepath)[1] == ".rst"
+ and filepath.startswith("clang-tools-extra/docs/clang-tidy/")
+ and os.path.exists(filepath)
+ )
+
+ 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 ""
+
+ parts: List[str] = []
+ if output := proc.stdout.strip():
+ parts.append(output)
+ if "D001" in output or "Line too long" in output:
+ parts.append(
+ "Note: documentation lines should be no more than 79
characters wide."
----------------
zeyi2 wrote:
Currently the `Note` is appended to the code block. It would be nice if user
can see:
```
⚠️ RST documentation linter, doc8 found issues in your code. ⚠️
You can test this locally with the following command:
View the output from doc8 here.
Note: documentation lines should be no more than 79 characters wide.
```
Also, I only add D001, IMO D000(invalid RST format), D002(no trailing
whitespace), D003(no tabulation for indentation), D004(no carriage returns (use
unix newlines)), D005(no newline at end of file) are relatively easy to
understand.
https://github.com/llvm/llvm-project/pull/172123
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits