GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Validate that recipes keep the indentation of lines they edit in place by jkschneider · Pull Request #10090 · openrewrite/rewrite

Conversation

@jkschneider

@jkschneider jkschneider commented Nov 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

A new recipe quality check, keepEditedLineIndentation, on by default: a line that a recipe edits in place keeps its leading whitespace. A line is edited in place when its code changes and the lines around it don't: one line in, one line out, between lines the recipe left alone.

The comparison diffs each result with leading whitespace ignored, so only lines whose code changed are compared. It leaves out:

  • runs of consecutive changed lines, which are usually code that changed shape, such as an if-else chain that became switch cases;
  • a line edited inside code that moved, whose unchanged neighbors changed indentation too;
  • a replacement that shares too little text with the old line to be the same line;
  • the space that aligns a doc comment's *;
  • YAML and Python, whose indentation is structure, binary files, and formatting recipes.

A test opts out with RecipeQualityValidation.builder().keepEditedLineIndentation(false). Two tests here do: a ColdFusion NormalizeFormat test whose ad-hoc recipe moves a removed modifier's space into the function's prefix on purpose, and a Ruby heredoc test of the naive way to replace a body, which drops the body's indentation with its text.

With the system property org.openrewrite.test.keepEditedLineIndentation.shiftedInput, each recipe test also reruns the recipe on its Java and XML sources with one more space at the start of each indented line that opens nothing, and applies the same check. Test inputs are formatted to their style, so a recipe that recomputes a line's indentation from the style produces the expected output; this mode shows it, as hand-indented files do. It is off by default, a measuring tool for sweeping recipe repositories.

The check compares source printed without markers, so a search result printed in front of a line's indentation is not an edit, and it reads whitespace escapes that a line's code starts with as the whitespace they stand for.

The fixes this check needs are merged. Running the recipe tests of 75 openrewrite and moderneinc repositories with it found them:

  • Keep the indentation of code that is replaced or formatted in place #10089, which keeps the indentation of code that JavaTemplate, maybeAutoFormat and AddOrUpdateChild replace or format in place, and the test tidying it needs
  • Keep the indentation of a statement that RemoveUnneededBlock unwraps on its line rewrite-static-analysis#1275: RemoveUnneededBlock keeps the indentation of a statement it unwraps on its line
  • Keep the formatting of the builder chain MigrateRequestConfig extends rewrite-apache#193: MigrateRequestConfig keeps the formatting of the builder chain it extends
  • Indent WebSecurityConfigurerAdapterTest's in-memory configuration inputs like their class rewrite-spring#1323: two WebSecurityConfigurerAdapterTest inputs indented like their class

