-
Notifications
You must be signed in to change notification settings - Fork 146
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
Add a new user/beginner friendly errors system #505
base: master
Are you sure you want to change the base?
Conversation
This reverts commit a88f7fb, since it broke tests and flake8.
…rmatter the new style with colors and arrows
Subjective nit, this should probably have a bit more padding for readability's sake. Other than that, looks pretty amazing :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall a very good new feature, the norminette would really benefit from its addition!
Some changes are still necessary in my opinion, but please you are absolutely free to discuss your choices!
Bests,
tblochet
class HumanizedErrorsFormatter(_formatter): | ||
def __str__(self) -> str: | ||
output = '' | ||
for file in self.files: | ||
for error in file.errors: | ||
highlight = error.highlights[0] | ||
# Location | ||
output += f"\x1b[;97m{file.path}:{highlight.lineno}:{highlight.column}\x1b[0m" | ||
output += ' ' + error.name | ||
if not highlight.length: | ||
output += ' ' + error.text | ||
if highlight.length: | ||
# Line | ||
output += f"\n {highlight.lineno:>5} | {file[highlight.lineno,].translated}" | ||
# Arrow | ||
output += "\n | " + ' ' * (highlight.column - 1) | ||
output += f"\x1b[0;91m{'^' * (highlight.length or 0)} {highlight.hint or error.text}\x1b[0m" | ||
output += '\n' | ||
return output | ||
|
||
|
||
class ShortErrorsFormatter(_formatter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a better idea to create another _formatter
class, rather than modifying the existing default class.
maybe class CompilerLikeErrorsFormatter
# if len(item) == 2: | ||
# lineno, column = item | ||
# return self._line_to_index[lineno + column] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See last comment, potentially breaking change
@@ -151,6 +151,7 @@ Error: TOO_MANY_WS (line: 7, col: 1): Extra whitespaces for indent | |||
Error: TAB_REPLACE_SPACE (line: 7, col: 2): Found tab when expecting space | |||
Error: TOO_MANY_WS (line: 9, col: 1): Extra whitespaces for indent level | |||
Error: MACRO_NAME_CAPITAL (line: 9, col: 10): Macro name must be capitalized | |||
Error: SPC_BEFORE_NL (line: 26, col: 2): Space before newline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a potentially breaking change, it should be in a separate PR
context.new_error("RETURN_PARENTHESIS", context.peek_token(tmp)) | ||
token = context.peek_token(tmp) | ||
error = Error.from_name("RETURN_PARENTHESIS") | ||
error.add_highlight(token) | ||
context.errors.add(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to do a complete refacto on this,
There are about 145 more context.new_error()
still being used.
Maybe in another PR ?
@@ -11,7 +11,8 @@ | |||
from norminette.registry import Registry | |||
from norminette.errors import JSONErrorsFormatter | |||
from norminette.errors import Error, Errors, Highlight as H | |||
from norminette.errors import HumanizedErrorsFormatter | |||
from norminette.errors import ShortErrorsFormatter | |||
# from norminette.errors import HumanizedErrorsFormatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comment
Hi, this is one of my drafts (maybe 7 months ago) focused on beginners (and quality of life) that I wrote for norminette when @matthieu42Network was accepting my PRs, I'm not sure if he's still available, but recently it seems like new people became collaborators, this made me happy and willing to continue with contributions.
New errors formatting
To use the new format is not necessary a new configuration, just run your norminette:
I added a red color to the errors: