OrderedProperties
Since Checkstyle 8.22
Description
Rationale: Sorted properties make it easy for people to find required properties by name
in file. This makes it easier to merge. While there are no problems at runtime.
This check is valuable only on files with string resources where order of lines
does not matter at all, but this can be improved.
E.g.: checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/messages.properties
You may suppress warnings of this check for files that have a logical structure like
build files or log4j configuration files. See SuppressionFilter.
<suppress checks="OrderedProperties"
files="log4j.properties|ResourceBundle/Bug.*.properties|logging.properties"/>
Known limitation: The key should not contain a newline. The string compare will work, but not the line number reporting.
Properties
name | description | type | default value | since |
---|---|---|---|---|
fileExtensions | Specify the file extensions of the files to process. | String[] | .properties |
8.22 |
Examples
To configure the check:
<module name="Checker">
<module name="OrderedProperties"/>
</module>
Example properties file:
A=65
a=97
key=107 than nothing
key.sub=k is 107 and dot is 46
key.png=value
# // violation above 'Property key 'key.png' is not in the right order with previous property 'key.sub''
We check order of key's only. Here we would like to use a Locale independent order mechanism and binary order. The order is case-insensitive and ascending.
- The capital 'A' is on 65 and the lowercase 'a' is on position 97 on the ascii table.
- Key and key.sub are in correct order here, because only keys are relevant. Therefore, on line 5 you have only "key" and nothing behind. On line 6 you have "key." The dot is on position 46 which is higher than nothing. key.png will be reported as violation because "png" comes before "sub".
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks