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 5, 2024
1 parent d4329e7 commit 30ab7dd
Show file tree
Hide file tree
Showing 23 changed files with 416 additions and 238 deletions.
155 changes: 142 additions & 13 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,82 @@
<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">
<property name="commentFormat" value="NOSONAR|NOCHECKSTYLE" />
</module>

<!-- 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 +130,51 @@
<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="MissingJavadocMethod" />
<module name="MissingJavadocPackage" />
<module name="MissingJavadocType" />
<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="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 @@ -93,7 +184,9 @@
<module name="LocalVariableName" />
<module name="MemberName" />
<module name="MethodName" />
<module name="MethodTypeParameterName" />
<module name="MethodTypeParameterName">
<property name="format" value="^[A-Z][0-9]?$" />
</module>
<module name="PackageName">
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$" />
</module>
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
16 changes: 12 additions & 4 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

<suppressions>
<!-- Tests -->
<suppress
checks="InnerTypeLast|MethodName|TypeName"
files=".*[\\/]src[\\/]test[\\/]"
/>
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="FinalClass" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="HideUtilityClassConstructor" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="IllegalThrows" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="InnerTypeLast" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="MethodName" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="ThrowsCount" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="TypeName" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+Test\.java$" checks="RequireThis" />

<!-- Test Helpers -->
<suppress files=".*[\\/]?src[\\/]test[\\/].+\.java$" checks="MissingJavadocPackage" />
<suppress files=".*[\\/]?src[\\/]test[\\/].+\.java$" checks="MissingJavadocType" />
</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
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id('org.gradle.toolchains.foojay-resolver-convention') version '0.7.0'
id('org.gradle.toolchains.foojay-resolver-convention') version '0.8.0'
}

rootProject.name = 'maybe'

dependencyResolutionManagement {
versionCatalogs {
libs {
version('checkstyle', '10.12.7')
version('checkstyle', '10.13.0')
version('jacoco', '0.8.11')
version('junit', '5.10.1')
version('sonarlint-core', '9.6.1.76766')
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/io/github/joselion/maybe/CloseableHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
*
* @param <T> The autoclosable type
* @param <E> The throwable type
*
* @author Jose Luis Leon
* @since v1.3.0
*/
public class CloseableHandler<T extends AutoCloseable, E extends Throwable> {
public final class CloseableHandler<T extends AutoCloseable, E extends Throwable> {

private final Either<E, T> value;

Expand All @@ -30,7 +29,7 @@ private CloseableHandler(final Either<E, T> value) {

/**
* Internal use method to instatiate a CloseableHandler from a given resource.
*
*
* @param <T> the type of the resource
* @param <E> the type of the error
* @param resource the resource to instantiate the CloseableHandler with
Expand Down Expand Up @@ -86,11 +85,11 @@ Optional<E> error() {
* prepared resource in the argument. The resource is automatically closed
* after the operation finishes, just like a common try-with-resources
* statement.
* <p>
* Returs a {@link SolveHandler} which allows to handle the possible error
*
* <p>Returs a {@link SolveHandler} which allows to handle the possible error
* and return a safe value. The returned handler is {@code empty} if neither
* the resource nor the error is present.
*
*
* @param <S> the type of the value returned by the {@code solver}
* @param <X> the type of exception the {@code solver} may throw
* @param solver the checked function operation to solve
Expand Down Expand Up @@ -121,11 +120,11 @@ public <S, X extends Throwable> SolveHandler<S, X> solve(
* prepared resource in the argument. The resource is automatically closed
* after the operation finishes, just like a common try-with-resources
* statement.
* <p>
* Returning then an {@link EffectHandler} which allows to handle the
*
* <p>Returning then an {@link EffectHandler} which allows to handle the
* possible error. The returned handler is {@code empty} if neither the
* resource nor the error is present.
*
*
* @param <X> the type of exception the {@code effect} may throw
* @param effect the checked consumer operation to execute
* @return an {@link EffectHandler} with either the thrown exception to be
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/io/github/joselion/maybe/EffectHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
* EffectHandler is an API to handle the posible error of a {@link Maybe}'s
* effect operation. It can return back to maybe to continue linking operations,
* or use termimal methods to return a safe value.
*
*
* @param <E> the type of exception that the effect may throw
*
* @author Jose Luis Leon
* @since v0.3.2
*/
Expand All @@ -43,7 +42,7 @@ static <E extends Throwable> EffectHandler<E> empty() {

/**
* Internal use method to instantiate an {@link EffectHandler} with an error.
*
*
* @param <E> the type of the possible exception
* @param error the error to instanciate the EffectHandler
* @return a EffectHandler instance with an error value
Expand Down Expand Up @@ -101,7 +100,7 @@ public <X extends Throwable> EffectHandler<E> doOnError(final Class<X> ofType, f
/**
* Run an effect if the error is present. The error is passed in the argument
* of the {@code effect} consumer.
*
*
* @param effect a consumer function that recieves the caught error
* @return the same handler to continue chainning operations
*/
Expand All @@ -116,7 +115,7 @@ public EffectHandler<E> doOnError(final Consumer<? super E> effect) {
* The caught error is passed to the argument of the handler consumer. If the
* error is caught and handled, the operation returns an empty
* {@link EffectHandler}. Otherwise, the same instance is returned.
*
*
* @param <X> the type of the error to catch
* @param ofType thetype of the error to catch
* @param handler a consumer function that receives the caught error
Expand Down Expand Up @@ -198,7 +197,7 @@ public void orElse(final Consumer<? super E> effect) {

/**
* Throws the error if present. Does nothing otherwise.
*
*
* @throws E the error thrown by the {@code effect} operation
*/
public void orThrow() throws E {
Expand All @@ -210,7 +209,7 @@ public void orThrow() throws E {
/**
* If an error is present, map the error to another exception and throw it. Does
* nothing otherwise.
*
*
* @param <X> the new error type
* @param mapper a function that maps the new exception to throw
* @throws X a mapped exception
Expand Down
Loading

0 comments on commit 30ab7dd

Please sign in to comment.