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

Add GlobalCoroutineUsage rule + coroutines ruleset #2174

Merged
merged 15 commits into from
Jan 9, 2020
Merged

Add GlobalCoroutineUsage rule + coroutines ruleset #2174

merged 15 commits into from
Jan 9, 2020

Conversation

xouabita
Copy link
Contributor

@xouabita xouabita commented Dec 12, 2019

Closes #2155

@codecov-io
Copy link

codecov-io commented Dec 12, 2019

Codecov Report

Merging #2174 into master will decrease coverage by 0.03%.
The diff coverage is 92.3%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2174      +/-   ##
============================================
- Coverage     81.41%   81.37%   -0.04%     
- Complexity     2064     2073       +9     
============================================
  Files           340      343       +3     
  Lines          5934     5981      +47     
  Branches       1077     1086       +9     
============================================
+ Hits           4831     4867      +36     
- Misses          526      532       +6     
- Partials        577      582       +5
Impacted Files Coverage Δ Complexity Δ
...bosch/detekt/rules/providers/CoroutinesProvider.kt 100% <100%> (ø) 3 <3> (?)
...ch/detekt/rules/coroutines/GlobalCoroutineUsage.kt 88.88% <88.88%> (ø) 3 <3> (?)
.../io/gitlab/arturbosch/detekt/generator/out/Yaml.kt 58.62% <0%> (-6.77%) 0% <0%> (ø)
...arturbosch/detekt/generator/collection/KDocTags.kt 77.41% <0%> (-3.35%) 0% <0%> (ø)
...ch/detekt/api/internal/ValidatableConfiguration.kt 86.36% <0%> (-2.21%) 0% <0%> (ø)
.../io/gitlab/arturbosch/detekt/cli/runners/Runner.kt 86.95% <0%> (-1.94%) 10% <0%> (ø)
...gitlab/arturbosch/detekt/generator/out/Markdown.kt 20.68% <0%> (-0.74%) 4% <0%> (ø)
...rturbosch/detekt/rules/empty/EmptyFunctionBlock.kt 92.3% <0%> (ø) 12% <0%> (ø) ⬇️
...bosch/detekt/generator/collection/Configuration.kt 100% <0%> (ø) 5% <0%> (+1%) ⬆️
...h/detekt/rules/naming/MemberNameEqualsClassName.kt 88.46% <0%> (ø) 14% <0%> (ø) ⬇️
... and 9 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 01b6fe1...970165d. Read the comment docs.

@xouabita xouabita marked this pull request as ready for review December 12, 2019 11:27
Copy link
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this rule! I would make the rule more conservative as mentioned in my comment.

@xouabita xouabita changed the title Add GlobalScopeUsage rule + concurrency ruleset Add GlobalScopeUsage rule + coroutines ruleset Dec 16, 2019
@xouabita xouabita requested review from 3flex and schalkms December 16, 2019 15:49
@xouabita
Copy link
Contributor Author

I have changed the rule to only report GlobalScope.async and GlobalScope.launch. It also does not need type resolution anymore.
Let me know what do you think 🙂

import io.gitlab.arturbosch.detekt.api.RuleSetProvider
import io.gitlab.arturbosch.detekt.rules.coroutines.GlobalScopeUsage

/** The coroutines rule set analyzes code for potential coroutines problems.
Copy link
Member

Choose a reason for hiding this comment

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

Please move the documentation start to the next line.


/** The coroutines rule set analyzes code for potential coroutines problems.
*
* @active since v1.3.0
Copy link
Member

Choose a reason for hiding this comment

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

Please update this to 1.4.0

bar(GlobalScope)
}
"""
assertThat(subject.compileAndLint(code)).hasSize(0)
Copy link
Member

Choose a reason for hiding this comment

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

Please use isEmpty() instead of hasSize(0).

Copy link
Member

@arturbosch arturbosch left a comment

Choose a reason for hiding this comment

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

Looks good to go for 1.4.0. Thanks for the rule.
Please see my comments.

bar(scope)
}
"""
assertThat(subject.compileAndLint(code)).hasSize(0)
Copy link
Member

Choose a reason for hiding this comment

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

Please use isEmpty() instead of hasSize(0).

@arturbosch arturbosch added this to the 1.4.0 milestone Dec 28, 2019
@@ -133,8 +133,8 @@ artifacts {
}

detekt {
buildUponDefaultConfig = true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed because :detekt-gradle-plugin:detekt was failing.

* What went wrong:
Execution failed for task ':detekt-gradle-plugin:detekt'.
> Invalid detekt configuration file detected.
Property 'coroutines' is misspelled or does not exist.
io.gitlab.arturbosch.detekt.cli.InvalidConfig: Run failed with 1 invalid config property.

Copy link
Member

Choose a reason for hiding this comment

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

Blocked by #2217

Copy link
Member

Choose a reason for hiding this comment

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

If this issue is resolved, this line should be removed.

Copy link
Member

Choose a reason for hiding this comment

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

Submitted #2227 before I saw this - I think @xouabita has the correct solution, but we can discuss further in my PR. I don't see any other way to fix this while also enforcing validation of the config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome!

@schalkms schalkms added blocked and removed blocked labels Jan 2, 2020
@xouabita
Copy link
Contributor Author

xouabita commented Jan 7, 2020

I have rebased with #2227

@schalkms
Copy link
Member

schalkms commented Jan 7, 2020

Cool thanks! I’m waiting for @3flex final review to merge this PR.

Copy link
Member

@3flex 3flex left a comment

Choose a reason for hiding this comment

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

Just two comments, @schalkms let me know your thoughts, but I'm otherwise happy with this. Hopefully it will inspire some more rules focused on correct usage of coroutines!

  1. Original rule was called GlobalScopeUsage but scope is now limited to just flagging use of async and launch on GlobalScope. Is there a better name for the rule? Maybe GlobalCoroutine since the intention is to flag new coroutines with global scope?
  2. GlobalScope.broadcast and GlobalScope.produce also create new coroutines with global scope. I have no experience with these and the docs don't specifically discourage their use, any opinions on whether they should also be flagged? Easy to add later though but should do it now if anyone knows the answer.

@arturbosch
Copy link
Member

  1. How about GlobalCoroutineUsage then?
  2. I guess we can limit this for async and launch for now and when users start use this rule they will report if these two fucntions are also discouraged to use :)

@schalkms
Copy link
Member

schalkms commented Jan 8, 2020

GlobalCoroutineUsage

+1

I guess we can limit this for async and launch for now and when users start use this rule they will report if these two fucntions are also discouraged to use :)

Absolutely! This is a very good start! I’d really like to merge this. Extension can be made in the future if we see a need.

@xouabita
Copy link
Contributor Author

xouabita commented Jan 9, 2020

will rename to GlobalCoroutineUsage then

@xouabita xouabita changed the title Add GlobalScopeUsage rule + coroutines ruleset Add GlobalCoroutineUsage rule + coroutines ruleset Jan 9, 2020
@3flex 3flex merged commit 483131d into detekt:master Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule [GlobalScopeUsage] to disallow usage of GlobalScope
7 participants