The Shellcheck plugin performs quality checks on your project’s Shell source files using Shellcheck and generates reports from these checks.
To use the Shellcheck plugin, include the following in your build script:
plugins {
id("com.felipefzdz.gradle.shellcheck") version "1.0.0"
}
The plugin adds a task to the project called shellcheck
that performs the quality checks.
Note that in order to be portable and repeatable Shellcheck will run:
-
Through a Docker container
-
A configurable Shellcheck version
This implies that no dependencies are required on the executing machine, except for Docker itself.
The Shellcheck plugin a task called shellcheck
to the project.
shellcheck {
sources = files("src/shellScripts", "src/moreScripts")
isIgnoreFailures = true
isShowViolations = true
shellcheckVersion = "v0.7.1"
severity = "error"
}
-
sources - Folders where the shell scripts are located. It will search recursively matching
.sh
,.bash
,.bash_login
,.bash_logout
,.bash_profile
,.bashrc
and.ksh
files. Matching on shell scripts with no extension is not supported yet. -
isIgnoreFailures - Whether to allow the build to continue if there are warnings.
-
isShowViolations - Whether rule violations are to be displayed on the console. Defaults to true.
-
shellcheckVersion - By default "v0.7.1"
-
severity - Minimum severity of errors to consider (error, warning, info, style). Defaults to
style
.
The HTML report generated by the Shellcheck task can be customized using a XSLT stylesheet, for example to highlight specific errors or change its appearance:
tasks.withType<Shellcheck>().configureEach {
reports {
xml.isEnabled = false
txt.isEnabled = false
html.isEnabled = true
html.stylesheet = resources.text.fromFile("config/xsl/shellcheck-custom.xsl")
}
}
XML generated report comes from shellcheck -f checkstyle
, therefore you can get inspiration from a sample Checkstyle stylesheet.
TXT generated report comes from shellcheck -f tty
.