Skip to content

Commit e886f35

Browse files
authoredAug 12, 2024··
Add end location to line-length violation (#981)
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>
1 parent 3236efd commit e886f35

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed
 

‎bundle/regal/rules/style/line_length.rego

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ report contains violation if {
2828
{"location": {
2929
"file": input.regal.file.name,
3030
"row": i + 1,
31-
"col": line_length,
31+
"col": 1,
3232
"text": input.regal.file.lines[i],
33+
"end": {
34+
"row": i + 1,
35+
"col": line_length,
36+
},
3337
}},
3438
)
3539
}

‎bundle/regal/rules/style/line_length_test.rego

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ foo == bar; bar == baz; [a, b, c, d, e, f] := [1, 2, 3, 4, 5, 6]; qux := [q | so
2020
}],
2121
"title": "line-length",
2222
"location": {
23-
"col": 103, "file": "policy.rego", "row": 6,
23+
"col": 1,
24+
"file": "policy.rego",
25+
"row": 6,
2426
"text": `foo == bar; bar == baz; [a, b, c, d, e, f] := [1, 2, 3, 4, 5, 6]; qux := [q | some q in input.nonsense]`,
27+
"end": {"col": 103, "row": 6},
2528
},
2629
"level": "error",
2730
}}
@@ -50,9 +53,11 @@ test_fail_line_too_long_but_below_breakable_word_threshold if {
5053
"description": "Line too long",
5154
"level": "error",
5255
"location": {
53-
"col": 56,
56+
"col": 1,
5457
"file": "policy.rego",
55-
"row": 7, "text": "\t# Long url: https://www.example.com/this/is/a/very/long",
58+
"row": 7,
59+
"text": "\t# Long url: https://www.example.com/this/is/a/very/long",
60+
"end": {"col": 56, "row": 7},
5661
},
5762
"related_resources": [{
5863
"description": "documentation",
@@ -73,10 +78,12 @@ test_fail_line_exceeds_120_characters_even_if_not_in_config if {
7378
"description": "Line too long",
7479
"level": "error",
7580
"location": {
76-
"col": 147,
81+
"col": 1,
7782
"file": "policy.rego",
83+
"row": 5,
7884
# regal ignore:line-length
79-
"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",
85+
"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",
86+
"end": {"col": 147, "row": 5},
8087
},
8188
"related_resources": [{
8289
"description": "documentation",

0 commit comments

Comments
 (0)
Please sign in to comment.