Skip to content

Commit 03ae374

Browse files
committed
Split filter function and refactor error handling
1 parent 1188b8d commit 03ae374

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

llvm/utils/git/code-lint-helper.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,15 @@ def filter_changed_files(self, changed_files: Sequence[str]) -> Sequence[str]:
304304
_, ext = os.path.splitext(filepath)
305305
if ext != ".rst":
306306
continue
307-
if not filepath.startswith("clang-tools-extra/docs/clang-tidy/"):
307+
if not self._should_lint_file(filepath):
308308
continue
309309
if os.path.exists(filepath):
310310
filtered_files.append(filepath)
311311
return filtered_files
312312

313+
def _should_lint_file(self, filepath: str) -> bool:
314+
return filepath.startswith("clang-tools-extra/docs/clang-tidy/")
315+
313316
def run_linter_tool(self, files_to_lint: Iterable[str], args: LintArgs) -> str:
314317
if not files_to_lint:
315318
return ""
@@ -331,13 +334,19 @@ def run_linter_tool(self, files_to_lint: Iterable[str], args: LintArgs) -> str:
331334
if proc.returncode == 0:
332335
return ""
333336

334-
if output := proc.stdout.strip():
335-
return output
337+
output = proc.stdout.strip()
338+
error_output = proc.stderr.strip()
336339

337-
if error_output := proc.stderr.strip():
338-
return error_output
340+
parts: List[str] = []
341+
if output:
342+
parts.append(output)
343+
if error_output:
344+
parts.append(f"stderr:\n{error_output}")
339345

340-
return f"doc8 exited with return code {proc.returncode} but no output."
346+
if parts:
347+
return "\n\n".join(parts)
348+
else:
349+
return f"doc8 exited with return code {proc.returncode} but no output."
341350

342351

343352
ALL_LINTERS = (ClangTidyLintHelper(), Doc8LintHelper())

0 commit comments

Comments
 (0)