Skip to content

Commit

Permalink
Modify the rule to handle just numbers and null values
Browse files Browse the repository at this point in the history
  • Loading branch information
LaithAlebrahim committed Mar 21, 2024
1 parent 7f20258 commit d102ee0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,33 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</property>
</properties>
</rule>
<rule name="ConstantsOnRightSideOfComparison" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" message="Constants should be on the right side of comparisons.">
<!-- /**
* @Todo Add tests cases for ConstantsOnRightSideOfComparison rule to ensure it works properly
*/ -->
<rule name="ConstantsOnRightSideOfComparison" language="java" message="Constants should be on the right side of comparisons." class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
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.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//EqualityExpression[
(
PrimaryExpression/PrimaryPrefix/Literal
or
PrimaryExpression/PrimaryPrefix/Name[@Image='null']
(
PrimaryExpression/PrimaryPrefix/Literal[@Float='true' or @Double='true' or @Int='true' or @Long='true']
or
PrimaryExpression/PrimaryPrefix/Name[@Image='null']
)
and
PrimaryExpression/PrimarySuffix
)
and
PrimaryExpression/PrimarySuffix
(
./EqualityExpression[@Image='==' or @Image='!=']
)
]
[not(./PrimaryExpression[1]/PrimaryPrefix/Literal or ./PrimaryExpression[1]/PrimaryPrefix/Name[@Image='null'])]
[not(./PrimaryExpression[1]/PrimaryPrefix/Literal[@Float='true' or @Double='true' or @Int='true' or @Long='true'] or ./PrimaryExpression[1]/PrimaryPrefix/Name[@Image='null'])]
]]></value>
</property>
</properties>
Expand Down

0 comments on commit d102ee0

Please sign in to comment.