This file outlines the changes made to the google_checks.xml file, which was originally obtained from a file on Checkstyle's GitHub repository.
Changes were made in order to:
-
Reflect nuances in Eastern University's standard Java style guide with respect to Google's style guide.
-
Improve functionality with code quality checks on CodeGrade.
-
Provide corrections tailored at students first learning Java.
-
Add better messages to certain warnings explaining what they mean.
The global Checker module was set to the info severity level. Therefore, unless otherwise specified, all errors will not result in a loss of points in CodeGrade.
<module name="Checker">
<property name="severity" value="info" />
...
</module>Many of the comments in the original xml were removed or modified as necessary. Additionally, many xml module attributes were rearranged to better suit documentation purposes.
The following modules pertaining to whitespace and separators were set to severity level warning:
WhitespaceAfterWhitespaceAroundOneStatementPerLineMultipleVariableDeclarationsArrayTypeStyleMissingSwitchDefaultFallThroughUpperEllModifierOrderEmptyLineSeparatorSeparatorWrapSeparatorWrapSeparatorWrapSeparatorWrapSeparatorWrap
Default indentation is now 4 spaces, rather than 2. This is done in conjunction with the --aosp option built-in to Google's formatter.
xml changed:
<module name="Indentation">
<property name="basicOffset" value="4" />
<property name="braceAdjustment" value="4" />
<property name="caseIndent" value="4" />
<property name="throwsIndent" value="8" />
<property name="lineWrappingIndentation" value="8" />
<property name="arrayInitIndent" value="4" />
</module>All values are doubled from the original.
Brackets are not required on single-line if statements.
Note: The only times brackets should be omitted are when:
- A single
ifis used (noelse) and the statement can be placed on the same line as theif.
Good:
if (condition) statement;Bad:
if (condition) statement;
else other_statement;if (condition) very_long_statement_that_exceeds_line_length- An
if-elseblock (or a series ofelse ifconditions) are used together, and all of them contain only one statement.
Good:
if (condition1)
statement1;
else if (condition2)
statement2;
else if (condition3)
statement3;
else
final_statement;Bad:
if (condition)
statement;
else {
statement1;
statement2;
}In each of these situations, omitting brackets is not required. But if it is possible to omit brackets according to these requirements, then doing so is encouraged.
The xml was changed to enable the allowSingleLineStatement property and set the severity level to warning. The affected tokens were also expanded to include every available token. Additionally, the message was updated to be more user-friendly to students.
<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE,
LITERAL_CASE, LITERAL_DEFAULT, LAMBDA" />
<property name="allowSingleLineStatement" value="true" />
<property name="severity" value="error" />
<message key="needBraces"
value="''{0}'' statement must either use ''{}''s or only span one line." />
</module>The following modules were changed to severity level warning:
EmptyBlockLeftCurlyRightCurly
Naming conventions are predominately based on Google's style guide, with some exceptions. For example, underscores are now strictly prohibited (except in constant names).
In most cases, either camel or Pascal case are strictly enforced.
A number of modules were changed in the following ways. They now:
- Require camel case (without any underscores) using a consistent regular expression.
- Have nearly identical messages that are designed to be clear for students.
- Are set to the
errorseverity level. - Are located in the same section of the
xmlfile, under the "camel case" header.
These modules include the following:
CatchParameterNameLambdaParameterNameLocalVariableNameMemberNameMethodNameParameterNamePatternVariableNameRecordComponentName
The TypeName module was changed in a similar fashion, except that it requires Pascal case.
These modules, which effect the naming of generics, require only capital letters and numbers. This is significantly more restrictive than Google's requirements. They include:
ClassTypeParameterNameRecordTypeParameterNameMethodTypeParameterNameInterfaceTypeParameterName
These modules all use the severity level error.
The ConstantName module was added and set to require upper snake case. However, since constant naming cannot be enforced perfectly in accord with Google's style, the severity level is set to info, which does not cause students to lose points in CodeGrade.
The PackageName module was kept using Google's style of only lowercase letters and numbers. Its severity level was set to error.
The AbbreviationAsWordInName module was changed to disable ignoring static names:
<property name="ignoreStatic" value="false" />It was set to the severity level error.
The following modules were categorized "Annotations":
AnnotationLocationAnnotationLocation
The following modules were categorized "Block Checks":
EmptyCatchBlock
The following modules were categorized "Coding":
FallThroughOneStatementPerLineMultipleVariableDeclarationsMissingSwitchDefaultNoFinalizerOverloadMethodsDeclarationOrder
The module VariableDeclarationUsageDistance was removed, despite its intention to uphold rule 4.8.2.2 from Google's style guide. This is because it has too many false-positives and is generally unhelpful to students new to coding. In most cases, it can be suppressed by declaring a flagged variable final, but given that students learn about variables well before learning about the final keyword, this solution is unhelpful.
The OneStatementPerLine and MissingSwitchDefault modules now have severity level error.
The following modules were categorized "Imports":
CustomImportOrder
The following modules were categorized "Javadocs":
InvalidJavadocPositionJavadocTagContinuationIndentationSummaryJavadocJavadocParagraphRequireEmptyLineBeforeBlockTagGroup**AtclauseOrder**JavadocMethod*MissingJavadocMethod*MissingJavadocType*SingleLineJavadoc**NonEmptyAtclauseDescription*
* Changed to security level error.
** Changed to security level warning.
The MissingJavadocMethod module was modified to exclude the main method from requiring Javadocs.
The InvalidJavadocPosition module was given a better message.
<property name="ignoreMethodNamesRegex" value="^main$" />
<property name="severity" value="error" />The JavadocMethod, MissingJavadocType, and NonEmptyAtclauseDescription modules now have security level error.
The RequireEmptyLineBeforeBlockTagGroup, AtclauseOrder, and SingleLineJavadoc modules now have security level warning.
The following modules were categorized "Modifiers":
ModifierOrder
The following modules were categorized "Miscellaneous".
OuterTypeFilename**OuterTypeNumber**UpperEll*ArrayTypeStyle*CommentsIndentation*SuppressionXpathFilterSuppressWarningsHolderSuppressionCommentFilterSuppressWithNearbyCommentFilter
* Changed to security level error.
** Changed to security level warning.
OuterTypeFilename and OuterTypeNumber were also given new, user-friendly messages.