From 35b90438b9f51d02f8247e01773908cf98e9300e Mon Sep 17 00:00:00 2001 From: Brian de Buiteach Date: Mon, 1 Jun 2020 22:40:30 +0100 Subject: [PATCH] display line content in non-compliant files in pre-commit messages --- pre_commit_hooks/detect_verbose_curl.py | 5 +++-- tests/detect_verbose_curl_test.py | 28 ++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pre_commit_hooks/detect_verbose_curl.py b/pre_commit_hooks/detect_verbose_curl.py index dc3e2f2..d5daa36 100644 --- a/pre_commit_hooks/detect_verbose_curl.py +++ b/pre_commit_hooks/detect_verbose_curl.py @@ -14,8 +14,9 @@ def _get_file_verbose_occurrences(filename: str) -> int: for i, line in enumerate(f, 1): if CURL_VERBOSE_PATTERN.search(line): print( - 'Talkative/Verbose cURL command found: ' - '{filename}:{i}:{line}', + f'Talkative/Verbose cURL command found:' + f'{repr(filename)}:{repr(i)}:{line.decode("utf-8")}', + end='', ) file_verbose_occurrences += 1 return file_verbose_occurrences diff --git a/tests/detect_verbose_curl_test.py b/tests/detect_verbose_curl_test.py index 396947b..f9617d4 100644 --- a/tests/detect_verbose_curl_test.py +++ b/tests/detect_verbose_curl_test.py @@ -58,28 +58,28 @@ def test_failing(tmpdir, capsys): out, _ = capsys.readouterr() assert out == ( - "Talkative/Verbose cURL command found: f.sh:3:b\'curl -v -X GET" - " ${url} -H \"X-Custom-Header: pytest-test\"\\n\'\n" - "Talkative/Verbose cURL command found: f.sh:4:b\'curl -X GET " - "${url} -H \"X-Custom-Header: pytest-test\" --verbose\\n\'\n" - 'Talkative/Verbose cURL command found: ' - "f.sh:5:b\'curl --write-out output.txt" - " -X GET ${url} -H \"X-Custom-Header: pytest-test\"\\n\'\n" + "Talkative/Verbose cURL command found:'f.sh':3:curl -v -X GET" + " ${url} -H \"X-Custom-Header: pytest-test\"\n" + "Talkative/Verbose cURL command found:'f.sh':4:curl -X GET " + "${url} -H \"X-Custom-Header: pytest-test\" --verbose\n" + 'Talkative/Verbose cURL command found:' + "'f.sh':5:curl --write-out output.txt" + " -X GET ${url} -H \"X-Custom-Header: pytest-test\"\n" - "Talkative/Verbose cURL command found: f.groovy:3:b\'curl " + "Talkative/Verbose cURL command found:'f.groovy':3:curl " "-d \"{key1:value1, key2:value2}\"" " -w output.txt -H \"Content-Type: application/json\"" - " -X POST ${url}\\n\'\n" + ' -X POST ${url}\n' 'Talkative/Verbose cURL command found:' - " f.groovy:4:b\'curl " + "'f.groovy':4:curl " '--trace-ascii ascii.txt ' "-d \"{key1:value1, key2:value2}\"" " -H \"Content-Type: application/json\" " - "-X POST ${url}\\n\'\n" - "Talkative/Verbose cURL command found: f.groovy:5:b\'curl " + '-X POST ${url}\n' + "Talkative/Verbose cURL command found:'f.groovy':5:curl " "-d \"{key1:value1, key2:value2}\"" - '-X POST ${url} --trace trace.txt ' - " -H \"Content-Type: application/json\"\\n\'\n" + ' -X POST ${url} --trace trace.txt ' + " -H \"Content-Type: application/json\"\n" 'Number of talkative/verbose cURL commands: 6\n' )