Skip to content

Commit

Permalink
chore(lint): Update Checkstyle rules
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Feb 3, 2024
1 parent 2b563ed commit 0df7859
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 23 deletions.
153 changes: 141 additions & 12 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
<module name="NewlineAtEndOfFile" />

<!-- Regexp -->
<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 name="RegexpMultiline">
<property name="fileExtensions" value="java" />
<property name="format" value="^([^\n ]+ )*(class|record|interface) [^{]*\{\n[^\n}]" />
<property name="message" value="Leave empty line after class/record/interface definition." />
</module>
<module name="RegexpMultiline">
<property name="fileExtensions" value="java" />
<property name="format" value="^([^\n ]+ )*(enum) [^{]*\{\n[\n}]" />
<property name="message" value="Do not leave empty line after enum definition." />
</module>
<module name="RegexpMultiline">
<property name="fileExtensions" value="java" />
<property name="format" value="[\n{]\n(?:.+)\}\n$" />
<property name="message" value="Do not leave empty line before end of class/record/interface/enum" />
</module>

<!-- Size Violations -->
<module name="FileLength">
<property name="max" value="2000" />
</module>
<module name="LineLength">
<property name="max" value="120" />
<property name="ignorePattern" value="^package.*|^import.*" />
Expand All @@ -38,32 +44,80 @@
<module name="TreeWalker">
<property name="tabWidth" value="2" />

<!-- Annotations -->
<module name="AnnotationUseStyle" />
<module name="MissingDeprecated" />
<module name="MissingOverride" />

<!-- Block Checks -->
<module name="AvoidNestedBlocks" />
<module name="EmptyBlock" />
<module name="EmptyCatchBlock" />
<module name="LeftCurly" />
<module name="NeedBraces" />
<module name="RightCurly" />

<!-- Class Design -->
<module name="FinalClass" />
<module name="HideUtilityClassConstructor" />
<module name="InnerTypeLast" />
<module name="InterfaceIsType" />
<module name="MutableException" />
<module name="OneTopLevelClass" />
<module name="ThrowsCount" />
<module name="VisibilityModifier" />

<!-- Coding -->
<module name="AvoidDoubleBraceInitialization" />
<module name="AvoidNoArgumentSuperConstructorCall" />
<module name="CovariantEquals" />
<module name="DeclarationOrder" />
<module name="DefaultComesLast" />
<module name="EmptyStatement" />
<module name="EqualsHashCode" />
<module name="FallThrough" />
<module name="FinalLocalVariable" />
<module name="HiddenField">
<property
name="tokens"
value="VARIABLE_DEF, PATTERN_VARIABLE_DEF, LAMBDA, RECORD_COMPONENT_DEF"
/>
</module>
<module name="IllegalCatch" />
<module name="IllegalThrows" />
<module name="IllegalToken" />
<module name="IllegalType" />
<module name="InnerAssignment" />
<module name="MissingSwitchDefault" />
<module name="ModifiedControlVariable" />
<module name="MultipleVariableDeclarations" />
<module name="NoArrayTrailingComma" />
<module name="NoClone" />
<module name="NoEnumTrailingComma" />
<module name="NoFinalizer" />
<module name="OneStatementPerLine" />
<module name="OverloadMethodsDeclarationOrder" />
<module name="PackageDeclaration" />
<module name="ParameterAssignment" />
<module name="RequireThis">
<property name="validateOnlyOverlapping" value="false" />
</module>
<module name="SimplifyBooleanExpression" />
<module name="SimplifyBooleanReturn" />
<module name="StringLiteralEquality" />
<module name="UnnecessaryParentheses" />
<module name="UnnecessarySemicolonAfterOuterTypeDeclaration" />
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
<module name="UnnecessarySemicolonInEnumeration" />
<module name="UnnecessarySemicolonInTryWithResources" />
<module name="UnusedLocalVariable" />

<!-- Javadoc Comments -->
<module name="InvalidJavadocPosition" />
<!-- Filters -->
<module name="SuppressWithNearbyCommentFilter" />

