Add list of functions to skip in IgnoredReturnValue rule#4434
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4434 +/- ##
============================================
- Coverage 84.32% 84.32% -0.01%
- Complexity 3288 3294 +6
============================================
Files 475 472 -3
Lines 10502 10525 +23
Branches 1882 1886 +4
============================================
+ Hits 8856 8875 +19
- Misses 670 671 +1
- Partials 976 979 +3
Continue to review full report at Codecov.
|
schalkms
left a comment
There was a problem hiding this comment.
This is a nice addition to this rule. I like it. Thanks for submitting!
|
Thanks :) |
There was a problem hiding this comment.
Thanks for providing a PR to address this issue. I will follow up on completing the docs, but we have ignoreAnnotated universal option added. This means that you probably don't necessarily need this PR (or wait for a new release) to work around this issue.
I am wondering if we should differentiate the two following scenarios:
- In the app code, apply
ignoreAnnotatedat the caller side. - In the detekt configuration file, use a new option like
skipFunctionsin this PR to ignore specific functions globally.
@BraisGabin what do you think?
|
@chao2zhang I don't think |
|
@artem-zinnatullin I think @chao2zhang meant the following comment in the changelog.
|
|
Good callout! I forgot about |
BraisGabin
left a comment
There was a problem hiding this comment.
I think that ignoreFunction would not work on this scenario. That Suppressor ignores justthe issues finded on the function declaration. Here the issue is thrown in the function call so I think that it would not work.
But I agree that this feature could be handled by a Suppressor so it could be used on any rule. But some open questions:
- Should we use the same
Suppressorfor both cases (issues in the definition and the call side)? - If we decide it should be in different
Suppressors how do we call this new one?ignoreFunctionCall? Naming is hard.
| "List of fully-qualified function names that should be skipped by this check. " + | ||
| "Example: 'package.class.fun1'" | ||
| ) | ||
| private val skipFunctions: List<String> by config(emptyList()) |
There was a problem hiding this comment.
I think that you should use FunctionMatcher. It provides more porwerful matching (you can match only by name or name + param types. Here a rule using it:
|
@BraisGabin spot on suggestion with a FunctionMatcher and naming! I was wondering on distinguishing function overloads, I've changed the code to use the matcher and renamed the property to Regarding the
I think it won't work, "inside a function with a given name" while I'm trying to ignore external function calls. |
|
@chao2zhang What do you think about this? It would be nice to have a |
…etekt/rules/bugs/IgnoredReturnValue.kt Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
Hey Detekt team, I was configuring
IgnoredReturnValuerule in our project and found it extremely useful — fixed few actual bugs!In fact, with this rule my old feature request filed to Kotlin team 6 years ago is now fulfilled heh https://youtrack.jetbrains.com/issue/KT-12719
However the rule does find quite a lot of false-positives that are outside of our or Detekt control.
Thus I'm proposing a configuration option for the
IgnoredReturnValuerule that will allow user to list fully qualified names of the functions return values of which they don't expect to be consumed — thus skipped by the rule.Examples:
In Ktor some routing DSL methods return values (idk why, seems like bad design, but oh well) and DSL doesn't rely on them to be used:
Or some stdlib functions like
use:and so on.