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

[java] Improve rule UnnecessaryReturn to detect more cases #3195

Merged
merged 5 commits into from
Apr 10, 2021

Conversation

oowekyala
Copy link
Member

@oowekyala oowekyala commented Apr 4, 2021

Describe the PR

Update UnnecessaryReturn. The rule is more general than before, so I guess there will be fps to find out. But it will also be much more useful. Namely it now checks return statements in initializers, constructors, and lambdas properly. Also it doesn't flag just a return statement at the very end of a method, which is exceedingly rare and useless, but recurses to find out whether we're at the end of the control flow graph of the method. So it should handle arbitrarily complex code.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)
  • Document the improvement somewhere (release notes?)
  • Tests with lambdas

@oowekyala oowekyala added this to the 7.0.0 milestone Apr 4, 2021
@oowekyala oowekyala added this to In progress in PMD 7 via automation Apr 4, 2021
@pmd-test
Copy link

pmd-test commented Apr 4, 2021

2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 129 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 2969 violations,
introduces 8182 new violations, 1 new errors and 0 new configuration errors,
removes 15645 violations, 10 errors and 2 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 138 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 2969 violations,
introduces 8191 new violations, 1 new errors and 0 new configuration errors,
removes 15645 violations, 10 errors and 2 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 11717 new violations, 633 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 1240 violations,
introduces 13059 new violations, 631 new errors and 0 new configuration errors,
removes 159111 violations, 7 errors and 2 configuration errors.
Full report

Generated by 🚫 Danger

@oowekyala oowekyala marked this pull request as ready for review April 4, 2021 23:01
@adangel adangel added the an:enhancement An improvement on existing features / rules label Apr 10, 2021
@adangel adangel changed the title [java] Update rule UnnecessaryReturn [java] Improve rule UnnecessaryReturn to detect more cases Apr 10, 2021
Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mention this PR in the release notes for 7.0.0

/**
* Returns true if the node is the last child of its parent (or is the root node).
*/
public static boolean isLastChild(Node it) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a candidate for Node itself... But that's for a separate PR/issue (Node API)

adangel added a commit that referenced this pull request Apr 10, 2021
adangel added a commit that referenced this pull request Apr 10, 2021
[java] Improve rule UnnecessaryReturn to detect more cases #3195
@adangel adangel merged commit b23330d into pmd:pmd/7.0.x Apr 10, 2021
PMD 7 automation moved this from In progress to Done Apr 10, 2021
@oowekyala oowekyala deleted the update-UnnecessaryReturn branch April 10, 2021 17:47
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
an:enhancement An improvement on existing features / rules
Projects
No open projects
PMD 7
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants