Skip to content

Conversation

@guptapratykshh
Copy link
Contributor

#18197

The default indentation check configuration doesn't correctly assess indentation for line-wrapped expressions in return statements. As a result, it misses indentation violations in these expressions. In contrast, the same violations are properly identified when the expression is stored in an intermediate variable.

this code shows the issue-

public static int workingIndentationCheck() {
    var intermediate = 1
            + 1
    + 1 // ✓ Violation correctly detected: '+' has incorrect indentation level 4, expected level should be 16
                    + 1 // ✓ Violation correctly detected: '+' has incorrect indentation level 24, expected level should be 16
                + 1; // ✓ Violation correctly detected: '+' has incorrect indentation level 20, expected level should be 16
    return intermediate;
}

public static int failingIndentationCheck() {
    return 1
            + 1
    + 1 // ✗ Incorrect violation message: "'method def' child has incorrect indentation level 4, expected level should be 16" (should be '+')
                    + 1 // ✗ Missing violation (indent should be 16)
                + 1; // ✗ Missing violation (indent should be 16)
}

I modified the BlockParentHandler class to add special handling for return statements with line-wrapped expressions. The fix:
Detects when a return statement's expression spans multiple lines
Uses checkWrappingIndentation() to properly check continuation lines
Ensures error messages show the operator name (via LineWrappingHandler.logWarningMessage() which uses currentNode.getText())

@guptapratykshh guptapratykshh force-pushed the fix-indentation-return-statement-18197 branch from 643939a to 3503820 Compare December 12, 2025 17:24
@romani
Copy link
Member

romani commented Dec 14, 2025

please work on CI failures
and without waiting us do diff testing to spot any unwanted regressions
https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#executing-generation

@guptapratykshh guptapratykshh force-pushed the fix-indentation-return-statement-18197 branch 17 times, most recently from 38508ad to f680391 Compare December 16, 2025 06:17
@guptapratykshh guptapratykshh force-pushed the fix-indentation-return-statement-18197 branch from f680391 to 641addd Compare December 22, 2025 14:19
@romani
Copy link
Member

romani commented Dec 26, 2025

ci is red, please run "mvn clean verify" on local before pushing to github

@guptapratykshh guptapratykshh force-pushed the fix-indentation-return-statement-18197 branch 8 times, most recently from 5b4a932 to da2f87f Compare December 27, 2025 19:28
@guptapratykshh guptapratykshh force-pushed the fix-indentation-return-statement-18197 branch from da2f87f to 24808e5 Compare December 27, 2025 19:30
@romani
Copy link
Member

romani commented Dec 29, 2025

Keep focus of making CI green

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.

2 participants