Three more recipe PRs switch autoFormat to maybeAutoFormat so that those recipes keep a declaration's line too (openrewrite/rewrite-logging-frameworks#338, openrewrite/rewrite-spring#1324, openrewrite/rewrite-static-analysis#1276). A last run over the nine repositories that changed since, with #10089 and this check, found nothing for the check. Tests that need a JavaScript, Python or C# runtime did not run.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-project-automation github-project-automation Bot added this to OpenRewrite Nov 20, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Nov 20, 2026
@moderne-meeseeks moderne-meeseeks Bot assigned jkschneider Nov 20, 2026
This was referenced Nov 20, 2026
Keep the indentation of a statement that RemoveUnneededBlock unwraps on its line openrewrite/rewrite-static-analysis#1275
Merged
Indent UseMapOfTest's double-brace input like its method openrewrite/rewrite-migrate-java#1479
Merged
Indent SystemOutToLoggingTest's doNotDeleteFile input with four spaces openrewrite/rewrite-logging-frameworks#337
Merged
Indent JUnitAssertEqualsToAssertThatTest's custom-class test with four spaces openrewrite/rewrite-testing-frameworks#1343
Merged
Indent WebSecurityConfigurerAdapterTest's in-memory configuration inputs like their class openrewrite/rewrite-spring#1323
Merged
Keep the formatting of the builder chain MigrateRequestConfig extends openrewrite/rewrite-apache#193
Merged
Keep the indentation of code that is replaced or formatted in place #10089
Merged
@jkschneider
jkschneider force-pushed the indent-preservation-check branch from 111bcb6 to ea66c10 Compare November 20, 2026 12:38
@jkschneider
jkschneider changed the base branch from main to template-keep-replaced-indentation November 20, 2026 12:38
This was referenced Nov 20, 2026
Keep the indentation of a logger field whose modifiers ChangeLoggersToPrivate changes openrewrite/rewrite-logging-frameworks#338
Merged
Keep the indentation of a method whose parameter ChangeMethodParameter changes openrewrite/rewrite-spring#1324
Merged
Keep the indentation of declarations FinalizeLocalVariables and MoveFieldAnnotationToType edit in place openrewrite/rewrite-static-analysis#1276
Merged
jkschneider added a commit to openrewrite/rewrite-static-analysis that referenced this pull request Nov 20, 2026
@jkschneider
Keep the indentation of a statement that RemoveUnneededBlock unwraps …
0d20d63
…on its line (#1275)

`RemoveUnneededBlock` formats each statement it moves out of a removed block. A statement that
shared the block's line, as in `{ System.out.println("hello!"); }`, takes the place of the block on
that line but got the indentation the formatter computes instead of the one the line had. It now
keeps the line's indentation. Statements on lines of their own are formatted as before.

The input of
`ReplaceValidateNotNullHavingVarargsWithObjectsRequireNonNullTest#replaceMethodsWithThreeArg`
indented its statement two spaces deeper than the method body, so its expected output depended on
the recipe recomputing the indentation of the line it replaces. It is now indented like the method
body, and the expected output is unchanged.

These prepare for openrewrite/rewrite#10089, which keeps the indentation of a line whose code a
recipe replaces or formats in place, and openrewrite/rewrite#10090, a recipe quality check, on by
default, that a line a recipe edits in place keeps its indentation. The tests pass with the
published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-migrate-java that referenced this pull request Nov 20, 2026
@jkschneider
Indent UseMapOfTest's double-brace input like its method (#1479)
f0cf8b9
The input of `changeDoubleBraceInitForNonStringTypes` indented its double-brace initialization six
spaces deeper than the method around it, so its expected output depended on `UseMapOf` recomputing
the indentation of the line it replaces. Indented like its method, the input gives the same
expected output whether that line keeps its indentation or not.

These prepare for openrewrite/rewrite#10089, which keeps the indentation of a line whose code a
recipe replaces or formats in place, and openrewrite/rewrite#10090, a recipe quality check, on by
default, that a line a recipe edits in place keeps its indentation. The tests pass with the
published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-logging-frameworks that referenced this pull request Nov 20, 2026
@jkschneider
Indent SystemOutToLoggingTest's doNotDeleteFile input with four spaces (
ad0c9c7
#337)

The input of `doNotDeleteFile` was indented with two spaces. Its expected output recorded the
recipe re-indenting the class to four spaces, except the method's closing brace, and the
`System.out.println` line it replaces to eight. With openrewrite/rewrite#10089 that line keeps its
indentation instead. Indented with four spaces, like the expected output, the input gives the same
expected output either way.

When it adds the logger field, `SystemOutToLogging` still re-indents a class indented with two
spaces to four. That is a separate issue.

These prepare for openrewrite/rewrite#10089, which keeps the indentation of a line whose code a
recipe replaces or formats in place, and openrewrite/rewrite#10090, a recipe quality check, on by
default, that a line a recipe edits in place keeps its indentation. The tests pass with the
published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-testing-frameworks that referenced this pull request Nov 20, 2026
@jkschneider
Indent JUnitAssertEqualsToAssertThatTest's custom-class test with fou…
b04fd48
…r spaces (#1343)

`shouldImportWhenCustomClassIsUsed` was indented with two spaces, and its expected output recorded
the replaced assertion at six, two spaces deeper than the method body. With
openrewrite/rewrite#10089 a line whose code a `JavaTemplate` replaces keeps its indentation.
Indented with four spaces, the test expects the same output either way.

These prepare for openrewrite/rewrite#10089, which keeps the indentation of a line whose code a
recipe replaces or formats in place, and openrewrite/rewrite#10090, a recipe quality check, on by
default, that a line a recipe edits in place keeps its indentation. The tests pass with the
published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-spring that referenced this pull request Nov 20, 2026
@jkschneider
Indent WebSecurityConfigurerAdapterTest's in-memory configuration inp…
4e4d537
…uts like their class (#1323)

The inputs of `inMemoryConfig` and `inMemoryConfigWithUserBuilder` indented `configure` two spaces
deeper than its annotation, and the `auth.inMemoryAuthentication()` statement two spaces deeper
than the statement before it. Their expected outputs recorded the recipe recomputing the
indentation of the `return` statement that replaces that line, which the quality check in
openrewrite/rewrite#10090 rejects. Indented like their class, the inputs give the same expected
outputs.

These prepare for openrewrite/rewrite#10089, which keeps the indentation of a line whose code a
recipe replaces or formats in place, and openrewrite/rewrite#10090, a recipe quality check, on by
default, that a line a recipe edits in place keeps its indentation. The tests pass with the
published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-apache that referenced this pull request Nov 20, 2026
@jkschneider
Keep the formatting of the builder chain MigrateRequestConfig extends (…
dea73a7
…#193)

`MigrateRequestConfig` appends `.setConnectionManager(...)` to an `HttpClientBuilder` chain with a
`JavaTemplate` whose argument is the chain, and the template re-formatted the chain. In the test,
`.setDefaultRequestConfig(requestConfig)` moved from 12 spaces to 16 while `.build()` below it
stayed at 12. The recipe now puts back the chain as it was written, so the line keeps its
indentation.

These prepare for openrewrite/rewrite#10089, which keeps the indentation of a line whose code a
recipe replaces or formats in place, and openrewrite/rewrite#10090, a recipe quality check, on by
default, that a line a recipe edits in place keeps its indentation. The tests pass with the
published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-logging-frameworks that referenced this pull request Nov 20, 2026
@jkschneider
Keep the indentation of a logger field whose modifiers ChangeLoggersT…
ef260d0
…oPrivate changes (#338)

`ChangeLoggersToPrivate` formatted the field whose modifiers it changes with `autoFormat`, which
gives the declaration's line the indentation of a file formatted from scratch. In a file indented
by hand, or with tabs among spaces, that moves a line the recipe only edited. `maybeAutoFormat`
formats the same way, and with openrewrite/rewrite#10089 it keeps the indentation of the line where
a declaration it changes stays. Until that is released, the output is unchanged.

Found by running the tests of `ChangeLoggersToPrivate` and `Slf4jBestPractices` with one more space
at the start of each indented line that opens nothing, the opt-in shifted-input mode of
openrewrite/rewrite#10090. With openrewrite/rewrite#10089 the mode flagged 7 of those tests before
this change and none after. The tests pass with the published rewrite snapshot and with both of
those changes.
jkschneider added a commit to openrewrite/rewrite-spring that referenced this pull request Nov 20, 2026
@jkschneider
Keep the indentation of a method whose parameter ChangeMethodParamete…
353edbe
…r changes (#1324)

`ChangeMethodParameter` formatted the method whose parameter it changes with `autoFormat`, which
gives the declaration's line the indentation of a file formatted from scratch. In a file indented
by hand, or with tabs among spaces, that moves a line the recipe only edited. `maybeAutoFormat`
formats the same way, and with openrewrite/rewrite#10089 it keeps the indentation of the line where
a declaration it changes stays. Until that is released, the output is unchanged.

Found by running the tests of `ChangeMethodParameter` with one more space at the start of each
indented line that opens nothing, the opt-in shifted-input mode of openrewrite/rewrite#10090. With
openrewrite/rewrite#10089 the mode flagged 16 of `ChangeMethodParameter`'s tests before this change
and none after. The tests pass with the published rewrite snapshot and with both of those changes.
jkschneider added a commit to openrewrite/rewrite-static-analysis that referenced this pull request Nov 20, 2026
@jkschneider
Keep the indentation of declarations FinalizeLocalVariables and MoveF…
593cbe9
…ieldAnnotationToType edit in place (#1276)

`FinalizeLocalVariables` and `MoveFieldAnnotationToType` formatted the declaration they change with
`autoFormat`, which gives the declaration's line the indentation of a file formatted from scratch.
In a file indented by hand, or with tabs among spaces, that moves a line the recipe only edited.
`maybeAutoFormat` formats the same way, and with openrewrite/rewrite#10089 it keeps the indentation
of the line where a declaration it changes stays. Until that is released, the output is unchanged.

Found by running the tests of `FinalizeLocalVariables` and `MoveFieldAnnotationToType` with one
more space at the start of each indented line that opens nothing, the opt-in shifted-input mode of
openrewrite/rewrite#10090. With openrewrite/rewrite#10089 the mode flagged 10 of those tests (7 of
`FinalizeLocalVariables`, 3 of `MoveFieldAnnotationToType`) before this change and none after. The
tests pass with the published rewrite snapshot and with both of those changes.
@jkschneider
jkschneider force-pushed the template-keep-replaced-indentation branch from 921f255 to e2f982d Compare November 20, 2026 13:34
@jkschneider
jkschneider force-pushed the indent-preservation-check branch from 44863d2 to 03ae33c Compare November 20, 2026 13:34
Base automatically changed from template-keep-replaced-indentation to main November 20, 2026 13:50
jkschneider added 3 commits November 20, 2026 08:50
@jkschneider
Validate that recipes keep the indentation of lines they edit in place
90e491f
A new recipe quality check, keepEditedLineIndentation, on by default: a line that a recipe edits in place, one line
in and one line out between lines it left alone, keeps its leading whitespace. Code that replaces the first element
on a line takes over the prefix of the element it replaced.

The comparison diffs each result's text with leading whitespace ignored, so only lines whose code changed are
compared. It leaves out runs of consecutive changed lines, which are usually code that changed shape; lines edited
inside code that moved, whose unchanged neighbors changed indentation too; replacements that share too little text
with the old line to be the same line; the space that aligns a doc comment's star; YAML and Python, whose indentation
is structure; binary files; and formatting recipes.
@jkschneider
Find recipes that recompute the indentation of what they edit, on demand
aa95543
With the system property org.openrewrite.test.keepEditedLineIndentation.shiftedInput set, each recipe test reruns the
recipe on the Java and XML sources it changed with one more space at the start of each line that opens nothing, and
checks the lines it edits in place against that input. Test inputs are formatted to their style, so a recipe that
formats what it changes, or builds a prefix from the style, gets the expected output; a statement one space deeper
than its parent plus the style's unit shows it, as hand-indented files do. Off by default: a measuring tool for
sweeping recipe repositories.
@jkschneider
Compare the source without the markers a printer shows in front of in…
4f767fb
…dentation

A search result on plain text prints in front of the line's leading whitespace, so a search recipe looked like it
reindented the line it found. The indentation checks now compare the source as it is written.
jkschneider added 3 commits November 20, 2026 08:50
@jkschneider
Read whitespace a recipe spells as escapes as that whitespace
b3da992
A recipe that escapes the tabs a text block line starts with keeps the line's whitespace, spelled differently, so the
indentation check reads the escapes a line's code starts with as the whitespace they stand for.
@jkschneider
Opt a NormalizeFormat test out of the edited-line indentation check
244ed5e
The test removes a modifier and checks that normalizing moves its space into the function's prefix, which deepens
the line on purpose.
@jkschneider
Opt a heredoc test out of the edited-line indentation check
29b883f
The test replaces a heredoc body with a quoted literal the naive way, dropping the body's indentation with its
text, to check that the terminator still starts its own line.
@jkschneider
jkschneider force-pushed the indent-preservation-check branch from 03ae33c to 29b883f Compare November 20, 2026 13:50
@jkschneider
jkschneider marked this pull request as ready for review November 20, 2026 13:52
@jkschneider
jkschneider merged commit e3ce456 into main Nov 20, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

@jkschneider
jkschneider deleted the indent-preservation-check branch November 20, 2026 13:52
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@jkschneider jkschneider

Labels

None yet

Projects

OpenRewrite
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@jkschneider
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.