KT.IGNORED_RETURN_VALUE

Function, annotated with either @CheckReturnValue or @CheckResult returns value which is not used

This rule warns on instances where a function, annotated with either @CheckReturnValue or @CheckResult, returns a value but that value is not used in any way. The Kotlin compiler gives no warning for this scenario normally so that's the rationale behind this rule. fun returnsValue() = 42 fun returnsNoValue() {}

Noncompliant Code

Copy
returnsValue()

Compliant Code

Copy
if (42 == returnsValue()) {}
val x = returnsValue()

Options

  • restrictToAnnotatedMethods (default: True)

    if the rule should check only annotated methods

  • returnValueAnnotations (default: ['*.checkresult', '*.checkreturnvalue'])

    List of glob patterns to be used as inspection annotation

  • ignoreReturnValueAnnotations (default: ['*.canignorereturnvalue'])

    Annotations to skip this inspection

  • ignoreFunctionCall (default: [])

    List of function signatures which should be ignored by this rule. Specifying fully-qualified function signature with name only (i.e. java.time.LocalDate.now) will ignore all function calls matching the name. Specifying fully-qualified function signature with parameters (i.e. java.time.LocalDate.now(java.time.Clock)) will ignore only function calls matching the name and parameters exactly.

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html