Skip to content

[java] Fix #5770: New Rule: VariableCanBeInlined#5847

Merged
adangel merged 4 commits intopmd:mainfrom
Pankraz76:deprecate_UnnecessaryLocalBefore
Aug 15, 2025
Merged

[java] Fix #5770: New Rule: VariableCanBeInlined#5847
adangel merged 4 commits intopmd:mainfrom
Pankraz76:deprecate_UnnecessaryLocalBefore

Conversation

@Pankraz76
Copy link
Copy Markdown
Contributor

@Pankraz76 Pankraz76 commented Jun 23, 2025

Fix #5770: [java] UnnecessaryLocalBeforeReturnOrThrowsRule

evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeReturnOrThrowsRule.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from c8bfc98 to fa07c3c Compare June 23, 2025 12:24
@Pankraz76 Pankraz76 marked this pull request as ready for review June 23, 2025 12:32
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 23, 2025

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 185 new violations, 0 new errors and 0 new configuration errors,
removes 153 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-08-08 10:06:18+00:00 for d5e111a)

@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from fa07c3c to df87f06 Compare June 23, 2025 20:22
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml
Comment thread pmd-java/src/main/resources/rulesets/java/quickstart.xml Outdated
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] UnnecessaryLocalBeforeRule Fix #5770: [java] UnnecessaryLocalBeforeReturnOrThrowsRule Jun 29, 2025
@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from e3fd927 to e6f5266 Compare June 29, 2025 11:10
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] UnnecessaryLocalBeforeReturnOrThrowsRule Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeReturnOrThrowsRule Jun 29, 2025
@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from cf0e12e to 6d31e91 Compare June 29, 2025 11:12
@Pankraz76 Pankraz76 requested a review from adangel June 29, 2025 11:12
Comment thread docs/pages/release_notes.md Outdated
@oowekyala
Copy link
Copy Markdown
Member

oowekyala commented Jun 29, 2025

I think the new name is too specific because this rule could as well apply to yield statements. I think the best applicable names would be UnnecessaryLocalBeforeBranch or UnnecessaryLocalBeforeJump

Or even BeforeControlFlowTransfer if you think those are too obscure. I would think people know what a jump is though.

@Pankraz76
Copy link
Copy Markdown
Contributor Author

I think the new name is too specific because this rule could as well apply to yield statements. I think the best applicable names would be UnnecessaryLocalBeforeBranch or UnnecessaryLocalBeforeJump

Or even BeforeControlFlowTransfer if you think those are too obscure. I would think people know what a jump is though.

thanks for the yield case.

Yes then might use Branch, as its known from test coverage tools too, also this was the initial suggestion.

Branch is generic and known in the dev context.

@Pankraz76 Pankraz76 changed the title Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeReturnOrThrowsRule Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeBranch Jun 30, 2025
@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from e703fd7 to 7538251 Compare June 30, 2025 11:44
@adangel
Copy link
Copy Markdown
Member

adangel commented Jul 8, 2025

Let's first fix specification before continuing on the pull request, so that we know, what to do: #5770

@Pankraz76 Pankraz76 marked this pull request as draft July 20, 2025 16:40
@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from d5111fa to c9a957b Compare August 8, 2025 09:02
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] evolute UnnecessaryLocalBeforeReturnRule to UnnecessaryLocalBeforeBranch Fix #5770: [java] migrate UnnecessaryLocalBeforeReturnRule and UnnecessaryLocalBeforeBranch into VariableCanBeInlined Aug 8, 2025
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] migrate UnnecessaryLocalBeforeReturnRule and UnnecessaryLocalBeforeBranch into VariableCanBeInlined Fix #5770: [java] VariableCanBeInlined Aug 8, 2025
@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from c9a957b to de5e6d5 Compare August 8, 2025 09:24
@Pankraz76
Copy link
Copy Markdown
Contributor Author

check issue:

again broken window effect still not closed.

[INFO] There are 2 errors reported by Checkstyle 10.26.1 with /net/sourceforge/pmd/pmd-checkstyle-config.xml ruleset.
[ERROR] src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/VariableCanBeInlinedRule.java:[1] (header) RegexpHeader: Line does not match expected header line of '^/*$'.
[ERROR] src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/VariableCanBeInlinedTest.java:[1] (header) RegexpHeader: Line does not match expected header line of '^/*$'.
[INFO] ------------------------------------------------------------------------

@Pankraz76 Pankraz76 marked this pull request as ready for review August 8, 2025 09:46
@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch 2 times, most recently from 422d5aa to d5e111a Compare August 8, 2025 09:49
@adangel adangel changed the title Fix #5770: [java] VariableCanBeInlined Fix #5770: [java] New Rule: VariableCanBeInlined Aug 11, 2025
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Aug 11, 2025
Copy link
Copy Markdown
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.

Thanks for the updated PR!

Unfortunately, it is not ready yet, but almost! Can you please have a look?

And don't worry about the release notes, I'll update it once the PR is ready to be merged.

Comment thread docs/pages/release_notes.md Outdated
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Outdated
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Outdated
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Outdated
@pmd-actions-helper
Copy link
Copy Markdown
Contributor

pmd-actions-helper Bot commented Aug 11, 2025

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 185 new violations, 0 new errors and 0 new configuration errors,
removes 153 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-08-15 09:46:47+00:00 for a2eb2e4)

@Pankraz76 Pankraz76 force-pushed the deprecate_UnnecessaryLocalBefore branch from e7140d2 to 728d0e4 Compare August 11, 2025 19:51
@Pankraz76 Pankraz76 requested a review from adangel August 12, 2025 07:54
@Pankraz76 Pankraz76 changed the title Fix #5770: [java] New Rule: VariableCanBeInlined Fix #5770: [java] New Rule: VariableCanBeInlined Aug 12, 2025
@adangel adangel changed the title Fix #5770: [java] New Rule: VariableCanBeInlined Fix #5770: [java] New Rule: VariableCanBeInlined Aug 15, 2025
Copy link
Copy Markdown
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've updated the PR myself (you seem to have not noticed the comments in the middle?).

If CI looks good, I'll merge it later today.

Comment thread pmd-java/src/main/resources/category/java/codestyle.xml
Comment thread pmd-java/src/main/resources/rulesets/java/quickstart.xml Outdated
Comment thread pmd-java/src/main/resources/category/java/codestyle.xml Outdated
@adangel adangel added this to the 7.17.0 milestone Aug 15, 2025
@adangel adangel merged commit 2010efe into pmd:main Aug 15, 2025
12 checks passed
@adangel adangel changed the title Fix #5770: [java] New Rule: VariableCanBeInlined [java] Fix #5770: New Rule: VariableCanBeInlined Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] New Rule: VariableCanBeInlined: Local variables should not be declared and then immediately returned or thrown

3 participants