From f4b95a3ae3225d772c1a6d68cca8b902cd0821d9 Mon Sep 17 00:00:00 2001 From: Binu R J Date: Thu, 9 Apr 2020 19:15:39 +0530 Subject: [PATCH 1/2] [java] ClassNamingConventions suggests to add Util for class containing only static constants, fixes #1164 --- .../codestyle/ClassNamingConventionsRule.java | 2 +- .../codestyle/xml/ClassNamingConventions.xml | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ClassNamingConventionsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ClassNamingConventionsRule.java index b90c1804aa..efd4a782c5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ClassNamingConventionsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/ClassNamingConventionsRule.java @@ -30,7 +30,7 @@ public class ClassNamingConventionsRule extends AbstractNamingConventionRule interfaceRegex = defaultProp("interface").build(); private final PropertyDescriptor enumerationRegex = defaultProp("enum").build(); private final PropertyDescriptor annotationRegex = defaultProp("annotation").build(); - private final PropertyDescriptor utilityClassRegex = defaultProp("utility class").defaultValue("[A-Z][a-zA-Z0-9]+(Utils?|Helper)").build(); + private final PropertyDescriptor utilityClassRegex = defaultProp("utility class").defaultValue("[A-Z][a-zA-Z0-9]+(Utils?|Helper|Constants)").build(); public ClassNamingConventionsRule() { diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/ClassNamingConventions.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/ClassNamingConventions.xml index 0248ab34b9..53e4bd1f7c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/ClassNamingConventions.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/ClassNamingConventions.xml @@ -53,7 +53,7 @@ Utility class convention 1 - The utility class name 'Foo' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)' + The utility class name 'Foo' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper|Constants)' Class with only static members except constructors should be a utility class 1 - The utility class name 'Foo' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper)' + The utility class name 'Foo' doesn't match '[A-Z][a-zA-Z0-9]+(Utils?|Helper|Constants)' + + Utility class can have name constants + 0 + + + From cc2894eaf47ff90069a5f9328c90c02d5ad8dcc3 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 13 Apr 2020 12:04:56 +0200 Subject: [PATCH 2/2] [doc] Update release notes, refs #2409, fixes #1164 --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9978d9b8b8..5fac2fa8d1 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -51,6 +51,7 @@ Note that XPath 1.0 support, the default XPath version, is deprecated since PMD * java * [#2378](https://github.com/pmd/pmd/issues/2378): \[java] AbstractJUnitRule has bad performance on large code bases * java-codestyle + * [#1164](https://github.com/pmd/pmd/issues/1164): \[java] ClassNamingConventions suggests to add Util for class containing only static constants * [#1723](https://github.com/pmd/pmd/issues/1723): \[java] UseDiamondOperator false-positive inside lambda * java-design * [#2390](https://github.com/pmd/pmd/issues/2390): \[java] AbstractClassWithoutAnyMethod: missing violation for nested classes @@ -135,6 +136,7 @@ implementations, and their corresponding Parser if it exists (in the same packag * [#2397](https://github.com/pmd/pmd/pull/2397): \[apex] fixed WITH SECURITY_ENFORCED regex to recognise line break characters - [Kieran Black](https://github.com/kieranlblack) * [#2401](https://github.com/pmd/pmd/pull/2401): \[doc] Update DoNotUseThreads rule documentation - [Saikat Sengupta](https://github.com/s4ik4t) * [#2403](https://github.com/pmd/pmd/pull/2403): \[java] #2402 fix false-positives on Primitive Streams - [Bernd Farka](https://github.com/BerndFarkaDyna) +* [#2409](https://github.com/pmd/pmd/pull/2409): \[java] ClassNamingConventions suggests to add Util for class containing only static constants, fixes #1164 - [Binu R J](https://github.com/binu-r) {% endtocmaker %}