Skip to content

Issue #33: FinalLocalVariable recipe created #40

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Anmol202005
Copy link
Collaborator

Fixes: #33
Implemented FinalLocalVariable recipe.

@Anmol202005 Anmol202005 marked this pull request as draft July 8, 2025 19:49
@Anmol202005 Anmol202005 marked this pull request as ready for review July 8, 2025 20:01
@Anmol202005
Copy link
Collaborator Author

the recipe currently has partial coverage: When multiple variables are declared together like int a, b, c; and only one of them has a violation, the recipe won't process it.

@Anmol202005
Copy link
Collaborator Author

@rdiachenko kindly review.

@rdiachenko rdiachenko requested a review from timurt July 8, 2025 20:49
import org.openrewrite.java.tree.Space;
import org.openrewrite.marker.Markers;

public class FinalLocalVariable extends Recipe {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please add javadoc

import org.junit.jupiter.api.Test;
import org.openrewrite.Recipe;

public class FinalLocalVariableTest extends AbstractRecipeTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that https://checkstyle.sourceforge.io/checks/coding/finallocalvariable.html#FinalLocalVariable has different params

Can you please add tests covering the following cases to make sure it works correctly

for (String item : items) {
for (int i = 0; i < 10; i++)
public void processData(String data, int count)
final int alreadyFinal
try (FileReader fr = new FileReader(filename)) {
int a, b, c;
items.forEach(item -> System.out.println(item));

If it requires too much rework, let me know

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will apply fixes on the bases of violation report.
None of the param will be helpful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, let me clarify

Not asking to support FinalLocalVariable's params

What I meant is that Checkstyle's FinalLocalVariable might fail for different positions based on the configurations

For example, validateEnhancedForLoopVariable means that the FinalLocalVariable check might fail for for (String item : items) { - will your recipe fix it?

<checkstyle version="10.12.3">
<file name="org/checkstyle/autofix/recipe/finallocalvariable/missingfinal/InputMissingFinal.java">
<error line="5" column="12" severity="error"
message="Use uppercase 'L' for long literals."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error messages seem to be incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement recipe for FinalLocalVariable
2 participants