Checkstyle supports localization of the output messages.
If your language is not supported, please consider
translating the messages in the messages.properties
file. Please let us
know if you translate the file.
The property checkstyle.enableExternalDtdLoad
defines ability use custom DTD files in config and load them from some location.
The property type
is boolean and defaults
to false
. Disabled by default due to security concerns.
The following is an example of include xml files content in xml by ENTITY feature
to let keep common part of configs in single file and composite main config
by few smaller parts.
Imagine we want to define for test sources a bit different requirements
than for main code.
Common part checkstyle-common.xml
:
<module name="FileLength"> <property name="max" value="1"/> </module>
Main config checkstyle.xml
:
<?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd" [ <!ENTITY common SYSTEM "checkstyle-common.xml"> ]> <module name="Checker"> &common; <module name="TreeWalker"> <module name="MemberName"> <property name="format" value="^[a-z][a-zA-Z]+$"/> </module> </module> </module>
Test config checkstyle-test.xml
:
<?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd" [ <!ENTITY common SYSTEM "checkstyle-common.xml"> ]> <module name="Checker"> &common; <module name="TreeWalker"> <module name="MemberName"> <property name="format" value="_[a-z]"/> </module> </module> </module>
Target file for validation Test.java
:
class Test { int i = 0; }
Example of execution for checkstyle.xml
. Violation from Check of
common.xml
is expected, validation of field name is done by main code rules:
$ java -Dcheckstyle.enableExternalDtdLoad=true -classpath checkstyle-XX.X-all.jar \ com.puppycrawl.tools.checkstyle.Main -c checkstyle.xml Test.java Starting audit... [ERROR] Test.java:1: File length is 3 lines (max allowed is 1). [FileLength] [ERROR] Test.java:2:7: 'i' must match pattern '^[a-z][a-zA-Z]+$'. [MemberName] Audit done. Checkstyle ends with 2 errors.
Example of execution for checkstyle-test.xml
. Violation from Check of
common.xml
is expected, validation of field name is done by test code rules:
$ java -Dcheckstyle.enableExternalDtdLoad=true -classpath checkstyle-XX.X-all.jar \ com.puppycrawl.tools.checkstyle.Main -c checkstyle-test.xml Test.java Starting audit... [ERROR] Test.java:1: File length is 3 lines (max allowed is 1). [FileLength] [ERROR] Test.java:2:7: 'i' must match pattern '_[a-z]'. [MemberName] Audit done. Checkstyle ends with 2 errors.
Checkstyle supports property expansion within property definitions, also known as property chaining. This feature allows you to define properties using other properties. For example:
checkstyle.dir=/home/user/checkstyle config.dir=configs checkstyle.suppressions.file=${checkstyle.dir}/${config.dir}/suppressions.xml
${checkstyle.suppressions.file}
in your checkstyle configuration,
which will resolve to
/home/user/checkstyle/configs/suppressions.xml
.
Note that property variable expression must be of the form
${expression}
.
It is not necessary to define chained properties sequentially.