Skip to content

Commit

Permalink
Standardize highlight offset
Browse files Browse the repository at this point in the history
 - min/max the col (sometime norminette returns a weird col)
 - add a visual test
 - We don't need to do -1 (norminette do +1 only for col=0 and this behavior is a bug)
  • Loading branch information
GlaceCoding committed Nov 29, 2021
1 parent b6e9f29 commit d5e8206
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
7 changes: 4 additions & 3 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Norminette(Linter):
(?:(?P<message>.+))
'''

line_col_base = (1, 1)
line_col_base = (1, 0)
multiline = True
error_stream = util.STREAM_BOTH
defaults = {
Expand All @@ -50,18 +50,19 @@ def split_match(self, match):
return error

def reposition_match(self, line, col, m, vv):
col = int(m['col2']) - 1
col = int(m['col2'])
if col > 0:
content = vv.select_line(line)
c = 0
cr = 0
maxc = col
while c < maxc and c < len(content):
while cr < maxc and c < len(content):
if content[c] == '\t':
spaces = (4 - math.ceil(cr % 4))
col -= spaces
cr += spaces
c += 1
cr += 1
col = max(min(col, len(content) - 1), 0)

return super().reposition_match(line, col, m, vv)
42 changes: 42 additions & 0 deletions test/test-linter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <--- here error on the second `/`
//23456789012345678901234567890

// vvvv------ 1 error
int main(void)
{
return a;
if (test)
return a;
}
// ^---^--- 2 errors on `a`
static int test(void)
{
return (0);
}
// ^^^^--- 1 on error on `test`

int n(long a)
{
double a;

return (0);
}

#include "test.h" // <--- here here `include`

int n(void)
{
return a;
if (test)
return a;
}
// ^---^--- 4 errors: 2 on `a`
// ^^^-^^^--------- 2 after `;`

int n(void)
{
return (a);
if (test)
return (a);
}
// ^---^--- 2 errors after `;`

0 comments on commit d5e8206

Please sign in to comment.