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 Lint rules warning against accessing the Dispatchers object or creating CoroutineScope without a DispatcherProvider #21

Open
RBusarow opened this issue Jan 20, 2020 · 0 comments
Labels
lint We need to be create a Lint rule

Comments

@RBusarow
Copy link
Owner

Any access to the Dispatchers object breaks tests. This happens if we create a CoroutineScope without giving it a DispatcherProvider, or if we hard-code stuff like this:

class SomeClass {

  // We can still use `.dispatcherProvider` with this coroutineScope,
  // but it always returns a default implementation
  val coroutineScope = CoroutineScope(Job() + Dispatchers.Main)

  // This obviously accesses a hard-coded dispatcher
  fun foo() = coroutineScope.launch(Dispatchers.Default) { ... }
}

This is relatively easy to catch with Lint rules, but adding that rule to the main artifact will immediately create a warning for any code which has not been refactored.

Open Items

  • Should a Lint rule go into its own artifact, effectively allowing the user to opt in by adding the dependency? Or should it just be published as part of the core artifact?
@RBusarow RBusarow added the lint We need to be create a Lint rule label Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint We need to be create a Lint rule
Projects
None yet
Development

No branches or pull requests

1 participant