Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Constants should be on the right side of comparison #1237

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions qulice-pmd/src/main/resources/com/qulice/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,35 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</property>
</properties>
</rule>
<!-- /**
* @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 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[@Float='true' or @Double='true' or @Int='true' or @Long='true']
or
PrimaryExpression/PrimaryPrefix/Name[@Image='null']
)
and
PrimaryExpression/PrimarySuffix
)
and
(
./EqualityExpression[@Image='==' or @Image='!=']
)
]
[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>
</rule>
</ruleset>