Browse Source

Configure Checkstyle to require package-level null-safety annotations

This commit updates the project's checkstyle configuration to check
that package-info.java files contain the @NonNullApi and @NonNullFields
null-safety annotations.

See gh-30069
pull/30107/head
Ed .d 2 years ago committed by Sam Brannen
parent
commit
7e32f504b0
  1. 4
      src/checkstyle/checkstyle-suppressions.xml
  2. 20
      src/checkstyle/checkstyle.xml

4
src/checkstyle/checkstyle-suppressions.xml

@ -130,7 +130,7 @@ @@ -130,7 +130,7 @@
<suppress files="sockjs[\\/]transport[\\/]TransportType" checks="JavadocVariable"/>
<suppress files="src[\\/]test[\\/]java[\\/]org[\\/]springframework[\\/]web[\\/]reactive[\\/]protobuf[\\/].*" checks=".*"/>
<!-- Suppress JavadocPackage checks on packages outside of src/main-->
<!-- Suppress JavadocPackage checks and package null safety annotations on packages outside of src/main-->
<!-- And outside 'framework-docs' module-->
<!-- And outside 'spring-core/src/main/java/org/springframework/asm' package-->
<!-- And outside 'spring-core/src/main/java/org/springframework/cglib' package-->
@ -138,5 +138,7 @@ @@ -138,5 +138,7 @@
<!-- And outside 'spring-core/src/main/java/org/springframework/javapoet' package-->
<!-- And outside 'spring-core/src/main/java/org/springframework/lang' package-->
<suppress checks="JavadocPackage" files="(^(?!.*src[\\/]main[\\/]).*)|(.*framework-docs.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/asm.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/cglib.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/objenesis.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/javapoet.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/lang.*)"/>
<suppress checks="RegexpSinglelineJava" files="^(?!.*(package-info.java))" id="javaDocPackageNonNullFieldsAnnotation"/>
<suppress checks="RegexpSinglelineJava" files="^(?!.*(package-info.java))" id="javaDocPackageNonNullApiAnnotation"/>
</suppressions>

20
src/checkstyle/checkstyle.xml

@ -239,6 +239,26 @@ @@ -239,6 +239,26 @@
<module name="io.spring.javaformat.checkstyle.check.SpringCatchCheck"/>
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck"/>
<module name="io.spring.javaformat.checkstyle.check.SpringJUnit5Check"/>
<!--package-info should contain null-safety annotations-->
<!--These two modules will fail to detect multiline annotations-->
<module name="RegexpSinglelineJavaCheck">
<property name="id" value="javaDocPackageNonNullFieldsAnnotation"/>
<property name="format" value="(@NonNullFields|@org\.springframework\.lang\.NonNullFields)"/>
<property name="minimum" value="1"/>
<property name="maximum" value="1"/>
<property name="severity" value="warning"/>
<property name="message" value="package-info.java is missing required null-safety annotation @NonNullFields."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJavaCheck">
<property name="id" value="javaDocPackageNonNullApiAnnotation"/>
<property name="format" value="(@NonNullApi|@org\.springframework\.lang\.NonNullApi)"/>
<property name="minimum" value="1"/>
<property name="maximum" value="1"/>
<property name="severity" value="warning"/>
<property name="message" value="package-info.java is missing required null-safety annotation @NonNullApi."/>
<property name="ignoreComments" value="true"/>
</module>
</module>
<!--package-info checker -->

Loading…
Cancel
Save