Skip to content

Line numbers in stylish and json report are off by one #22

@rixx

Description

@rixx

Describe the bug

All line numbers in the stylish and json report format are off by one, reporting line 0 when the actual issue is on line 1. In the compact export format, both versions of the line number are reported.

Steps to reproduce

Create a test.html with this content:

 <form></div>

For reference, I also tested this with indent errors by running against a file containing just <div></div>. The same issue occurs, but doesn't illustrate the issue with mixed content in some error messages.

Run curlylint test.html. The output reports line number 0:

test.html
0:8	Parse error: expected 'form' at 0:8	parse_error

Oh no! 💥 💔 💥
1 error reported

Run curlylint --format json test.html. The output reports line number 0:

[{"file_path": "test.html", "line": 0, "column": 8, "message": "Parse error: expected 'form' at 0:8", "code": "parse_error"}]
Oh no! 💥 💔 💥
1 error reported

Run curlylint --format compact. The output reports line number 1 and line number 0:

test.html:1:8: Parse error: expected 'form' at 0:8 (parse_error)
Oh no! 💥 💔 💥
1 error reported

Expected behavior

Consistent reporting of line numbers, preferably 1-indexed. 😉

Actual behavior

Behaviour is buggy/mixed, primarily 0-indexed, as described above. Sorry, no screenshots, but I pasted the output.

Reproducible demo

As above. Your issue template indicates that I should link a project for this, which I can do, if the one-line test.html is insufficient. Please let me know, in that case.

Bug source

The compact method casts its contents to str (1), which comes down to the IssueLocation class, which includes a +1 in its str() method. The other two formatters don't adjust the internal line number at all.

The issue of the mixed message in the compact report seems to sit deeper, as it's due to the issue message, which is constructed in each rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions