Skip to content

Commit

Permalink
Use 120 characters as max line length if not configured (#473)
Browse files Browse the repository at this point in the history
Fixes #472

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert authored Nov 15, 2023
1 parent be7ed72 commit b36f696
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 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 @@ -11,13 +11,17 @@ import data.regal.result

cfg := config.for_rule("style", "line-length")

default max_line_length := 120

max_line_length := cfg["max-line-length"]

report contains violation if {
some i, line in input.regal.file.lines

line != ""

line_length := count(line)
line_length > cfg["max-line-length"]
line_length > max_line_length

not has_word_above_threshold(line, cfg)

Expand Down
26 changes: 25 additions & 1 deletion bundle/regal/rules/style/line_length_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,31 @@ test_fail_line_too_long_but_below_breakable_word_threshold if {
},
"related_resources": [{
"description": "documentation",
"ref": "https://docs.styra.com/regal/rules/style/line-length",
"ref": config.docs.resolve_url("$baseUrl/$category/line-length", "style"),
}],
"title": "line-length",
}}
}

test_fail_line_exceeds_120_characters_even_if_not_in_config if {
# regal ignore:line-length
r := rule.report with input as ast.with_future_keywords(`# 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
allow := true
`)
with config.for_rule as {"level": "error"}
r == {{
"category": "style",
"description": "Line too long",
"level": "error",
"location": {
"col": 147,
"file": "policy.rego",
# regal ignore:line-length
"row": 8, "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",
},
"related_resources": [{
"description": "documentation",
"ref": config.docs.resolve_url("$baseUrl/$category/line-length", "style"),
}],
"title": "line-length",
}}
Expand Down

0 comments on commit b36f696

Please sign in to comment.