Skip to content

Commit 4ebdd7e

Browse files
authoredAug 12, 2024··
Add end location to non-raw-regex-pattern violations (#980)
This was another one that annoyed me recently, so fixed it :) Signed-off-by: Anders Eknert <anders@styra.com>
1 parent e886f35 commit 4ebdd7e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
 

‎bundle/regal/rules/idiomatic/non_raw_regex_pattern.rego

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ report contains violation if {
5858

5959
chr == `"`
6060

61-
violation := result.fail(rego.metadata.chain(), result.location(value[pos]))
61+
violation := result.fail(rego.metadata.chain(), result.ranged_location_from_text(value[pos]))
6262
}

‎bundle/regal/rules/idiomatic/non_raw_regex_pattern_test.rego

+21-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ test_fail_non_raw_rule_head if {
1515
"category": "idiomatic",
1616
"description": "Use raw strings for regex patterns",
1717
"level": "error",
18-
"location": {"col": 18, "file": "policy.rego", "row": 3, "text": "x := regex.match(\"[0-9]+\", \"1\")"},
18+
"location": {
19+
"col": 18,
20+
"file": "policy.rego",
21+
"row": 3,
22+
"text": "x := regex.match(\"[0-9]+\", \"1\")",
23+
"end": {"col": 26, "row": 3},
24+
},
1925
"related_resources": [{
2026
"description": "documentation",
2127
"ref": config.docs.resolve_url("$baseUrl/$category/non-raw-regex-pattern", "idiomatic"),
@@ -33,7 +39,13 @@ test_fail_non_raw_rule_body if {
3339
"category": "idiomatic",
3440
"description": "Use raw strings for regex patterns",
3541
"level": "error",
36-
"location": {"col": 18, "file": "policy.rego", "row": 4, "text": "\t\tregex.is_valid(\"[0-9]+\")"},
42+
"location": {
43+
"col": 18,
44+
"file": "policy.rego",
45+
"row": 4,
46+
"text": "\t\tregex.is_valid(\"[0-9]+\")",
47+
"end": {"col": 26, "row": 4},
48+
},
3749
"related_resources": [{
3850
"description": "documentation",
3951
"ref": config.docs.resolve_url("$baseUrl/$category/non-raw-regex-pattern", "idiomatic"),
@@ -49,7 +61,13 @@ test_fail_pattern_in_second_arg if {
4961
"category": "idiomatic",
5062
"description": "Use raw strings for regex patterns",
5163
"level": "error",
52-
"location": {"col": 25, "file": "policy.rego", "row": 3, "text": "r := regex.replace(\"a\", \"[a]\", \"b\")"},
64+
"location": {
65+
"col": 25,
66+
"file": "policy.rego",
67+
"row": 3,
68+
"text": "r := regex.replace(\"a\", \"[a]\", \"b\")",
69+
"end": {"col": 30, "row": 3},
70+
},
5371
"related_resources": [{
5472
"description": "documentation",
5573
"ref": config.docs.resolve_url("$baseUrl/$category/non-raw-regex-pattern", "idiomatic"),

0 commit comments

Comments
 (0)
Please sign in to comment.