-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Well, with the help of a new built-in function, anyway. This allows us to ditch the system for Go-based rules entirely, which feels like a big step for this project! Fixes #1298 Signed-off-by: Anders Eknert <[email protected]>
- Loading branch information
1 parent
a283bee
commit 9c13fa3
Showing
21 changed files
with
218 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# METADATA | ||
# description: File should be formatted with `opa fmt` | ||
package regal.rules.style["opa-fmt"] | ||
|
||
import data.regal.result | ||
|
||
report contains violation if { | ||
# NOTE: | ||
# 1. this won't identify CRLF line endings, as we've stripped them from the input previously | ||
# 2. this will perform worse than having the text representation of the file in the input | ||
not regal.is_formatted(concat("\n", input.regal.file.lines), {"rego_version": input.regal.file.rego_version}) | ||
|
||
violation := result.fail(rego.metadata.chain(), {"location": { | ||
"file": input.regal.file.name, | ||
"row": 1, | ||
"col": 1, | ||
"text": input.regal.file.lines[0], | ||
}}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package regal.rules.style["opa-fmt_test"] | ||
|
||
import data.regal.config | ||
import data.regal.rules.style["opa-fmt"] as rule | ||
|
||
test_fail_not_formatted if { | ||
r := rule.report with input as regal.parse_module("p.rego", `package p `) | ||
with input.regal.file.rego_version as "v1" | ||
|
||
r == {{ | ||
"category": "style", | ||
"description": "File should be formatted with `opa fmt`", | ||
"level": "error", | ||
"location": { | ||
"col": 1, | ||
"file": "p.rego", | ||
"row": 1, | ||
"text": "package p ", | ||
}, | ||
"related_resources": [{ | ||
"description": "documentation", | ||
"ref": config.docs.resolve_url("$baseUrl/$category/opa-fmt", "style"), | ||
}], | ||
"title": "opa-fmt", | ||
}} | ||
} | ||
|
||
test_success_formatted if { | ||
r := rule.report with input as regal.parse_module("p.rego", "package p\n") | ||
with input.regal.file.rego_version as "v1" | ||
|
||
r == set() | ||
} | ||
|
||
test_fail_v0_required_but_v1_policy if { | ||
r := rule.report with input as regal.parse_module("p.rego", "package p\n\none contains 1\n") | ||
with input.regal.file.rego_version as "v0" | ||
|
||
r == {{ | ||
"category": "style", | ||
"description": "File should be formatted with `opa fmt`", | ||
"level": "error", | ||
"location": { | ||
"col": 1, | ||
"file": "p.rego", | ||
"row": 1, | ||
"text": "package p", | ||
}, | ||
"related_resources": [{ | ||
"description": "documentation", | ||
"ref": config.docs.resolve_url("$baseUrl/$category/opa-fmt", "style"), | ||
}], | ||
"title": "opa-fmt", | ||
}} | ||
} | ||
|
||
test_success_v0_required_and_v0_policy if { | ||
r := rule.report with input as regal.parse_module("p_v0.rego", "package p\n\none[\"1\"]\n") | ||
with input.regal.file.rego_version as "v0" | ||
|
||
r == set() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.