Add Java checkstyle
Closed this issue · 1 comments
In order to have a common appearance and general rules in the whole extension, we should add a light Java check style and import order.
Documentation:
Checkstyle proposal:
My proposal is something very light, that could be extended(or change) in the future if we see any inconvenience.
<module name="Checker">
<property name="severity" value="error"/>
<module name="TreeWalker">
<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="RedundantImport"/>
<module name="RequireThis">
<property name="validateOnlyOverlapping" value="true"/>
</module>
</module>
</module>
Imports (https://checkstyle.org/checks/imports/index.html):
Checks for redundant import statements. An import statement is considered redundant if:
It is a duplicate of another import. This is, when a class is imported more than once.
The class non-statically imported is from the java.lang package, e.g. importing java.lang.String.
The class non-statically imported is from the same package as the current package.
Checks that there are no import statements that use the * notation.
Checks for unused import statements. An import statement is considered unused if:
It is not referenced in the file. The algorithm does not support wild-card imports like import java.io.*;. Most IDE's provide very sophisticated checks for imports that handle wild-card imports.
The class imported is from the java.lang package. For example, importing java.lang.String.
The class imported is from the same package.
Optionally: it is referenced in Javadoc comments. This check is on by default, but it is considered bad practice to introduce a compile-time dependency for documentation purposes only. As an example, the import java.util.List would be considered referenced with the Javadoc comment {@link List}. The alternative to avoid introducing a compile-time dependency would be to write the Javadoc comment as {@link java.util.List}.
RequireThis (https://checkstyle.sourceforge.io/checks/coding/requirethis.html)
Import sort proposal:
impsort-maven-plugin
in order to automatically sort/validate the order of all the import
Proposal:
- java
- jakarta
- org
- io
formatter-maven-plugin
in order to automatically (re)format/validate a maven project(including source code). Keeping a coding style format consistent and following certain specifications is an important requirement in preventing unnecessary conflicts and code diffs.
Note: all of this plugins should be triggered with a mvn clean install