Skip to content


checkstyle documentation

checkstyle - GitHub

Configuration in Mega-Linter

Variable Description Default value
JAVA_CHECKSTYLE_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
JAVA_CHECKSTYLE_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
JAVA_CHECKSTYLE_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
JAVA_CHECKSTYLE_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
JAVA_CHECKSTYLE_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
JAVA_CHECKSTYLE_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
JAVA_CHECKSTYLE_PRE_COMMANDS List of bash commands to run before the linter None
JAVA_CHECKSTYLE_POST_COMMANDS List of bash commands to run after the linter None
JAVA_CHECKSTYLE_CONFIG_FILE checkstyle configuration file name
Use LINTER_DEFAULT to let the linter find it
JAVA_CHECKSTYLE_RULES_PATH Path where to find linter configuration file Workspace folder, then Mega-Linter default rules
JAVA_CHECKSTYLE_DISABLE_ERRORS Run linter but consider errors as warnings false
JAVA_CHECKSTYLE_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0

IDE Integration

Use checkstyle in your favorite IDE to catch errors before Mega-Linter !

IDE Extension Name Install
Eclipse eclipse-cs Visit Web Site
IDEA checkstyle-idea
Visual Studio Code vscode-checkstyle Install in VsCode

Mega-Linter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default Mega-Linter Flavor 94 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 42 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .java

How the linting is performed

  • checkstyle is called one time by identified file

Example calls

java -jar /usr/bin/checkstyle
java -jar /usr/bin/checkstyle -c sun_checks.xml

Help content

Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32    use a 32-bit data model if available
    -d64    use a 64-bit data model if available
    -server    to select the "server" VM
                  The default VM is server,
                  because you are running on a server-class machine.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
                  set a system property
                  enable verbose output
    -version      print product version and exit
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
                  enable assertions with specified granularity
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
                  load native agent library by full pathname
                  load Java programming language agent, see java.lang.instrument
                  show splash screen with specified image
See for more details.

Installation on mega-linter Docker image

  • Dockerfile commands :
# Parent descriptor install
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
# Linter install
        | grep browser_download_url \
        | grep ".jar" \
        | cut -d '"' -f 4) \
    && curl --retry 5 --retry-delay 5 -sSL $CHECKSTYLE_LATEST \
        --output /usr/bin/checkstyle

Example success log

Results of checkstyle linter (version 8.38)
See documentation on

[SUCCESS] .automation/test/java/
    Starting audit...
    Audit done.

Example error log

Results of checkstyle linter (version 8.38)
See documentation on

[ERROR] .automation/test/java/
    Starting audit...
    [ERROR] .automation/test/java/ Utility classes should not have a public or default constructor. [HideUtilityClassConstructor]
    [ERROR] .automation/test/java/ Name 'java_bad_1' must match pattern '^[A-Z][a-zA-Z0-9]*$'. [TypeName]
    [ERROR] .automation/test/java/ '{' at column 1 should be on the previous line. [LeftCurly]
    [ERROR] .automation/test/java/ Parameter args should be final. [FinalParameters]
    [ERROR] .automation/test/java/ Array brackets at illegal position. [ArrayTypeStyle]
    [ERROR] .automation/test/java/ '{' at column 5 should be on the previous line. [LeftCurly]
    Audit done.
    Checkstyle ends with 6 errors.