Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add end location to non-raw-regex-pattern violations #980

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundle/regal/rules/idiomatic/non_raw_regex_pattern.rego
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ report contains violation if {

chr == `"`

violation := result.fail(rego.metadata.chain(), result.location(value[pos]))
violation := result.fail(rego.metadata.chain(), result.ranged_location_from_text(value[pos]))
}
24 changes: 21 additions & 3 deletions bundle/regal/rules/idiomatic/non_raw_regex_pattern_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ test_fail_non_raw_rule_head if {
"category": "idiomatic",
"description": "Use raw strings for regex patterns",
"level": "error",
"location": {"col": 18, "file": "policy.rego", "row": 3, "text": "x := regex.match(\"[0-9]+\", \"1\")"},
"location": {
"col": 18,
"file": "policy.rego",
"row": 3,
"text": "x := regex.match(\"[0-9]+\", \"1\")",
"end": {"col": 26, "row": 3},
},
"related_resources": [{
"description": "documentation",
"ref": config.docs.resolve_url("$baseUrl/$category/non-raw-regex-pattern", "idiomatic"),
Expand All @@ -33,7 +39,13 @@ test_fail_non_raw_rule_body if {
"category": "idiomatic",
"description": "Use raw strings for regex patterns",
"level": "error",
"location": {"col": 18, "file": "policy.rego", "row": 4, "text": "\t\tregex.is_valid(\"[0-9]+\")"},
"location": {
"col": 18,
"file": "policy.rego",
"row": 4,
"text": "\t\tregex.is_valid(\"[0-9]+\")",
"end": {"col": 26, "row": 4},
},
"related_resources": [{
"description": "documentation",
"ref": config.docs.resolve_url("$baseUrl/$category/non-raw-regex-pattern", "idiomatic"),
Expand All @@ -49,7 +61,13 @@ test_fail_pattern_in_second_arg if {
"category": "idiomatic",
"description": "Use raw strings for regex patterns",
"level": "error",
"location": {"col": 25, "file": "policy.rego", "row": 3, "text": "r := regex.replace(\"a\", \"[a]\", \"b\")"},
"location": {
"col": 25,
"file": "policy.rego",
"row": 3,
"text": "r := regex.replace(\"a\", \"[a]\", \"b\")",
"end": {"col": 30, "row": 3},
},
"related_resources": [{
"description": "documentation",
"ref": config.docs.resolve_url("$baseUrl/$category/non-raw-regex-pattern", "idiomatic"),
Expand Down