<!-- Imports -->
<module name="AvoidStarImport" />
<module name="IllegalImport" />
<module name="ImportOrder">
<property name="groups" value="/^java\./,javax,org,com" />
<property name="ordered" value="true" />
Expand All @@ -74,16 +128,55 @@
<module name="RedundantImport" />
<module name="UnusedImports" />

<!-- Javadoc Comments -->
<module name="InvalidJavadocPosition" />
<module name="JavadocBlockTagLocation" />
<module name="JavadocContentLocation" />
<module name="JavadocMethod" />
<module name="JavadocMissingLeadingAsterisk" />
<module name="JavadocMissingWhitespaceAfterAsterisk" />
<module name="JavadocParagraph" />
<module name="JavadocStyle">
<property name="endOfSentenceFormat" value="([.:?!][ \t\n\r\f&lt;])|([.:?!]$)" />
</module>
<module name="JavadocTagContinuationIndentation">
<property name="offset" value="2" />
</module>
<module name="JavadocType">
<property name="scope" value="public" />
</module>
<module name="NonEmptyAtclauseDescription" />
<module name="RequireEmptyLineBeforeBlockTagGroup" />
<module name="SingleLineJavadoc" />

<!-- Miscellaneous -->
<module name="ArrayTypeStyle" />
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true" />
</module>
<module name="CommentsIndentation" />
<module name="FinalParameters" />
<module name="Indentation">
<property name="arrayInitIndent" value="2" />
<property name="basicOffset" value="2" />
<property name="caseIndent" value="2" />
<property name="lineWrappingIndentation" value="2" />
<property name="throwsIndent" value="2" />
</module>
<module name="NoCodeInFile" />
<module name="OuterTypeFilename" />
<module name="TodoComment" />
<module name="TrailingComment">
<property name="legalComment" value="^\sNOSONAR$" />
</module>
<module name="UpperEll" />

<!-- Modifiers -->
<module name="ModifierOrder" />
<module name="RedundantModifier" />

<!-- Naming Conventions -->
<module name="AbstractClassName" />
<module name="ClassTypeParameterName" />
<module name="ConstantName" />
<module name="IllegalIdentifierName" />
Expand All @@ -104,17 +197,53 @@
<module name="StaticVariableName" />
<module name="TypeName" />

<!-- Regexp -->
<module name="RegexpSinglelineJava">
<property name="format" value="(?!\*)[^$]\s+$" />
<property name="minimum" value="0" />
<property name="maximum" value="0" />
<property name="message" value="Line has trailing spaces." />
</module>

<!-- Size Violations -->
<module name="AnonInnerLength" />
<module name="OuterTypeNumber" />

