Skip to content

Commit

Permalink
Issue sevntu-checkstyle#734: New check 'Jsr305AnnotationsCheck'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbert committed May 16, 2019
1 parent 356b897 commit e5227c0
Show file tree
Hide file tree
Showing 26 changed files with 2,659 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ h3. Contributors
Hidoyatov Victor, Troshin Sergey, Svinukhov Vladimir, "Ilia Dubinin":https://github.com/sabaka, Dmitry Gridyushko, "Vadym Chekrii":https://github.com/vchekrii, "Vadim Panasiuk":https://github.com/VadimPanasiuk,
"Aleksey Grigirov":https://github.com/KTannenberg, Alexander Berezovsky, "Sergey Burtsev":https://github.com/burtsevsergey, "Baratali Izmailov":https://github.com/baratali, "Max Vetrenko":https://github.com/maxvetrenko,
"Pavel Baranchikov":https://github.com/pbaranchikov , "Ashutosh Agarwal":https://github.com/Radsaggi, "Alexey Nesterenko":https://github.com/alexkravin. , ...... for whole list please look at "contributors list":https://github.com/sevntu-checkstyle/sevntu.checkstyle/network/members .

The "Jsr305AnnotationsCheck" is based on the "JSR305CheckstylePlugin":https://github.com/bjrke/JSR305CheckstylePlugin by "Jan Burkhardt":https://github.com/bjrke with contributions from Mattias Nissler, Thorsten Ehlers, Fabian Loewner and Ole Langbehn.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-metadata PUBLIC
"-//eclipse-cs//DTD Check Metadata 1.1//EN"
"http://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
<checkstyle-metadata>
<rule-group-metadata name="SevNTU checks" priority="500">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,10 @@ MoveVariableInsideIfCheck.desc = Checks if a variable is only used inside if sta

RequireFailForTryCatchInJunitCheck.name = Require Fail For Try/Catch in JUnit Check
RequireFailForTryCatchInJunitCheck.desc = Checks if a try/catch block has a junit fail assertion inside the try for a junit method.

Jsr305AnnotationsCheck.name=Jsr305AnnotationsCheck
Jsr305AnnotationsCheck.desc=Checks method parameters and return values for the presence of @Nonnull, @Nullable, or @CheckForNull annotations.
Jsr305AnnotationsCheck.packages=Sets the parent package for all classes that will be checked.
Jsr305AnnotationsCheck.excludePackages=Packages excluded from checking. This can be useful if under the parent package set with "packages" there are subpackages which should not be checked.
Jsr305AnnotationsCheck.allowOverridingReturnValue=Annotating return values "@CheckForNull" in overridden methods is flagged as a violation. When setting this property to true, this will be ignored (useful for upgrading).
Jsr305AnnotationsCheck.allowOverridingParameter=Annotating parameters "@Nonnull" in overridden methods is flagged as a violation. When setting this property to true, this will be ignored (useful for upgrading).
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-metadata PUBLIC
"-//eclipse-cs//DTD Check Metadata 1.1//EN"
"http://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
<checkstyle-metadata>
<rule-group-metadata name="SevNTU checks" priority="1600">

Expand Down Expand Up @@ -556,5 +556,48 @@
<message-key key="require.fail"/>
</rule-metadata>

<rule-metadata name="%Jsr305AnnotationsCheck.name" internal-name="Jsr305AnnotationsCheck" parent="TreeWalker">
<alternative-name internal-name="com.github.sevntu.checkstyle.checks.coding.Jsr305AnnotationsCheck"/>
<description>%Jsr305AnnotationsCheck.desc</description>
<property-metadata name="packages" datatype="String">
<description>%Jsr305AnnotationsCheck.packages</description>
</property-metadata>
<property-metadata name="excludePackages" datatype="String">
<description>%Jsr305AnnotationsCheck.excludePackages</description>
</property-metadata>
<property-metadata name="allowOverridingReturnValue" datatype="Boolean" default-value="false">
<description>%Jsr305AnnotationsCheck.allowOverridingReturnValue</description>
</property-metadata>
<property-metadata name="allowOverridingParameter" datatype="Boolean" default-value="false">
<description>%Jsr305AnnotationsCheck.allowOverridingParameter</description>
</property-metadata>

<message-key key="jsr305.illegal.class.level.annotation" />
<message-key key="jsr305.contradicting.class.level.annotations" />
<message-key key="jsr305.param.definitions.with.check.annotation" />
<message-key key="jsr305.param.definition.with.override.annotation" />
<message-key key="jsr305.param.definition.with.nonnull.by.default.annotation" />
<message-key key="jsr305.param.definition.with.nullable.by.default.annotation" />
<message-key key="jsr305.param.definition.with.return.values.default.annotation" />
<message-key key="jsr305.param.nonnull.and.nullable.annotation" />
<message-key key="jsr305.primitives.with.nullness.annotation" />
<message-key key="jsr305.overridden.definitions.with.increased.param.constraint" />
<message-key key="jsr305.redundant.nonnull.param.annotation" />
<message-key key="jsr305.redundant.nullable.param.annotation" />
<message-key key="jsr305.parameter.without.nullness.annotation" />
<message-key key="jsr305.return.value.with.nonnull.by.default.annotation" />
<message-key key="jsr305.return.value.with.nullable.annotation" />
<message-key key="jsr305.contradicting.return.value.annotations" />
<message-key key="jsr305.overridden.method.with.check.return.value.annotation" />
<message-key key="jsr305.redundant.nonnull.by.default.annotation" />
<message-key key="jsr305.redundant.nullable.by.default.annotation" />
<message-key key="jsr305.void.with.check.return.value.annotation" />
<message-key key="jsr305.redundant.nonnull.return.annotation" />
<message-key key="jsr305.return.without.nullness.annotation" />
<message-key key="jsr305.overridden.methods.allow.only.nonnull" />
<message-key key="jsr305.need.to.inherit.param.annotations" />
<message-key key="jsr305.constructor.with.return.annotation" />
</rule-metadata>

</rule-group-metadata>
</checkstyle-metadata>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-metadata PUBLIC
"-//eclipse-cs//DTD Check Metadata 1.1//EN"
"http://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
<checkstyle-metadata>
<rule-group-metadata name="SevNTU checks" priority="1600">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-metadata PUBLIC
"-//eclipse-cs//DTD Check Metadata 1.1//EN"
"http://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
<checkstyle-metadata>
<rule-group-metadata name="SevNTU checks" priority="500">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-metadata PUBLIC
"-//eclipse-cs//DTD Check Metadata 1.1//EN"
"http://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd">
<checkstyle-metadata>
<rule-group-metadata name="SevNTU checks" priority="500">

Expand Down
14 changes: 13 additions & 1 deletion sevntu-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
<scope>test</scope>
<version>${checkstyle.eclipse-cs.version}</version>
</dependency>
<!-- required for Jsr305AnnotationsCheck -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<!-- required for Jsr305AnnotationsCheck -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -283,7 +295,7 @@
<regex><pattern>.*.checks.coding.MapIterationInForEachLoopCheck</pattern><branchRate>90</branchRate><lineRate>98</lineRate></regex>
<regex><pattern>.*.checks.coding.NoNullForCollectionReturnCheck</pattern><branchRate>85</branchRate><lineRate>96</lineRate></regex>
<regex><pattern>.*.checks.coding.OverridableMethodInConstructorCheck</pattern><branchRate>94</branchRate><lineRate>99</lineRate></regex>
<regex><pattern>.*.checks.design.HideUtilityClassConstructorCheck</pattern><branchRate>94</branchRate><lineRate>100</lineRate></regex>
<regex><pattern>.*.checks.design.HideUtilityClassConstructorCheck</pattern><branchRate>96</branchRate><lineRate>100</lineRate></regex>
</regexes>
</check>
</configuration>
Expand Down
11 changes: 10 additions & 1 deletion sevntu-checks/sevntu-checks.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">

Expand Down Expand Up @@ -159,6 +159,15 @@
<module name="com.github.sevntu.checkstyle.checks.coding.WhitespaceBeforeArrayInitializerCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck" />
<module name="com.github.sevntu.checkstyle.checks.coding.RequireFailForTryCatchInJunitCheck" />
<module name="com.github.sevntu.checkstyle.checks.coding.Jsr305AnnotationsCheck">
<!-- we ignore this Check only because we are not ready to follow it and refactor whole project for now-->
<property name="severity" value="ignore"/>
<property name="packages" value="com.github.sevntu.checkstyle.checks.naming,com.github.sevntu.checkstyle.checks.coding"/>
<property name="excludePackages" value="com.github.sevntu.checkstyle.checks.sizes,com.github.sevntu.checkstyle.checks.design"/>
<property name="allowOverridingReturnValue" value="false"/>
<property name="allowOverridingParameter" value="false"/>
</module>


<!-- Design -->
<module name="com.github.sevntu.checkstyle.checks.design.ChildBlockLengthCheck">
Expand Down
Loading

0 comments on commit e5227c0

Please sign in to comment.