-
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.
Fixes #297 Signed-off-by: Anders Eknert <[email protected]>
- Loading branch information
1 parent
21a0dc4
commit c3d3fe0
Showing
7 changed files
with
66 additions
and
63 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
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,54 @@ | ||
# unassigned-return-value | ||
|
||
**Summary**: Non-boolean return value unassigned | ||
|
||
**Category**: Bugs | ||
|
||
**Avoid** | ||
```rego | ||
package policy | ||
import rego.v1 | ||
allow if { | ||
# return value not assigned | ||
lower(input.user.name) | ||
# ... | ||
} | ||
``` | ||
|
||
**Prefer** | ||
```rego | ||
package policy | ||
allow if { | ||
# return value assigned | ||
name_lower := lower(input.user.name) | ||
# ... | ||
} | ||
``` | ||
|
||
## Rationale | ||
|
||
Calling a built-in function that returns a non-boolean value without actually assigning the returned value is almost | ||
always a mistake. Only return of `false` or undefined will cause evaluation to halt, so a function that e.g. always | ||
returns a string will always be evaluated as "truthy". But more importantly — not handling the return value in that case | ||
is almost certainly a mistake. | ||
|
||
## Configuration Options | ||
|
||
This linter rule provides the following configuration options: | ||
|
||
```yaml | ||
rules: | ||
bugs: | ||
unassigned-return-value: | ||
# one of "error", "warning", "ignore" | ||
level: error | ||
``` | ||
## Community | ||
If you think you've found a problem with this rule or its documentation, would like to suggest improvements, new rules, | ||
or just talk about Regal in general, please join us in the `#regal` channel in the Styra Community | ||
[Slack](https://communityinviter.com/apps/styracommunity/signup)! |
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,54 +1,5 @@ | ||
# unused-return-value | ||
|
||
**Summary**: Non-boolean return value unused | ||
## Please Note | ||
|
||
**Category**: Bugs | ||
|
||
**Avoid** | ||
```rego | ||
package policy | ||
import rego.v1 | ||
allow if { | ||
# return value unused | ||
lower(input.user.name) | ||
# ... | ||
} | ||
``` | ||
|
||
**Prefer** | ||
```rego | ||
package policy | ||
allow if { | ||
# return value assigned | ||
name_lower := lower(input.user.name) | ||
# ... | ||
} | ||
``` | ||
|
||
## Rationale | ||
|
||
Calling a built-in function that returns a non-boolean value without actually *using* the returned value is almost | ||
always a mistake. Only return of `false` or undefined will cause evaluation to halt, so a function that e.g. always | ||
returns a string will always be evaluated as "truthy". But more importantly — not handling the return value in that case | ||
is almost certainly a mistake. | ||
|
||
## Configuration Options | ||
|
||
This linter rule provides the following configuration options: | ||
|
||
```yaml | ||
rules: | ||
bugs: | ||
unused-return-value: | ||
# one of "error", "warning", "ignore" | ||
level: error | ||
``` | ||
## Community | ||
If you think you've found a problem with this rule or its documentation, would like to suggest improvements, new rules, | ||
or just talk about Regal in general, please join us in the `#regal` channel in the Styra Community | ||
[Slack](https://communityinviter.com/apps/styracommunity/signup)! | ||
This rule has been renamed to *unassigned-return-value* and can be found [here](../unassigned-return-value.md). |
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