From 1bc1b8198c6cf5b6a0d73f425b6638bd64adaccd Mon Sep 17 00:00:00 2001 From: Kilian Lieret Date: Mon, 30 Aug 2021 08:30:23 +0200 Subject: [PATCH] Improve formatting of context (no double parentheses) --- jekyll_relative_url_check/abstract.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jekyll_relative_url_check/abstract.py b/jekyll_relative_url_check/abstract.py index 44160e5..d35d642 100644 --- a/jekyll_relative_url_check/abstract.py +++ b/jekyll_relative_url_check/abstract.py @@ -11,7 +11,7 @@ def check_file(self, file: Path): return self._check_file(file) def _check_file(self, file: Path): - return self._check_text(file.read_text(), context=f"(in file {file})") + return self._check_text(file.read_text(), context=f"in file {file}") def check_files(self, files: Iterable[Path]): return all(map(self._check_file, files)) @@ -38,9 +38,12 @@ def _check_text(self, text: str, context=""): for regex in self.absolute_url_regexs: found |= set(regex.findall(line)) if found: - print( + msg = ( f"We believe we have found absolute URLS: {found} in this " - f"line: '{line}' ({context})" + f"line: '{line}'" ) + if context: + msg += f" ({context})" + print(msg) found_any = True return not found_any