forked from StyraInc/regal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rule:
missing-metadata
(StyraInc#1131)
This rule is not for everyone, and hence in the `custom` category. For a public projects, libraries and reusable policies, this should however be considered. This uncovered a [bug in OPA](open-policy-agent/opa#7050), which has now been addressed. In order to make progress on this we're now depending on OPA `main`. This should be changed as soon as OPA v0.69.0 is released. Some unrelated fixes in this PR, fixing annoyances as I worked on it: - add Regal specific attributes (`input.regal.*`) to the input created by the `eval:use-as-input` directive - Add another metadata snippet to allow creating a `# METADATA` block with only description and no title. Tbh, I'm still not sure what to use `title` for, while `description` is pretty much mandatory. - Set `ignore-if-sub-attribute: true` on default config for `prefer-some-in-iteration` rule. This was documented to be the case already, but seemed to have gone missing at some point. - Add pprof option to language-server command, and pprof handlers to web server Signed-off-by: Anders Eknert <anders@styra.com>
- Loading branch information
1 parent
f0a6bcf
commit 2dd7609
Showing
91 changed files
with
1,230 additions
and
436 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
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 |
---|---|---|
@@ -1,53 +1,61 @@ | ||
# METADATA | ||
# description: | | ||
# transforms OPA's JSON test coverage format to equivalent | ||
# simplecov JSON, to be used for Codecov reports, et. al. | ||
package build.simplecov | ||
|
||
import rego.v1 | ||
|
||
from_opa := {"coverage": coverage} | ||
# METADATA | ||
# entrypoint: true | ||
from_opa := {"coverage": _coverage} | ||
|
||
coverage[file] := {"lines": to_lines(report)} if some file, report in input.files | ||
_coverage[file] := {"lines": _to_lines(report)} if some file, report in input.files | ||
|
||
covered_map(report) := cm if { | ||
_covered_map(report) := cm if { | ||
covered := object.get(report, "covered", []) | ||
cm := {line: 1 | | ||
some item in covered | ||
some line in numbers.range(item.start.row, item.end.row) | ||
} | ||
} | ||
|
||
not_covered_map(report) := ncm if { | ||
_not_covered_map(report) := ncm if { | ||
not_covered := object.get(report, "not_covered", []) | ||
ncm := {line: 0 | | ||
some item in not_covered | ||
some line in numbers.range(item.start.row, item.end.row) | ||
} | ||
} | ||
|
||
to_lines(report) := lines if { | ||
cm := covered_map(report) | ||
ncm := not_covered_map(report) | ||
_to_lines(report) := lines if { | ||
cm := _covered_map(report) | ||
ncm := _not_covered_map(report) | ||
keys := sort([line | some line, _ in object.union(cm, ncm)]) | ||
last := keys[count(keys) - 1] | ||
|
||
lines := [value | | ||
some i in numbers.range(1, last) | ||
value := to_value(cm, ncm, i) | ||
value := _to_value(cm, ncm, i) | ||
] | ||
} | ||
|
||
to_value(cm, _, line) := 1 if cm[line] | ||
_to_value(cm, _, line) := 1 if cm[line] | ||
|
||
to_value(_, ncm, line) := 0 if ncm[line] | ||
_to_value(_, ncm, line) := 0 if ncm[line] | ||
|
||
to_value(cm, ncm, line) := null if { | ||
_to_value(cm, ncm, line) := null if { | ||
not cm[line] | ||
not ncm[line] | ||
} | ||
|
||
# utility rule to evaluate when only the | ||
# lines not covered are of interest | ||
# invoke like: | ||
# METADATA | ||
# description: | | ||
# utility rule to evaluate when only the lines not covered are of interest | ||
# invoke like: | ||
# regal test --coverage bundle \ | ||
# | opa eval -f pretty -I -d build/simplecov/simplecov.rego 'data.build.simplecov.not_covered' | ||
# entrypoint: true | ||
not_covered[file] := info.not_covered if { | ||
some file, info in input.files | ||
} |
12 changes: 10 additions & 2 deletions
12
...rkflows/update-example-index/process.rego → build/workflows/update_example_index.rego
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.