-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add docs * fix tests --------- Co-authored-by: Joel Dickson <[email protected]>
- Loading branch information
1 parent
1e58819
commit 9d425f7
Showing
3 changed files
with
49 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# AG001: Ignored Return Value Rule | ||
|
||
This rule detects instances where return values from function calls | ||
are ignored, which can lead to potential bugs. | ||
|
||
## Description | ||
|
||
Ignoring return values often indicates that a function is being called | ||
solely for its side effects, which can be a code smell. This practice | ||
can result in: | ||
|
||
1. Wasted computation | ||
2. Missed error handling | ||
3. Unexpected behavior | ||
|
||
## Noncompliant Code Examples | ||
|
||
```kotlin | ||
toUppercase("hello") // Noncompliant: Return value is ignored | ||
getNumbers().filter { it > 2 } // Noncompliant: Return value is ignored | ||
userManager.login("user", "password") // Noncompliant: Return value is ignored | ||
``` | ||
|
||
## Compliant Code Examples | ||
|
||
```kotlin | ||
val uppercased = toUppercase("hello") | ||
val filteredNumbers = getNumbers().filter { it > 2 } | ||
val loginSuccessful = userManager.login("user", "password") | ||
``` | ||
|
||
## Exceptions | ||
|
||
The rule does not flag: | ||
- Functions returning `Unit` or `Nothing` | ||
- Cases where the return value is explicitly ignored using an underscore: | ||
|
||
```kotlin | ||
_ = toUppercase("hello") // Compliant: Explicitly ignored | ||
``` | ||
We recognise that sometimes you do want to ignore the return value, | ||
by making it explicit then we know its not a bug and it's intentional. |
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