Codacy: Imports should be sorted alphabetically

25 Sep

If you’re developing Scala apps and let them be checked by Codacy, you might have enabled the check “Imports should be sorted alphabetically“.
What sounds easy, isn’t in fact.

Here are my findings, summarised as example imports.

import import akka.Done // upper/lowercase doesn't matter import akka.streams.Source import java.util.ArrayList // this needs to be in the middle of the packages, most IDEs put it into an extra block import mycompany.mypackage._ // underscore is always before import mycompany.mypackage.mysubpackage.mysubsubpackage.A import mycompany.mypackage.{ClassA, ClassB, ClassC} import mycompany.otherpackage.SomeProtocol // space before dot import mycompany.otherpackage.SomeProtocol.{MessageA, MessageB} import org.slf4j.LoggerFactory import pureconfig._ // again, underscore before import pureconfig.generic.{ExportMacros, ProductHint} import scala.concurrent.{ExecutionContext, Future} import scala.collection.JavaConverters._ import import scala.util.{Failure, Success} // normal IDEs put all scala.* classes into an extra block at the end of all import statements import slick.basic.DatabaseConfig import slick.jdbc.JdbcProfile

I hope this helps someone.. I’m sure, I’ll check back on this page in about a week again….

Comment Form