Skip to main content

Checkstyle

Supported VersionLanguageWebsite
8.44Javahttps://checkstyle.org

Checkstyle is a style checker for Java code and aims to enforce a coding standard.

Getting Started#

To start using Checkstyle, enable it in your repository settings.

Configuration#

You can customize Checkstyle analysis using sider.yml. For example:

linter:  checkstyle:    config: google    target: src    exclude:      - vendor      - pattern: foo      - string: foo    ignore:      - warning      - info    properties: checkstyle.properties
NameTypeDefault
root_dirstring-
dependenciesstring[], map[]-
configstringsider
targetstring, string[].
excludestring, string[], map[]-
ignorestring[]-
propertiesstring-

config#

This option allows you to declare the coding standard you want to follow.

Supported values are:

See also the -c CLI option of Checkstyle.

target#

This option allows you to specify directories to be analyzed.

alias: dir

exclude#

This option allows you to specify -e and -x command line options passed to the checkstyle command.

  • If exclude is a string, the -e option will be used.
  • If including object(s) with a string key (e.g. { string: vendor }), the -e option will be used.
  • If including object(s) with a pattern key (e.g. { pattern: vendor }), the -x option will be used.

By default, nothing will be excluded.

ignore#

This option allows you to ignore issues based on their severity. Write the list of severities you want to ignore.

By default, nothing will be ignored.

properties#

This option allows you to specify the properties file passed to checkstyle. The value will be passed to Checkstyle's -p option.

Localization#

Checkstyle supports the localization of output messages. You can see the details on Checkstyle documentation. Also, you can see the supported languages in Checkstyle's GitHub.

If you want to use the localization on Sider, you need to do as follows.

  1. Create your Checkstyle configuration file, e.g. your_checkstyle_ruleset.xml. (it is easy to base an existing file like google_checks.xml)

  2. Add the localeCountry and localeLanguage properties to the configuration file like below:

    <module name="Checker">  <property name="localeCountry" value="JP"/>  <property name="localeLanguage" value="ja"/>  <!-- ... --></module>
  3. Set the config option in your sider.yml like below:

    linter:  checkstyle:    config: your_checkstyle_ruleset.xml