From d9a614184b085342c8ae16662df8e7beb92d5284 Mon Sep 17 00:00:00 2001 From: Misha Bigun Date: Mon, 25 Nov 2024 21:24:05 +0200 Subject: [PATCH 1/2] implement py-linter-formatter --- app/main.py | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/app/main.py b/app/main.py index 20463c45..c5ae3be3 100644 --- a/app/main.py +++ b/app/main.py @@ -1,13 +1,45 @@ def format_linter_error(error: dict) -> dict: - # write your code here - pass + return { + "line": error["line_number"], + "column": error["column_number"], + "message": error["text"], + "name": error["code"], + "source": "flake8" + } def format_single_linter_file(file_path: str, errors: list) -> dict: - # write your code here - pass + return { + "errors": [ + { + "line": error["line_number"], + "column": error["column_number"], + "message": error["text"], + "name": error["code"], + "source": "flake8" + } + for error in errors + ], + "path": file_path, + "status": "failed" + } def format_linter_report(linter_report: dict) -> list: - # write your code here - pass + return [ + { + "errors": [ + { + "line": error["line_number"], + "column": error["column_number"], + "message": error["text"], + "name": error["code"], + "source": "flake8" + } + for error in errors + ], + "path": file_name, + "status": "failed" if errors else "passed" + } + for file_name, errors in linter_report.items() + ] From b78cd8c44ec868f0257eb3a8c3ffc08d4a57ce85 Mon Sep 17 00:00:00 2001 From: Misha Bigun Date: Tue, 26 Nov 2024 21:23:16 +0200 Subject: [PATCH 2/2] Fix file_name is correctly defined and used within the loop --- app/main.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/app/main.py b/app/main.py index c5ae3be3..12c155de 100644 --- a/app/main.py +++ b/app/main.py @@ -21,25 +21,12 @@ def format_single_linter_file(file_path: str, errors: list) -> dict: for error in errors ], "path": file_path, - "status": "failed" + "status": "failed" if errors else "passed" } def format_linter_report(linter_report: dict) -> list: return [ - { - "errors": [ - { - "line": error["line_number"], - "column": error["column_number"], - "message": error["text"], - "name": error["code"], - "source": "flake8" - } - for error in errors - ], - "path": file_name, - "status": "failed" if errors else "passed" - } + format_single_linter_file(file_name, errors) for file_name, errors in linter_report.items() ]