Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IgnoredReturnValue] Add returnType?.isNothing() check #7772

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atulgpt
Copy link
Contributor

@atulgpt atulgpt commented Nov 9, 2024

Fixes #7765

@detekt-ci detekt-ci added the rules label Nov 9, 2024
@atulgpt atulgpt changed the title Add returnType?.isNothing() check [IgnoredReturnValue] Add returnType?.isNothing() check Nov 9, 2024
Copy link

codecov bot commented Nov 9, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.43%. Comparing base (754b4b6) to head (4c9189c).

Files with missing lines Patch % Lines
...arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7772      +/-   ##
============================================
- Coverage     85.44%   85.43%   -0.01%     
- Complexity     4175     4177       +2     
============================================
  Files           571      571              
  Lines         13136    13137       +1     
  Branches       2489     2490       +1     
============================================
  Hits          11224    11224              
  Misses          664      664              
- Partials       1248     1249       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x"D I was just reviewing the issue and saw "oh there is a PR already". I enter and it was just 1 minute old :P

Thanks for all the contributions (I know that you have more things that need my review but I have not the time :'( )

Comment on lines +1061 to +1069
fun `does not report when a function returns Unit`() {
val code = """
fun foo() {
println(42)
}
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings).isEmpty()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we have a test for this case? Good catch then!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could only find Unit involving with chain

Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this issue!
I’d also like to have an explicit test case for Nothing, e.g.

fun fail(message: String): Nothing {
    //
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IgnoredReturnValue should not flag ignored Nothing
4 participants