* Update Regal documentation Sync documentation with upstream Regal repository to reflect latest changes. This addresses a number of broken link issues from the checker before. Signed-off-by: Charlie Egan <charlie_egan@apple.com> * docs: Update release links these links create some issues in the link checker report. https://github.com/open-policy-agent/opa/issues/8278 ``` Errors in ./docs/docs/deploy/aws/ec2.mdx [404] https://github.com/open-policy-agent/opa/releases/download/v%7B%7Bversion%7D%7D/opa_linux_amd64 | Rejected status code (this depends on your "accept" configuration): Not Found Errors in ./docs/docs/deploy/azure/vm.mdx [404] https://github.com/open-policy-agent/opa/releases/download/v%7B%7Bversion%7D%7D/opa_linux_amd64 | Error (cached) Errors in ./docs/docs/deploy/google-cloud/gce.mdx [404] https://github.com/open-policy-agent/opa/releases/download/v%7B%7Bversion%7D%7D/opa_linux_amd64 | Error (cached) ``` These are not actually broken, they are just untemplated when the checker sees them. I figured since they are long lines we can use use a $REPO variable instead, to ensure that we only have valid https:// starting links on those pages. Signed-off-by: Charlie Egan <charlie_egan@apple.com> * Remove broken blog link https://github.com/open-policy-agent/opa/issues/8278 this link appears to be gone with no redirect. Signed-off-by: Charlie Egan <charlie_egan@apple.com> * docs: Fix outdated and broken documentation URLs Update various documentation links, SlideShare links, and external references that were resulting in redirects. Fixes https://github.com/open-policy-agent/opa/issues/8278 Signed-off-by: Charlie Egan <charlie_egan@apple.com> * Update broken regal links The other rules are using abs links here. Signed-off-by: Charlie Egan <charlie_egan@apple.com> --------- Signed-off-by: Charlie Egan <charlie_egan@apple.com>
2.1 KiB
redundant-existence-check
Summary: Redundant existence check
Category: Bugs
Automatically fixable: Yes
Avoid
package policy
employee if {
input.user.email
endswith(input.user.email, "@acmecorp.com")
}
is_admin(user) if {
user
"admin" in user.roles
}
Prefer
package policy
employee if {
endswith(input.user.email, "@acmecorp.com")
}
# alternatively
employee if endswith(input.user.email, "@acmecorp.com")
is_admin(user) if {
"admin" in user.roles
}
Rationale
Checking that a reference (like input.user.email) is defined before immediately using it is redundant. If the
reference is undefined, the next expression will fail anyway, as the value will be checked before the rest of the
expression is evaluated. While an extra check doesn't "hurt", it also serves no purpose, similarly to an unused
variable.
Note: This rule only applies to references that are immediately used in the next expression. If the reference is
used later in the rule, it won't be flagged. While the existence check could be redundant even in that case, it could
also be used to avoid making some expensive computation, an http.send call, or whatnot.
Exceptions
Function arguments where a boolean value is expected will be flagged as redundant existence checks, even though the intent was to check the boolean condition.
report(user, is_admin) if {
is_admin
# more conditions
}
For these cases, prefer to be explicit about what the assertion is checking:
report(user, is_admin) if {
is_admin == false # or true, != false, etc.
# more conditions
}
Configuration Options
This linter rule provides the following configuration options:
rules:
bugs:
redundant-existence-check:
# one of "error", "warning", "ignore"
level: error
Related Resources
- GitHub: Source Code