GeezerVison is showing github.com — [java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault with non-exhaustive enum switch · Issue #2737 · pmd/pmd
[java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault with non-exhaustive enum switch #2737
Description
Affects PMD Version: 6.26.0
Description:
https://github.com/pmd/pmd/blob/master/pmd-java/src/main/resources/category/java/bestpractices.xml#L1277
The message of the rule is misleading for the case of exhaustive enums. When an enum case is missing it will prompt the developer to add a default case but an alternative solution which is likely more correct is to add the missing cases and make the switch exhaustive. I propose the message is updated to:
Switch statements should have a default label or be exhaustive in case of enums
I also have a question, what is the purpose of the <description> element in rules? Is there any way it could be printed alongside the rule message when the rule fails when using pmd-maven-plugin?
Activity
oowekyala commented on Aug 24, 2020
Your suggestion makes sense!
The description of rules is used to generate documentation, like here on the website. I don't think the maven plugin can print the description. For some rules the description can be quite long though, so I think it's for the best. Maybe it would make sense to have a "short description" element, to give the gist of the rule?
vojtapol commented on Aug 25, 2020
The description of rules is used to generate documentation, like here on the website.
Thanks, that makes sense to me. I think the message is good enough as long as we make sure they have all the necessary info.
changed the title
[-][java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault[/-] [+][java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault with non-exhaustive enum switch[/+] on Nov 11, 2020added a commit that references this issue
on May 6, 2021This issue will close once commit 223b4e6 is merged into the 'main' branch.223b4e6
Metadata
Metadata
Development
No branches or pull requestsIssue actions