TypelevelAs should add `cats.syntax` import
Version 0.1.5
import cats.effect.Resource
val foo: Resource[A, B] = ???
val x = foo.map(_ => ())
The rule TypelevelAs.as will complain and suggest to rewrite the map line to .void.
Resource does not have a void method :)
The check should probably be limited to types that provide the necessary functions.
It does, if you do import cats.syntax.all._ :) I think there's a way for scalafix to add imports if necessary.
Oh, that is possible. I wonder if there is a good way to make that part of the message in such a situation maybe?
My actual issue turned out to be that I had multiple Functor instances (from Temporal and Sync) and the void syntax could not decide which one to pick :)
Here's how an http4s scalafix adds an import if needed. https://github.com/typelevel/typelevel-scalafix/blob/8e246387dbed1e772933d2f757bc7609bc909861/modules/http4s/rules/src/main/scala/org/typelevel/fix/Http4sLiteralsSyntax.scala#L41-L43
Let's close this issue because there is no issue :)
Actually there is an issue, the import is not being added :)
Right but you'd have to make the rule a lot more specific then, would you not?
What would happen to a foo.map(_ => ()) where foo does not have a void in cats.syntax?
Good point. So even after adding the import, this Scalafix could still be suggesting broken code. Seems to me like another reason to keep it open.
👍 I agree with that. This almost needs something like "do we have an implicit Functor? OK, just add the syntax" and otherwise bail out.
The (WIP) port of the RemoveInstancesImport rule does something similar to that actually: https://github.com/typelevel/typelevel-scalafix/pull/31/files#diff-b2f050feb2124095e5835138e89f5f116e4781fc5aeb560ea4415dcf7f17f926R46