You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
PMD provides some rules for finding blocks without braces for Apex. Talking about ifs, it provides different rules for ifs with and without elses. But the rule made to only match if...elses are catching ifs without elses. Even the provided example for the rule states that it will not match an if without an else, but that is not what is happening now.
The problem is on the xpath used for catching the violation. If we use the provided one:
Since you already have a fix, you could submit a PR. We'll gladly help if you have trouble
Side note: in the future, it would be nice to have an Apex rule similar to the Java ControlStatementBraces, which was added to merge all rules about braces and avoid this kind of mishaps.
Affects PMD Version:
6.41.0+
7.0.0
Rule: IfElseStmtsMustUseBraces
https://pmd.github.io/pmd-6.41.0/pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces
Description:
PMD provides some rules for finding blocks without braces for Apex. Talking about ifs, it provides different rules for ifs with and without elses. But the rule made to only match if...elses are catching ifs without elses. Even the provided example for the rule states that it will not match an if without an else, but that is not what is happening now.
The problem is on the xpath used for catching the violation. If we use the provided one:
There is not an enforcement that the else must be present. We need something like:
Where we make sure that the there is an else statement present.
Code Sample demonstrating the issue:
The example provided with the rule can be used to demonstrate the problem:
Expected outcome:
PMD reports violations on lines 2, 6 and 8. But the violation on line 2 is wrong. Only the lines 6 and 8 should be reported
Running PMD through: CLI
The text was updated successfully, but these errors were encountered: