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

fixed norminette validating wrong includes #405

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions norminette/norm_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}


Expand Down
6 changes: 4 additions & 2 deletions norminette/rules/check_preprocessor_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/rules/samples/ko_include2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include"libft.h"
#include "libft.h"
#include "libft.h"
#include<unistd.h>
#include <unistd.h>
#include <unistd.h>
22 changes: 22 additions & 0 deletions tests/rules/samples/ko_include2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 1":
<INCLUDE=#include"libft.h"> <NEWLINE>
ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 2":
<INCLUDE=#include "libft.h"> <NEWLINE>
ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 3":
<INCLUDE=#include "libft.h"> <NEWLINE>
ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 4":
<INCLUDE=#include<unistd.h>> <NEWLINE>
ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 5":
<INCLUDE=#include <unistd.h>> <NEWLINE>
ko_include2.c - IsPreprocessorStatement In "GlobalScope" from "None" line 6":
<INCLUDE=#include <unistd.h>> <NEWLINE>
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