Mergeable if statements should be combined - RSPEC-S1066#734
Mergeable if statements should be combined - RSPEC-S1066#734olwispe wants to merge 20 commits intoopenrewrite:mainfrom
if statements should be combined - RSPEC-S1066#734Conversation
timtebeek
left a comment
There was a problem hiding this comment.
Great to see @olwispe ! Added some light polish and I've been looking at the changes at scale.
Looking at these two examples I wonder if perhaps we should move the inner if conditional to a new line, and keep the comments in more of their original position.
I've pushed a quick test update that shows a comment lost. What are your thoughts to the above proposal?
|
Thanks for your comments. |
|
This PR is stale because it has been open for 90 days with no activity. Remove |
|
Hi @timtebeek! |
…fStatements.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…fStatements.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…fStatements.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2018f25 to
f0c659e
Compare
Moderne Validation Summary — Apache OrganizationRan Results
Additionally tested individually against Correctness✅ Repos with standard 4-space indentation: All patches look correct. Conditions are properly merged with ❌ Repos with 2-space indentation (e.g., Example (accumulo, 2-space indent): // Before (correct):
if (!extentsToHost.isEmpty()) {
if (...) {
requestTabletHosting(context, extentsToHost.values());
}
}
// After (incorrect — body shifted too far left):
if (!extentsToHost.isEmpty() &&
(...)) {
requestTabletHosting(context, extentsToHost.values()); // should be 8 spaces, got 6
}Root Cause
|
Replace ShiftFormat.indent(-1) with a custom shiftLeft that computes the actual indent difference between the inner and outer if statements. indent(-1) always used the default 4-space indent size, causing broken indentation in repos using 2-space indent (e.g., Apache Accumulo). Add test case for 2-space indentation.
Fix Applied: Indentation bug with non-4-space indentPushed commit Problem
FixReplaced TestAdded |
Co-authored-by: Tim te Beek <timtebeek@gmail.com>
Replace hand-rolled indentation shifting with the existing ShiftFormat.indent() utility from rewrite-java, which properly handles tabs vs spaces based on TabsAndIndentsStyle.
Replace ShiftFormat.indent() with autoFormat(merged, ctx) which delegates indentation correction to the standard formatting pipeline.
What's changed?
This PR implements RSPEC-S1066 which was requested in :
ifstatements should be merged.RSPEC-1066#45What's your motivation?
Among others, help migrate to pattern matching for
instanceofwhen combined withorg.openrewrite.staticanalysis.InstanceOfPatternMatch:Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
@timtebeek
Have you considered any alternatives or workarounds?
Any additional context
Checklist