-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Add list of functions to skip in IgnoredReturnValue rule #4434
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice addition to this rule. I like it. Thanks for submitting!
Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ignoreAnnotated
at the caller side. - In the detekt configuration file, use a new option like
skipFunctions
in 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Suppressor
for both cases (issues in the definition and the call side)? - If we decide it should be in different
Suppressor
s 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
Lines 46 to 58 in ff7824d
@Configuration( | |
"List of fully qualified method signatures which are forbidden. " + | |
"Methods can be defined without full signature (i.e. `java.time.LocalDate.now`) which will report " + | |
"calls of all methods with this name or with full signature " + | |
"(i.e. `java.time.LocalDate(java.time.Clock)`) which would report only call " + | |
"with this concrete signature." | |
) | |
private val methods: List<FunctionMatcher> by config( | |
listOf( | |
"kotlin.io.print", | |
"kotlin.io.println", | |
) | |
) { it.map(FunctionMatcher::fromFunctionSignature) } |
@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 |
...ules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/IgnoredReturnValue.kt
Outdated
Show resolved
Hide resolved
…etekt/rules/bugs/IgnoredReturnValue.kt Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
Hey Detekt team, I was configuring
IgnoredReturnValue
rule 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
IgnoredReturnValue
rule 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.