scalaintellij-ideaimportscala-implicits

Best way to handle false unused imports in intellij


Intellij falsely marked some import of Scala implicits as not being use. Is there a way to prevent it from deleting those import when optimized them explicitly for a specific import and not prevent optimized import for the entire project ?


Solution

  • I'm afraid there isn't, I had similar issues especially when using akka and importing the implicit execution context from an ActorSystem in some cases. I recommend defining the value instead of importing. One such example would be:

    // Avoid importing the execution context like this
    class MyActor extends Actor {
      import context.system.dispatcher
    }
    
    // Define it explicitly instead
    class MyActor extends Actor {
      implicit val ec = context.system.dispatcher
    }
    

    I hope this helps you.