diff --git a/norminette/norm_error.py b/norminette/norm_error.py index c6882fa9..9121336c 100644 --- a/norminette/norm_error.py +++ b/norminette/norm_error.py @@ -98,6 +98,7 @@ "MIXED_SPACE_TAB": "Mixed spaces and tabs", "ATTR_EOL": "Function attribute must be at the end of line", "INVALID_HEADER": "Missing or invalid 42 header", + "INCLUDE_MISSING_SP": "Missing space between include and filename", } diff --git a/norminette/rules/check_preprocessor_include.py b/norminette/rules/check_preprocessor_include.py index e383eb64..7d41e7d7 100644 --- a/norminette/rules/check_preprocessor_include.py +++ b/norminette/rules/check_preprocessor_include.py @@ -26,7 +26,9 @@ def run(self, context): val = context.peek_token(i).value.split("include", 1)[1] content = Lexer(val, context.peek_token(i).pos[0]) tkns = content.get_tokens() - i = 1 + i = 0 + if tkns[i].type not in ["TAB", "SPACE"]: + context.new_error("INCLUDE_MISSING_SP", tkns[i]) while i < len(tkns) and tkns[i].type in ["TAB", "SPACE"]: if tkns[i].type == "TAB": context.new_error("TAB_INSTEAD_SPC", tkns[i]) @@ -44,7 +46,7 @@ def run(self, context): filetype = tkns[i].value.split(".")[-1][0] except: filetype = "" - while tkns[i].type != "NEWLINE" and i < len(tkns) - 1: + while i < len(tkns) - 1 and tkns[i].type != "NEWLINE": i += 1 if (tkns[i].type == "NEWLINE" and tkns[i - 1].type in ["SPACE", "TAB"]) or tkns[ i diff --git a/tests/rules/samples/ko_include2.c b/tests/rules/samples/ko_include2.c new file mode 100644 index 00000000..b081dc79 --- /dev/null +++ b/tests/rules/samples/ko_include2.c @@ -0,0 +1,6 @@ +#include"libft.h" +#include "libft.h" +#include "libft.h" +#include +#include +#include diff --git a/tests/rules/samples/ko_include2.out b/tests/rules/samples/ko_include2.out new file mode 100644 index 00000000..e12ccc07 --- /dev/null +++ b/tests/rules/samples/ko_include2.out @@ -0,0 +1,22 @@ +ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 1": + +ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 2": + +ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 3": + +ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 4": + > +ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 5": + > +ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 6": + > +ko_include2.c: Error! +Error: INCLUDE_MISSING_SP (line: 1, col: 1): Missing space between include and filename +Error: INVALID_HEADER (line: 1, col: 1): Missing or invalid 42 header +Error: TAB_INSTEAD_SPC (line: 2, col: 2): Found tab when expecting space +Error: TAB_INSTEAD_SPC (line: 3, col: 3): Found tab when expecting space +Error: TAB_INSTEAD_SPC (line: 3, col: 5): Found tab when expecting space +Error: INCLUDE_MISSING_SP (line: 4, col: 4): Missing space between include and filename +Error: TAB_INSTEAD_SPC (line: 5, col: 5): Found tab when expecting space +Error: TAB_INSTEAD_SPC (line: 6, col: 6): Found tab when expecting space +Error: TAB_INSTEAD_SPC (line: 6, col: 9): Found tab when expecting space