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

Implement the rule to check if dispatchers are injectable #4222

Merged
merged 4 commits into from
Nov 15, 2021

Conversation

chao2zhang
Copy link
Member

This resolves #4175.

@codecov
Copy link

codecov bot commented Nov 1, 2021

Codecov Report

Merging #4222 (11a5a8c) into main (c848341) will increase coverage by 0.12%.
The diff coverage is 82.60%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #4222      +/-   ##
============================================
+ Coverage     84.19%   84.32%   +0.12%     
- Complexity     3233     3249      +16     
============================================
  Files           468      469       +1     
  Lines         10185    10186       +1     
  Branches       1786     1783       -3     
============================================
+ Hits           8575     8589      +14     
+ Misses          671      658      -13     
  Partials        939      939              
Impacted Files Coverage Δ
...rbosch/detekt/rules/coroutines/InjectDispatcher.kt 81.81% <81.81%> (ø)
...osch/detekt/rules/coroutines/CoroutinesProvider.kt 100.00% <100.00%> (ø)
...les/style/ExplicitCollectionElementAccessMethod.kt 68.96% <0.00%> (-14.37%) ⬇️
...rbosch/detekt/rules/style/ObjectLiteralToLambda.kt 83.78% <0.00%> (-3.40%) ⬇️
...turbosch/detekt/rules/style/ForbiddenMethodCall.kt 87.80% <0.00%> (-3.31%) ⬇️
.../io/gitlab/arturbosch/detekt/rules/style/NoTabs.kt 92.30% <0.00%> (-2.43%) ⬇️
...detekt/rules/bugs/DoubleMutabilityForCollection.kt 85.18% <0.00%> (-0.53%) ⬇️
.../kotlin/io/gitlab/arturbosch/detekt/cli/CliArgs.kt 100.00% <0.00%> (ø)
...ain/kotlin/io/github/detekt/metrics/LinesOfCode.kt 95.45% <0.00%> (ø)
...rturbosch/detekt/rules/style/UnusedPrivateClass.kt 76.59% <0.00%> (ø)
... and 14 more

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 c848341...11a5a8c. Read the comment docs.

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Great stuff :)

@cortinico cortinico added this to the 1.19.0 milestone Nov 1, 2021
@cortinico cortinico added the rules label Nov 1, 2021
…etekt/rules/coroutines/InjectDispatcher.kt

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
dispatcherNames:
- 'IO'
- 'Default'
- 'Unconfined'
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the use case to allow to configure this? Shouldn't we just check all the usages of Dispatchers.*? If this is because you can change the Main and the Immediate maybe a boolean flag (disable by default) could be a better fit for discoberavility.

Copy link
Member Author

Choose a reason for hiding this comment

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

Dispatchers.Main is generally okay because we have Dispatchers.setMain()/resetMain() available in test (https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/)

Additionally, if users define their own Dispatchers, this list is necessary for specifying their customized dispatcherNames.

Copy link
Member

Choose a reason for hiding this comment

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

Dispatchers.Main is generally okay because we have Dispatchers.setMain()/resetMain()

It's possible to change them, but I think that adding Main is a safer default. If someone is OK using those function it can remove it. This kind of test functions aren't very good. If you forget to use resetMain you can change the behaviour of other tests.

For example JodaTime had DateTimeUtils.setCurrentMillisFixed but it was removed in java.time. Now you are forced to inject a Clock if you want to test it. I think that we should add Main but default for the same reason.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I don't completely agree but we could move this to an issue. There's no need to block the merging for this.

@BraisGabin BraisGabin merged commit 61166d9 into detekt:main Nov 15, 2021
@cortinico cortinico added the notable changes Marker for notable changes in the changelog label Nov 15, 2021
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 rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule: Always inject dispatchers
3 participants