Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BraisGabin
Copy link
Member

In nearlly all our tests we use TestConfig(Map<String, Any>). This make us write code like this:

val rule = TooManyFunctions(
    TestConfig(
        mapOf(
            THRESHOLD_IN_CLASSES to "1",
            THRESHOLD_IN_FILES to "1",
            IGNORE_OVERRIDDEN to "false"
        )
    )
)

The mapOf provide us really little value there and only increase the verbosity. I changed all our test to use TestConfig(vararg Pair<String, Any>) it does exactly the same but the code is a bit easier:

val rule = TooManyFunctions(
    TestConfig(
        THRESHOLD_IN_CLASSES to "1",
        THRESHOLD_IN_FILES to "1",
        IGNORE_OVERRIDDEN to "false",
    )
)

I also deprecated the old version to promote this new one. I can't remove it because it is part of our public API.

@codecov
Copy link

codecov bot commented Feb 21, 2023

Codecov Report

Merging #5801 (5bc0ad4) into main (79eaed6) will increase coverage by 0.00%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##               main    #5801   +/-   ##
=========================================
  Coverage     84.59%   84.60%           
- Complexity     3789     3790    +1     
=========================================
  Files           546      546           
  Lines         12918    12918           
  Branches       2268     2268           
=========================================
+ Hits          10928    10929    +1     
+ Misses          862      861    -1     
  Partials       1128     1128           
Impacted Files Coverage Δ
...turbosch/detekt/rules/style/ForbiddenAnnotation.kt 90.24% <0.00%> (+2.43%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@TWiStErRob TWiStErRob left a comment

Choose a reason for hiding this comment

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

Really nice one! Pushed a small commit (it was easier to fix them than to call them out on GitHub)

Some questions as conversations, please review them.


companion object {
@Suppress("DEPRECATION")
operator fun invoke(vararg pairs: Pair<String, Any>) = TestConfig(mapOf(*pairs))
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this to be a constructor? and deprecate the invoke too?

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷 I don't know what benefits would provide us that. But I think that could be done in a different PR.

Copy link
Member

Choose a reason for hiding this comment

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

Just thinking about the future, since the map constructor is deprecated now, I would imagine it will be hidden eventually, which means that there won't be a way to construct TestConfig directly, only through the factory method in the companion object, which is strange considering the same could could be just a constructor. Since the constructor gets deprecated now, I think maybe it would be good to deprecated the companion invoke as well, and create a constructor with the same signature. Ideally the overload resolution would just pick the new constructor and give us source compatibility and keeping the invoke method as a deprecated one would give us binary compatibility for public users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants