Skip to content

Commit c2d5d0d

Browse files
committed
[#1198] update checkstyle and pmd rules
1 parent 6bd7a3f commit c2d5d0d

File tree

5 files changed

+18
-63
lines changed

5 files changed

+18
-63
lines changed

qulice-checkstyle/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
7070
<dependency>
7171
<groupId>com.puppycrawl.tools</groupId>
7272
<artifactId>checkstyle</artifactId>
73-
<version>10.9.3</version>
73+
<version>10.14.1</version>
7474
<exclusions>
7575
<exclusion>
7676
<groupId>net.sf.saxon</groupId>

qulice-checkstyle/src/test/java/com/qulice/checkstyle/CheckstyleValidatorTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ void allowsOnlyProperlyOrderedAtClauses() throws Exception {
437437
),
438438
new ViolationMatcher(
439439
message, file, "48", name
440+
),
441+
new ViolationMatcher(
442+
"Class Class should be declared as final.", file, "59", "FinalClassCheck"
440443
)
441444
)
442445
);

qulice-pmd/src/main/java/com/qulice/pmd/SourceValidator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public Collection<PmdError> validate(
101101
for (final DataSource source : sources) {
102102
final String name = source.getNiceFileName(false, path);
103103
Logger.debug(this, "Processing file: %s", name);
104-
this.context.setSourceCodeFilename(name);
105104
this.context.setSourceCodeFile(new File(name));
106105
this.validateOne(source);
107106
}

qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
3535
</description>
3636
<rule ref="category/java/bestpractices.xml">
3737
<exclude name="JUnitTestsShouldIncludeAssert"/>
38+
<exclude name="GuardLogStatement"/>
3839
<exclude name="PositionLiteralsFirstInComparisons"/>
3940
<exclude name="PositionLiteralsFirstInCaseInsensitiveComparisons"/>
4041
</rule>
@@ -158,6 +159,17 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
158159
]]></value>
159160
</property>
160161
</properties>
162+
<example>
163+
<![CDATA[
164+
public final class DirectAccessToStaticFields {
165+
private static int num = 1;
166+
167+
public static int number() {
168+
return num;
169+
}
170+
}
171+
]]>
172+
</example>
161173
</rule>
162174
<rule name="AvoidAccessToStaticMembersViaThis" message="Static members should be accessed in a static way [CLASS_NAME.FIELD_NAME], not via instance reference." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
163175
<description>
@@ -191,10 +203,9 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
191203
and not (
192204
MethodDeclarator[
193205
count(FormalParameters/FormalParameter)=1
194-
and @Image='main'
195206
and FormalParameters/FormalParameter[1]/Type/ReferenceType/ClassOrInterfaceType[@Image='String']
196207
and FormalParameters/FormalParameter[@Varargs='true']
197-
] and not(ResultType/Type)
208+
] and not(ResultType/Type) and @Name='main'
198209
)
199210
] and (
200211
Annotation/MarkerAnnotation/Name[@Image!='BeforeClass' and @Image!='AfterClass'
@@ -219,64 +230,6 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
219230
</property>
220231
</properties>
221232
</rule>
222-
<rule name="ReturnEmptyCollectionRatherThanNull" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" message="Returned null collection was found (NullCollection).">
223-
<description>
224-
Any method that returns an collection (i.e. an array or a List), it is better to return
225-
an empty one rather than a null reference.
226-
</description>
227-
<priority>1</priority>
228-
<properties>
229-
<property name="version" value="2.0"/>
230-
<!--Solve priority confict-->
231-
<property name="xpath">
232-
<value><![CDATA[
233-
//MethodDeclaration[
234-
(./ResultType/Type[pmd-java:typeIs('java.util.Collection')
235-
or pmd-java:typeIs('java.util.Map') or @ArrayType=true()]) and
236-
(./Block/BlockStatement/Statement/ReturnStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/NullLiteral)
237-
]]]></value>
238-
</property>
239-
</properties>
240-
</rule>
241-
<rule name="JUnit5TestShouldBePackagePrivate" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" message="JUnit 5 tests should be package-private">
242-
<description><![CDATA[
243-
Reports JUnit 5 test classes and methods that are not package-private.
244-
Contrary to JUnit 4 tests, which required public visibility to be run by the engine,
245-
JUnit 5 tests can also be run if they're package-private. Marking them as such
246-
is a good practice to limit their visibility.
247-
Test methods are identified as those which use `@Test`, `@RepeatedTest`,
248-
`@TestFactory`, `@TestTemplate` or `@ParameterizedTest`.
249-
]]></description>
250-
<priority>3</priority>
251-
<properties>
252-
<property name="version" value="2.0"/>
253-
<!--Solve priority confict-->
254-
<property name="xpath">
255-
<value><![CDATA[
256-
//ClassOrInterfaceDeclaration[
257-
(: a Junit 5 test class, ie, it has methods with the annotation :)
258-
@Interface=false() and
259-
ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
260-
[Annotation//Name[
261-
pmd-java:typeIs('org.junit.jupiter.api.Test') or pmd-java:typeIs('org.junit.jupiter.api.RepeatedTest')
262-
or pmd-java:typeIs('org.junit.jupiter.api.TestFactory') or pmd-java:typeIs('org.junit.jupiter.api.TestTemplate')
263-
or pmd-java:typeIs('org.junit.jupiter.params.ParameterizedTest')
264-
]]
265-
[MethodDeclaration]
266-
]/(
267-
self::*[@Abstract=false() and (@Public=true() or @Protected=true())]
268-
| ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
269-
[Annotation//Name[
270-
pmd-java:typeIs('org.junit.jupiter.api.Test') or pmd-java:typeIs('org.junit.jupiter.api.RepeatedTest')
271-
or pmd-java:typeIs('org.junit.jupiter.api.TestFactory') or pmd-java:typeIs('org.junit.jupiter.api.TestTemplate')
272-
or pmd-java:typeIs('org.junit.jupiter.params.ParameterizedTest')
273-
]]
274-
/MethodDeclaration[@Public=true() or @Protected=true()]
275-
)
276-
]]></value>
277-
</property>
278-
</properties>
279-
</rule>
280233
<rule name="JUnitTestClassShouldBeFinal" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" message="JUnit test class should be final">
281234
<description><![CDATA[
282235
Reports on JUnit test classes declared non-final.

qulice-pmd/src/test/java/com/qulice/pmd/EmptyCollectionRuleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void failsForNullCollection() throws Exception {
4949
"NullCollection.java",
5050
Matchers.is(false),
5151
Matchers.containsString(
52-
"Returned null collection was found (NullCollection)."
52+
"Return an empty collection rather than null. (ReturnEmptyCollectionRatherThanNull)"
5353
)
5454
).validate();
5555
}

0 commit comments

Comments
 (0)