Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?
Edsger Dijkstra
Plugins provides customization to an existing implementations of your code. Some of the main reasons to include plugins in your code include :-
- To support adding new features
- To reduce size of an application
- Ease developers in refactoring their code base
- To enable third party developers to create abilities which extend an application
In this blog post I will cover few plugins that can be used to introduce new features and enhance quality of your code.
1. WartRemover
WartRemover as the name suggests is used to remove undesirable features in your application. Its main goal is to help you write safe and correct software without having to constantly double-check yourself.
For example – In all those scenario’s where your statements are returning non unit, wart remover will be giving warnings like below statement :-
[warn] /tmp/src/main/scala/test/Foo.scala:2: [wartremover:NonUnitStatements] Statements must return Unit
Solution :-
val _ = someMethodCall(someArgument)
To check complete list of warts visit documentation.
How to include WartRemover in your Scala Project
addCompilerPlugin("org.wartremover" %% "wartremover" % "2.4.1")
Include above dependency to Plugins.sbt
wartremoverWarnings ++= Warts.all
Include above dependency in settings of your build.
2. Scala-Clippy
Scala Clippy is a compiler plugin which, when there’s a compiler error, checks it against the errors it knows about. If there’s a match, an additional error message (the advice) is printed to the user. It enriches your Scala compiler error output with additional advice and colors.
[error] Clippy advises: flat[M]ap is case sensitive
[error] getData(id).flatmap {
Integrating Scala-Clippy
addSbtPlugin(“com.softwaremill.clippy” % “plugin-sbt” % “0.6.1”
Enter sbt clean compile to test.
3. sbt-errors-summary
Here’s a summary from its author :-
“A simple plugin that makes the error reporter a bit more concise. I find it useful when doing refactoring: I get a lot of compilation errors, and I waste a lot of time switching between files and looking for line numbers in the error message, when I can immediately see what’s wrong when looking at the faulty line.”
4. Coursier
Coursier is a dependency resolver / fetcher written in scala. It aims at being fast and easy to embed in other contexts. It is able to fetch metadata and artifacts from both Maven and Ivy repositories. It handles parallel downloads out-of-the-box without resorting to global locks. It ensures one’s dependencies are fetched via coursier rather than by sbt itself.It can be used as an sbt-plugin, handling dependency resolutions in sbt.
5. sbt-stats
An sbt (Simple Build Tool) plugin provides source code statistics and analytics in the sbt console. It gives you the statistics like: total no. of files, Scala files, Java files, total size(in bytes), total no. of lines, characters, comments, blanks, brackets, etc.
Enter Stats command in SBT console.
References :-
- https://get-coursier.io/docs/overview
- https://www.wartremover.org/
- https://www.scala-sbt.org/1.x/docs/Community-Plugins.html