From 06a852d11b357661f57b0ff2fd4e83e32b03145f Mon Sep 17 00:00:00 2001 From: Anton Kozhukhovskiy Date: Wed, 12 Jul 2023 03:09:38 +0300 Subject: [PATCH 1/2] complete task --- app/main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/main.py b/app/main.py index 20463c45..e29562da 100644 --- a/app/main.py +++ b/app/main.py @@ -1,13 +1,27 @@ 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": [ + format_linter_error(error) + for error in errors + if error["filename"] == file_path + ], + "path": file_path, + "status": "failed" if len(errors) else "passed" + } def format_linter_report(linter_report: dict) -> list: - # write your code here - pass + return [ + format_single_linter_file(key, value) + for key, value in linter_report.items() + ] From aa664cfef2f9012448b6a1872c5985884a1000e0 Mon Sep 17 00:00:00 2001 From: Anton Kozhukhovskiy Date: Wed, 12 Jul 2023 03:14:22 +0300 Subject: [PATCH 2/2] change method for get value from dict --- app/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index e29562da..c2053beb 100644 --- a/app/main.py +++ b/app/main.py @@ -1,9 +1,9 @@ def format_linter_error(error: dict) -> dict: return { - "line": error["line_number"], - "column": error["column_number"], - "message": error["text"], - "name": error["code"], + "line": error.get("line_number"), + "column": error.get("column_number"), + "message": error.get("text"), + "name": error.get("code"), "source": "flake8" } @@ -13,7 +13,7 @@ def format_single_linter_file(file_path: str, errors: list) -> dict: "errors": [ format_linter_error(error) for error in errors - if error["filename"] == file_path + if error.get("filename") == file_path ], "path": file_path, "status": "failed" if len(errors) else "passed"