Gradle plugin for configuring WartRemover as a code linter in a Scala 3 project.
In a Scala 3 project, import the plugin inside the Gradle configuration.
plugins {
scala
id("io.github.jahrim.wartremover") version "<your-choice>"
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.scala-lang:scala3-library_3:<scala-version>")
}
This plugin only works for Scala 3. Moreover, it depends on
WartRemover Linting Tool for Scala, requiring
a <scala-version>
for which such tool is available (e.g. 3.2.2
).
The configuration of WartRemover for your Scala 3 project must be specified as an HOCON configuration file inside your project.
The plugin should be configured by specifying where to look for such configuration file.
wartremover {
configFile("<path-to-your-configuration-file>") // default: .wartremover.conf
}
If not configured, the default path for that the configuration file is <your-project>/.wartremover.conf
.
If such file is not found, the user will be notified that a default configuration for WartRemover has been
loaded.
Here's the default configuration file applied to WartRemover.
warts {
Any = Error
AsInstanceOf = Error
DefaultArguments = Error
EitherProjectionPartial = Error
IsInstanceOf = Error
IterableOps = Warning
NonUnitStatements = Warning
Null = Warning
OptionPartial = Warning
Product = Warning
Return = Warning
Serializable = Warning
StringPlusAny = Warning
Throw = Ignore
TripleQuestionMark = Warning
TryPartial = Warning
Var = Warning
}
The configuration file specifies how each wart should be treated by the Scala 3 compiler.
The configuration file must contain the warts
clause, which is a set of key-value pairs, where the keys are the
wart identifiers and the values are their level of threat, chosen by the user.
There are three levels of threat the user can choose from:
Error
: when the wart is found, the compiler will throw an error;Warning
: when the wart is found, the compiler will notify the user with a warning;Ignore
: when the wart is found, the compiler will ignore it.
The documentation for all warts can be found at this link. As of now, only Unsafe Warts are supported.
In your Scala 3 project, you can disable WartRemover for part of your code, by including the following annotation:
@SuppressWarnings(Array("org.wartremover.warts.<wart-id>"))
.
For example:
@SuppressWarnings(Array("org.wartremover.warts.Null"))
val myCodeHasToBe = null
See documentation at the repository webpage.