Skip to content

Commit

Permalink
Add end location to line-length violation (StyraInc#981)
Browse files Browse the repository at this point in the history
This one was particularly bad before, as only the last character on
the line would indicate an issue, making it really hard to see. Now
we flag the whole line.

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored and srenatus committed Oct 1, 2024
1 parent 724b189 commit 77c3440
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion bundle/regal/rules/style/line_length.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ report contains violation if {
{"location": {
"file": input.regal.file.name,
"row": i + 1,
"col": line_length,
"col": 1,
"text": input.regal.file.lines[i],
"end": {
"row": i + 1,
"col": line_length,
},
}},
)
}
Expand Down
17 changes: 12 additions & 5 deletions bundle/regal/rules/style/line_length_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ foo == bar; bar == baz; [a, b, c, d, e, f] := [1, 2, 3, 4, 5, 6]; qux := [q | so
}],
"title": "line-length",
"location": {
"col": 103, "file": "policy.rego", "row": 6,
"col": 1,
"file": "policy.rego",
"row": 6,
"text": `foo == bar; bar == baz; [a, b, c, d, e, f] := [1, 2, 3, 4, 5, 6]; qux := [q | some q in input.nonsense]`,
"end": {"col": 103, "row": 6},
},
"level": "error",
}}
Expand Down Expand Up @@ -50,9 +53,11 @@ test_fail_line_too_long_but_below_breakable_word_threshold if {
"description": "Line too long",
"level": "error",
"location": {
"col": 56,
"col": 1,
"file": "policy.rego",
"row": 7, "text": "\t# Long url: https://www.example.com/this/is/a/very/long",
"row": 7,
"text": "\t# Long url: https://www.example.com/this/is/a/very/long",
"end": {"col": 56, "row": 7},
},
"related_resources": [{
"description": "documentation",
Expand All @@ -73,10 +78,12 @@ test_fail_line_exceeds_120_characters_even_if_not_in_config if {
"description": "Line too long",
"level": "error",
"location": {
"col": 147,
"col": 1,
"file": "policy.rego",
"row": 5,
# regal ignore:line-length
"row": 5, "text": "# Long url: https://www.example.com/this/is/a/very/long/url/that/cannot/be/shortened/and/should/trigger/an/error/anyway/so/that/it/can/be/shortened",
"text": "# Long url: https://www.example.com/this/is/a/very/long/url/that/cannot/be/shortened/and/should/trigger/an/error/anyway/so/that/it/can/be/shortened",
"end": {"col": 147, "row": 5},
},
"related_resources": [{
"description": "documentation",
Expand Down

0 comments on commit 77c3440

Please sign in to comment.