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

Function generics matcher #4460

Merged
merged 2 commits into from
Mar 31, 2022
Merged

Function generics matcher #4460

merged 2 commits into from
Mar 31, 2022

Conversation

BraisGabin
Copy link
Member

Match generic names in signature functions.

Now ForbiddenMethod call allows to forbid kotlin.runCatching {} but allowing runCatching {}.

closes #4448

@BraisGabin BraisGabin added this to the 1.20.0 milestone Jan 6, 2022
@codecov
Copy link

codecov bot commented Jan 6, 2022

Codecov Report

Merging #4460 (568c2a4) into main (d7ac501) will increase coverage by 0.00%.
The diff coverage is 62.50%.

@@            Coverage Diff            @@
##               main    #4460   +/-   ##
=========================================
  Coverage     84.55%   84.56%           
  Complexity     3397     3397           
=========================================
  Files           484      484           
  Lines         11272    11276    +4     
  Branches       2059     2060    +1     
=========================================
+ Hits           9531     9535    +4     
  Misses          698      698           
  Partials       1043     1043           
Impacted Files Coverage Δ
...in/io/github/detekt/tooling/api/FunctionMatcher.kt 87.50% <62.50%> (+0.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7ac501...568c2a4. Read the comment docs.

@@ -33,11 +35,12 @@ sealed class FunctionMatcher {
private val parameters: List<String>
) : FunctionMatcher() {
override fun match(callableDescriptor: CallableDescriptor): Boolean {
if (callableDescriptor.fqNameOrNull()?.asString() != fullyQualifiedName) return false
val descriptor = callableDescriptor.original
Copy link
Member

Choose a reason for hiding this comment

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

Q: What is .original doing here? Why is it needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

That get's the function definition instead of the function call. If I request the type of the parameter of list("hello") it will say String but if I ask for the type of the original I get T.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha 👍 Thanks for clarifying

@cortinico cortinico removed this from the 1.20.0 milestone Mar 23, 2022
Base automatically changed from function-extension-matcher to main March 24, 2022 07:54
@BraisGabin BraisGabin marked this pull request as ready for review March 24, 2022 07:55
@BraisGabin
Copy link
Member Author

I would like to merge this one in 1.20 too if possible. This PR was waiting for #4459 to be merged because it depends on that code.

@cortinico cortinico added this to the 1.20.0 milestone Mar 24, 2022
@cortinico cortinico added the notable changes Marker for notable changes in the changelog label Mar 24, 2022
@cortinico
Copy link
Member

I'm fine adding this, but we need some follow-up docs for this to the website

@BraisGabin
Copy link
Member Author

🤔 I don't think we need to add new documentation here. The current documentation matchs what this matcher does. This one is more a "bug-fix" than a new feature. I mean, for sure it is a new feature but for a user it could seems like the same. The PR that introduced real changes was #4459 and I added the documentation directly in it. https://github.com/detekt/detekt/pull/4459/files#diff-76703cf8efe31f0c7e06926568e0d1e248eb82cb63bd40b0b37698dc35bed70fR52

@BraisGabin BraisGabin merged commit e052dbe into main Mar 31, 2022
@BraisGabin BraisGabin deleted the function-generics-matcher branch March 31, 2022 06:48
chao2zhang pushed a commit that referenced this pull request Apr 8, 2022
* Match functions with generics

* Add test to ensure that #4448 is fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notable changes Marker for notable changes in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule to use runCatching instead of kotlin.runCatching
2 participants