Parent issue: #19604
Description
Add Checkstyle checks for all rules under §2 - Java Source Files of the OpenJDK Java Style Guidelines v6.
Rules covered
From §2 - Java Source Files:
- Source files must be encoded in 7-bit ASCII -
charset property on Checker
- All lines must be terminated with a line feed character (LF, ASCII value 10) and not for instance CR or CR+LF -
LineEnding Check
- There may be no trailing white space at the end of a line -
RegexpSingleline Check
- The name of a source file must equal the name of the class it contains followed by the
.java extension, even for files that only contain a package private class. This does not apply to files that do not contain any class declarations, such as package-info.java. - OuterTypeFilename Check
Special Characters
Apart from LF the only allowed white space character is Space (ASCII value 32). Note that this implies that other white space characters (in, for instance, string and character literals) must be written in escaped form.
', ", \, \t, \b, \r, \f, and \n should be preferred over corresponding octal (e.g. \047) or Unicode (e.g. \u0027) escaped characters.
Should there be a need to go against the above rules for the sake of testing, the test should generate the required source.
Motivation
Having any white space character but space and LF in the source code can be a source of confusion.
The short forms (e.g. \t) are commonly used and easier to recognize than the corresponding longer forms (\011, \u0009).
Checks to add to openjdk_checks.xml
Checker-level (non-TreeWalker):
<property name="charset" value="US-ASCII"/>
<module name="LineEnding">
<property name="lineEnding" value="lf"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>
TreeWalker-level:
<module name="OuterTypeFilename"/>
Progress tracker
| Check |
Rule |
PR |
charset=US-ASCII |
7-bit ASCII encoding |
|
LineEnding |
LF line terminators |
|
RegexpSingleline |
No trailing whitespace |
|
OuterTypeFilename |
Filename matches class name |
|
Parent issue: #19604
Description
Add Checkstyle checks for all rules under §2 - Java Source Files of the OpenJDK Java Style Guidelines v6.
Rules covered
From §2 - Java Source Files:
charsetproperty on CheckerLineEnding CheckRegexpSingleline Check.javaextension, even for files that only contain a package private class. This does not apply to files that do not contain any class declarations, such as package-info.java. -OuterTypeFilename CheckSpecial Characters
Apart from LF the only allowed white space character is Space (ASCII value 32). Note that this implies that other white space characters (in, for instance, string and character literals) must be written in escaped form.
', ", \, \t, \b, \r, \f, and \n should be preferred over corresponding octal (e.g. \047) or Unicode (e.g. \u0027) escaped characters.
Should there be a need to go against the above rules for the sake of testing, the test should generate the required source.
Motivation
Having any white space character but space and LF in the source code can be a source of confusion.
The short forms (e.g. \t) are commonly used and easier to recognize than the corresponding longer forms (\011, \u0009).
Checks to add to
openjdk_checks.xmlChecker-level (non-TreeWalker):
TreeWalker-level:
Progress tracker
charset=US-ASCIILineEndingRegexpSinglelineOuterTypeFilename