Did you ever see a Scala compiler error such as:
[error] TheNextFacebook.scala:16: type mismatch; [error] found : akka.http.scaladsl.server.StandardRoute [error] required: akka.stream.scaladsl.Flow[akka.http.scaladsl.model.HttpRequest,akka.http.scaladsl.model.HttpResponse,Any] [error] Http().bindAndHandle(r, "localhost", 8080)
and had no idea what to do next? Well in this case, you need to provide an implicit instance of an
but the compiler isn't smart enough to be able to tell you that. Luckily, Scala Clippy is here to help!
Just add the Scala Clippy compiler plugin, and you'll see this additional helpful message:
[error] Clippy advises: did you forget to define an implicit akka.stream.ActorMaterializer? [error] It allows routes to be converted into a flow. [error] You can read more at http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0/scala/http/routing-dsl/index.html
The easiest to use Clippy is via an SBT plugin. If you'd like Clippy to be enabled for all projects, without
the need to modify each project's build, add the following to
addSbtPlugin("com.softwaremill.clippy" % "plugin-sbt" % "0.5.2")
Upon first use, the plugin will download the advice dataset from
https://scala-clippy.org and store it in the
$HOME/.clippy directory. The dataset will be updated at most once a day, in the background. You can customize the
dataset URL and local store by setting the
clippyLocalStoreDir sbt options to non-
Note: to customize a global sbt plugin (a plugin which is added via `~/.sbt/0.13/plugins/build.sbt`) keep in mind that:
~/.sbt/0.13/build.sbt(one directory up!). These settings will be automatically added to all of your projects.
import com.softwaremill.clippy.ClippySbtPlugin._to access the setting names as auto-imports don't work in the global settings
scalacOptions += "-P:clippy:colors=true")
Clippy can highlight:
If you'd like to enable this feature in sbt globally, add the following to `~/.sbt/0.13/build.sbt`: (see also notes above)
import com.softwaremill.clippy.ClippySbtPlugin._ // needed in global configuration only clippyColorsEnabled := true
To customize the colors, set any of `clippyColorDiff`, `clippyColorComment`, `clippyColorType`, `clippyColorLiteral`, `clippyColorKeyword` to `Some(ClippyColor.[name])`, where `[name]` can be: `Black`, `Red`, `Green`, `Yellow`, `Blue`, `Magenta`, `Cyan`, `White` or `None`.
You can of course add clippy on a per-project basis as well.
Help others users by submitting an advice for a compilation error that you have encountered! Just click "contribute" above and paste in your error!
Speaking of GitHub, you are also welcome to check out (and improve!) the plugin's & website's source code.
If you have advice that you feel is too specific to be worth sharing on global database, you can add it to your project specific advice file. Just create a file named .clippy.json in the root of your project directory. See clippy README for an example.
You can also use Clippy directly as a compiler plugin. If you use SBT, add the following setting to your
addCompilerPlugin("com.softwaremill.clippy" %% "plugin" % "0.5.2" classifier "bundle")
If you are using
scalac directly, add the following option:
See clippy README for more details.