Add checks for OpenJDK Style §2 - Java Source Files (original) (raw)

Parent issue: #19604

Image

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:

  1. Source files must be encoded in 7-bit ASCII - charset property on Checker
  2. All lines must be terminated with a line feed character (LF, ASCII value 10) and not for instance CR or CR+LF - LineEnding Check
  3. There may be no trailing white space at the end of a line - RegexpSingleline Check
  4. 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):

TreeWalker-level:

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