-
-
Notifications
You must be signed in to change notification settings - Fork 784
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
Conversation
Codecov Report
@@ 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
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.
Thanks for contributing this rule! I would make the rule more conservative as mentioned in my comment.
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/concurrency/GlobalScopeUsage.kt
Outdated
Show resolved
Hide resolved
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/concurrency/GlobalScopeUsage.kt
Outdated
Show resolved
Hide resolved
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/concurrency/GlobalScopeUsage.kt
Outdated
Show resolved
Hide resolved
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/concurrency/GlobalScopeUsage.kt
Outdated
Show resolved
Hide resolved
I have changed the rule to only report |
detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/coroutines/GlobalScopeUsage.kt
Outdated
Show resolved
Hide resolved
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. |
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.
Please move the documentation start to the next line.
|
||
/** The coroutines rule set analyzes code for potential coroutines problems. | ||
* | ||
* @active since v1.3.0 |
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.
Please update this to 1.4.0
bar(GlobalScope) | ||
} | ||
""" | ||
assertThat(subject.compileAndLint(code)).hasSize(0) |
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.
Please use isEmpty()
instead of hasSize(0)
.
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.
Looks good to go for 1.4.0. Thanks for the rule.
Please see my comments.
bar(scope) | ||
} | ||
""" | ||
assertThat(subject.compileAndLint(code)).hasSize(0) |
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.
Please use isEmpty()
instead of hasSize(0)
.
@@ -133,8 +133,8 @@ artifacts { | |||
} | |||
|
|||
detekt { | |||
buildUponDefaultConfig = true |
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 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.
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.
Blocked by #2217
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.
If this issue is resolved, this line should be removed.
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.
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.
Awesome!
I have rebased with #2227 |
Cool thanks! I’m waiting for @3flex final review to merge this PR. |
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.
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!
- Original rule was called
GlobalScopeUsage
but scope is now limited to just flagging use ofasync
andlaunch
onGlobalScope
. Is there a better name for the rule? MaybeGlobalCoroutine
since the intention is to flag new coroutines with global scope? GlobalScope.broadcast
andGlobalScope.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.
|
+1
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. |
will rename to |
GlobalScopeUsage
rule which reports use ofGlobalScope
.See Add rule [GlobalScopeUsage] to disallow usage of GlobalScope #2155 for more context
concurrency
rule setoptionalPaths
in create environmentcoroutines
as a test dependency to have coroutine types in the testCloses #2155