Skip to content

Commit

Permalink
add colors to the norminette (#492)
Browse files Browse the repository at this point in the history
colors can be change/customize form the norinette/colors file,
only few colors can be use, and not all the line is painted to avoid using invisible line trick
  • Loading branch information
yroussea authored Jun 20, 2024
1 parent 164bdfb commit a88f7fb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
44 changes: 44 additions & 0 deletions norminette/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
red = {
"TOO_MANY_ARGS",
"TOO_MANY_VARS_FUNC",
}
yellow = {
"MIXED_SPACE_TAB",
"BRACE_NEWLINE"
}
green = {
"TOO_MANY_FUNCS",
}
blue = {
"SPC_INSTEAD_TAB",
"TAB_INSTEAD_SPC",
"CONSECUTIVE_SPC",
"CONSECUTIVE_WS",
"SPC_BFR_OPERATOR",
"SPC_AFTER_OPERATOR",
"NO_SPC_BFR_OPR",
"NO_SPC_AFR_OPR",
"SPC_AFTER_PAR",
"SPC_BFR_PAR",
"NO_SPC_AFR_PAR",
"NO_SPC_BFR_PAR",
"SPC_AFTER_POINTER",
"SPC_LINE_START",
"SPC_BFR_POINTER",
"SPACE_BEFORE_FUNC",
"TOO_MANY_TABS_FUNC",
"TOO_MANY_TABS_TD",
"MISSING_TAB_FUNC",
"MISSING_TAB_VAR",
"TOO_MANY_TAB_VAR",
"LINE_TOO_LONG",
"EXP_PARENTHESIS",
}
pink = {
"WRONG_SCOPE_COMMENT",
"COMMENT_ON_INSTR",
}
grey = {
"INVALID_HEADER",
"WRONG_SCOPE_COMMENT",
}
21 changes: 20 additions & 1 deletion norminette/norm_error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
errors = {
from norminette.colors import red, blue, yellow, pink, grey, green

errors = {
"SPC_INSTEAD_TAB": "Spaces at beginning of line",
"TAB_INSTEAD_SPC": "Found tab when expecting space",
"CONSECUTIVE_SPC": "Two or more consecutives spaces",
Expand Down Expand Up @@ -150,11 +152,28 @@ def __init__(self, errno, line, col):
self.error_pos = f"(line: {(str(self.line)).rjust(3)}, col: {(str(self.col)).rjust(3)}):\t"
self.prefix = f"Error: {self.errno:<20} {self.error_pos:>21}"
self.error_msg = f"{errors.get(self.errno, 'ERROR NOT FOUND')}"
self.no_color = "\033[0m"
self.color = self.no_color
color = {
"\033[91m":red,
"\033[92m":green,
"\033[93m":yellow,
"\033[94m":blue,
"\033[95m":pink,
"\033[97m":grey,
}
for key,value in color.items():
if errno in value:
self.color = key
break
self.prefix = self.prefix
self.error_msg = self.color + self.error_msg + self.no_color

def __str__(self):
return self.prefix + self.error_msg



class NormWarning:
def __init__(self, errno, line, col):
self.errno = errno
Expand Down

0 comments on commit a88f7fb

Please sign in to comment.