<!-- Whitespace -->
<module name="EmptyForInitializerPad" />
<module name="EmptyForIteratorPad" />
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLines" value="false" />
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false" />
</module>
<module name="GenericWhitespace" />
<module name="MethodParamPad" />
<module name="NoLineWrap" />
<module name="NoWhitespaceAfter" />
<module name="NoWhitespaceBefore" />
<module name="NoWhitespaceAfter">
<property name="allowLineBreaks" value="true" />
<property
name="tokens"
value="ARRAY_INIT, AT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, ARRAY_DECLARATOR, INDEX_OP, METHOD_REF"
/>
</module>
<module name="NoWhitespaceBefore">
<property name="allowLineBreaks" value="true" />
<property
name="tokens"
value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, LABELED_STAT, METHOD_REF"
/>
</module>
<module name="NoWhitespaceBeforeCaseDefaultColon" />
<module name="OperatorWrap" />
<module name="ParenPad" />
<module name="SeparatorWrap">
<property name="option" value="eol" />
<property name="tokens" value="COMMA" />
</module>
<module name="SeparatorWrap">
<property name="option" value="nl" />
<property name="tokens" value="DOT" />
</module>
<module name="SingleSpaceSeparator" />
<module name="TypecastParenPad" />
<module name="WhitespaceAfter" />
Expand Down
12 changes: 7 additions & 5 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.3//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<!-- Tests -->
<suppress
checks="InnerTypeLast|MethodName|TypeName"
files=".*[\\/]src[\\/]test|testkit[\\/]"
/>
<suppress files=".*[\\/]?src[\\/]test(?:kit)?[\\/].+Test\.java$" checks="HideUtilityClassConstructor" />
<suppress files=".*[\\/]?src[\\/]test(?:kit)?[\\/].+Test\.java$" checks="InnerTypeLast" />
<suppress files=".*[\\/]?src[\\/]test(?:kit)?[\\/].+Test\.java$" checks="MethodName" />
<suppress files=".*[\\/]?src[\\/]test(?:kit)?[\\/].+Test\.java$" checks="ThrowsCount" />
<suppress files=".*[\\/]?src[\\/]test(?:kit)?[\\/].+Test\.java$" checks="TypeName" />
<suppress files=".*[\\/]?src[\\/]test(?:kit)?[\\/].+Test\.java$" checks="RequireThis" />
</suppressions>
2 changes: 1 addition & 1 deletion gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ com.google.errorprone:error_prone_annotations:2.23.0=checkstyle
com.google.guava:failureaccess:1.0.2=checkstyle
com.google.guava:guava:33.0.0-jre=checkstyle
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=checkstyle
com.puppycrawl.tools:checkstyle:10.12.7=checkstyle
com.puppycrawl.tools:checkstyle:10.13.0=checkstyle
commons-beanutils:commons-beanutils:1.9.4=checkstyle
commons-codec:commons-codec:1.15=checkstyle
commons-collections:commons-collections:3.2.2=checkstyle
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rootProject.name = 'strict-null-check'
dependencyResolutionManagement {
versionCatalogs {
libs {
version('checkstyle', '10.12.7')
version('checkstyle', '10.13.0')
version('junit', '5.10.1')
version('sonarlint-core', '9.6.1.76766')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Set<String> getSourcePackages() {
.stream()
.flatMap(sourceSet -> sourceSet.getAllJava().getSrcDirs().stream())
.map(File::toPath)
.filter(path -> !path.startsWith(getGeneratedDir().getPath()))
.filter(path -> !path.startsWith(this.getGeneratedDir().getPath()))
.flatMap(path -> Maybe.of(path).solve(Files::walk).orElseGet(Stream::empty))
.filter(subdir -> Files.notExists(subdir.resolve("package-info.java")))
.flatMap(subdir -> Maybe.of(subdir).solve(Files::list).orElseGet(Stream::empty))
Expand Down Expand Up @@ -85,7 +85,7 @@ private void buildPackageInfo(final String packageName) {
final var basePath = this.getGeneratedDir().getPath();
final var dashedPath = packageName.replace(".", "/");
final var dir = this.project.mkdir(basePath.concat("/java/main/").concat(dashedPath));
final var templateOutput = getPackageInfoTemplate(packageName);
final var templateOutput = this.getPackageInfoTemplate(packageName);
final var outputFile = new File(dir.getAbsolutePath(), "package-info.java");

Maybe.of(outputFile)
Expand All @@ -96,7 +96,7 @@ private void buildPackageInfo(final String packageName) {
}
})
.orThrow(exception -> {
project.getLogger().error(
this.project.getLogger().error(
"Unable to generate package-info.java at [%s]".formatted(outputFile),
exception
);
Expand Down
6 changes: 5 additions & 1 deletion src/testkit/java/testing/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;

public class Helpers {
public final class Helpers {

public static final Path PROJECT_PATH = Path.of("build/testkit");

public static final Path SRC_PATH = PROJECT_PATH.resolve("src/main/java/com/example/app");

public static final Path TEST_PATH = PROJECT_PATH.resolve("src/test/java/com/example/app");

private Helpers() {
throw new UnsupportedOperationException("Helpers is a helper class");
}

public static void writeBuildGradle(final String text) {
try {
Files.writeString(PROJECT_PATH.resolve("build.gradle"), text);
Expand Down

0 comments on commit 0df7859

Please sign in to comment.