WartRemover Gradle Plugin

Index


Purpose

The WartRemover Gradle Plugin is a plugin for Gradle whose goal is to simplify the configuration of the code linter WartRemover in Scala 3 projects.

The WartRemover Gradle Plugin relies on the WartRemover Compiler Plugin for the Scala 3 compiler, which is used to search the user’s code for warts during compilation.

This plugin offers two basic services:

Implementation

The implementation of this plugin is described by the following UML Class Diagram, which will be explained in the following sections.

UML Class Diagram

WartRemoverPlugin

The WartRemoverPlugin is a org.gradle.api.Plugin, meaning that it can be applied to a Gradle project as any other Gradle plugin.

When applied, the WartRemoverPlugin does the following:

  1. Provide an extension called wartremover, whose purpose is to configure this plugin;
  2. After the project evaluation:
    1. Add the WartRemover Compiler Plugin to the project dependencies, applying it to the Scala 3 compiler.

      The version of the WartRemover Compiler Plugin is computed from the version of the Scala 3 dependency provided by the user;

    2. Configure the WartRemover Compiler Plugin using the HOCON configuration file provided by the user;
    3. Provide a task called wartRemoverCompilerOptions, whose purpose is to print to the console the compiler options provided by the user.

WartRemoverExtension

The wartremover extension is modelled by the class WartRemoverExtension, which provides the following methods:

  • configFile: set the path to the HOCON configuration file used to compute the compiler options for the WartRemover Compiler Plugin. By default, this is set to the .wartremover.conf file within the root directory of the user’s project.
  • compilerOptions: parse the HOCON configuration file provided by the user, producing the compiler options for the WartRemover Compiler Plugin. If no configuration file is provided, it produces the default compiler options.

These methods can be accessed also by the user as follows:

// build.gradle.kts
wartremover {
    configFile(".custom-wartremover.conf")
    val options = compilerOptions()
}

The compiler options for the WartRemover Compiler Plugin are modelled by the class WartRemoverCompilerConfiguration, which is a type of CompilerConfiguration.

A CompilerConfiguration is a list of compiler options that can be applied to a certain compiler. In particular, a WartRemoverCompilerConfiguration is a set of compiler options to be applied to the Scala 3 compiler for configuring the WartRemover Compiler Plugin.

A WartRemoverCompilerConfiguration can be defined as a map from wart identifiers to TraverserTypes, where a TraverserType defines the threat level assigned to a wart when it is found during compilation.

When calling its method toCompilerOptions, the WartRemoverCompilerConfiguration produces a list of compiler options for configuring the WartRemover Compiler Plugin, computed from its internal map.

These compiler options are finally applied by the WartRemoverPlugin to the Scala 3 compiler, after the evaluation of the project.

Tasks

  • wartRemoverCompilerOptions

    The task wartRemoverCompilerOptions is a type of PrintTask, where a PrintTask is a task which takes a text as input to be printed to the console when called by the user.

    In particular, the task wartRemoverCompilerOptions is defined by the WartRemoverPlugin after the project evaluation, in order to print the compiler options computed for configuring the WartRemover Compiler Plugin.

Testing

The plugin has been tested using the Gradle TestKit on a build file defined specifically for testing purposes.

The goal of the provided tests was mainly to verify that this plugin could be applied to a Gradle project and that the compiler options for the WartRemover Compiler Plugin were computed correctly from the HOCON configuration file provided by the user.

The plugin has also been manually tested against several Scala 3 projects.

Note: the test suite should be extended to verify that all warts are identified correctly within some sample Scala 3 projects.


Back to Top