From 4fa9e77c7cb9d66f1c31e4748b7201232f6a004e Mon Sep 17 00:00:00 2001 From: LaithAlebrahim Date: Mon, 18 Mar 2024 17:01:30 +0300 Subject: [PATCH 1/4] Fixed Constants should be on the right side of comparison --- .../main/java/com/qulice/checkstyle/ConstantUsageCheck.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java b/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java index fdf6ae4de..b26a66750 100644 --- a/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java +++ b/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java @@ -82,7 +82,7 @@ private void checkField(final DetailAST ast, final DetailAST namenode) { final int line = namenode.getLineNo(); DetailAST variable = ast.getNextSibling(); int counter = 0; - while (null != variable) { + while (variable != null) { switch (variable.getType()) { case TokenTypes.VARIABLE_DEF: counter += this.parseVarDef(variable, name); @@ -148,7 +148,7 @@ private String getText(final DetailAST node) { } else { final StringBuilder result = new StringBuilder(); DetailAST child = node.getFirstChild(); - while (null != child) { + while (child != null) { final String text = this.getText(child); result.append(text); if (".".equals(node.getText()) @@ -214,7 +214,7 @@ private int parseDef(final DetailAST definition, final String name, counter += this.parseAnnotation(modifiers, name); } final DetailAST opening = definition.findFirstToken(type); - if (null != opening) { + if (opening != null) { final DetailAST closing = opening.findFirstToken(TokenTypes.RCURLY); final int start = opening.getLineNo(); final int end = closing.getLineNo() - 1; From 2626cbf215835ea884af5634f2747f3dbeaf442d Mon Sep 17 00:00:00 2001 From: LaithAlebrahim Date: Thu, 21 Mar 2024 03:50:36 +0300 Subject: [PATCH 2/4] Undo my last commit and revert it --- .../main/java/com/qulice/checkstyle/ConstantUsageCheck.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java b/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java index b26a66750..fdf6ae4de 100644 --- a/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java +++ b/qulice-checkstyle/src/main/java/com/qulice/checkstyle/ConstantUsageCheck.java @@ -82,7 +82,7 @@ private void checkField(final DetailAST ast, final DetailAST namenode) { final int line = namenode.getLineNo(); DetailAST variable = ast.getNextSibling(); int counter = 0; - while (variable != null) { + while (null != variable) { switch (variable.getType()) { case TokenTypes.VARIABLE_DEF: counter += this.parseVarDef(variable, name); @@ -148,7 +148,7 @@ private String getText(final DetailAST node) { } else { final StringBuilder result = new StringBuilder(); DetailAST child = node.getFirstChild(); - while (child != null) { + while (null != child) { final String text = this.getText(child); result.append(text); if (".".equals(node.getText()) @@ -214,7 +214,7 @@ private int parseDef(final DetailAST definition, final String name, counter += this.parseAnnotation(modifiers, name); } final DetailAST opening = definition.findFirstToken(type); - if (opening != null) { + if (null != opening) { final DetailAST closing = opening.findFirstToken(TokenTypes.RCURLY); final int start = opening.getLineNo(); final int end = closing.getLineNo() - 1; From 7f20258d58c92c77f12136136835e0b8ec146cb8 Mon Sep 17 00:00:00 2001 From: LaithAlebrahim Date: Thu, 21 Mar 2024 03:54:16 +0300 Subject: [PATCH 3/4] Fixed Constants should be on the right side of comparison --- .../main/resources/com/qulice/pmd/ruleset.xml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml b/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml index 750b1f3e9..7852a7f50 100644 --- a/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml +++ b/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml @@ -256,4 +256,26 @@ OF THE POSSIBILITY OF SUCH DAMAGE. + + + Enforces the code style guideline that constants (null, string literals, or numbers) should appear on the right side of comparison operators to reduce the risk of accidental assignment and improve readability. + + 3 + + + + + + From d102ee07a331a9f4a52731bccd35f379718966fd Mon Sep 17 00:00:00 2001 From: LaithAlebrahim Date: Thu, 21 Mar 2024 15:53:58 +0300 Subject: [PATCH 4/4] Modify the rule to handle just numbers and null values --- .../main/resources/com/qulice/pmd/ruleset.xml | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml b/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml index 7852a7f50..d5dacae1b 100644 --- a/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml +++ b/qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml @@ -256,9 +256,12 @@ OF THE POSSIBILITY OF SUCH DAMAGE. - + + - Enforces the code style guideline that constants (null, string literals, or numbers) should appear on the right side of comparison operators to reduce the risk of accidental assignment and improve readability. + Enforces the code style guideline that constants (null or numbers) should appear on the right side of comparison operators ('==' and '!=') to reduce the risk of accidental assignment and improve readability. 3 @@ -266,14 +269,20 @@ OF THE POSSIBILITY OF SUCH DAMAGE.