Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution-py-linter-formatter #1616

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
23 changes: 17 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
def format_linter_error(error: dict) -> dict:
# write your code here
pass
return {
("name" if key == "code" else "source" if key == "filename" else
"message" if key == "text" else tuple(key.split("_"))[0]):
("flake8" if key == "filename" else value)
for key, value in error.items() if key != "physical_line"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not readable code. please, use static key names and choose the correct fields from the dictionary for those keys. for example:

"name": error["code"]

}


def format_single_linter_file(file_path: str, errors: list) -> dict:
# write your code here
pass
return {
("errors" if elem == "error" else elem):
([format_linter_error(error) for error in errors]
if elem == "error" else file_path if elem == "path" else
"failed" if elem == "status" and errors != [] else "passed")
for elem in ("error", "path", "status")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same here. also, elem is bad naming for variable

}


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()
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use key, value if you already know field names. for example file_path, errors would be better

Loading