Skip to content

Conversation

dsgrieve
Copy link

@dsgrieve dsgrieve commented Sep 8, 2025

What's changed?

Recipe to remove trailing whitespace from plain-text files

What's your motivation?

Resolves #5958

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Patterned after other RemoveTrailingWhitespace recipes

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Sep 8, 2025
@dsgrieve dsgrieve changed the title skeleton for RemoveTrailingWhitespace from plain text files 5958: RemoveTrailingWhitespace from plain text files Sep 8, 2025
Comment on lines +40 to +43
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
""",
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
""",
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Copy link
Member

Choose a reason for hiding this comment

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

As you're seeing from the changes here we already have a recipe specifically for text blocks; no need to cover those in your recipe implementation.

Comment on lines +58 to +61
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\s\s
""",
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\s\s
""",
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\s\s
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Comment on lines +76 to +79
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\s\s
""",
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\s\s
""",
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\s\s
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Comment on lines +94 to +98
\s\s
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\s\s
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
\s\s
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\s\s
\s\s
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\s\s

Comment on lines +119 to +124
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
""",
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
""",
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
Lorem ipsum dolor sit amet, consectetur adipiscing elit,\s\s
\s\s
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

import org.openrewrite.Cursor;
import org.openrewrite.Tree;

public class RemoveTrailingWhitespaceVisitor<P> extends PlainTextVisitor<P> {
Copy link
Member

Choose a reason for hiding this comment

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

There's usually no need to have a separate named & public visitor class; typically you can inline these into the recipe itself.

Copy link
Author

Choose a reason for hiding this comment

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

This follows the established pattern for other RemoveTrailingWhitespace implementations.

Copy link
Member

Choose a reason for hiding this comment

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

Yes we have some outdated patterns lingering; going forward let's start with a minimal public API.

@Test
void removeTrailingFirst() {
rewriteRun(
text(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not fully sure, if this will work, but can you try adding a test which has a java() program?

Copy link
Author

Choose a reason for hiding this comment

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

There is already a RemoveTrailingWhitespace for Java (and a few others).

@greg-at-moderne
Copy link
Contributor

greg-at-moderne commented Sep 8, 2025

In the PR description

Resolves #5958

you can replace it with:

- fixes #5958

Which is more human friendly (issue status shown as icon) and triggers automatic GitHub closing of related issue.

@dsgrieve
Copy link
Author

dsgrieve commented Sep 8, 2025

@dsgrieve dsgrieve closed this Sep 8, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Sep 8, 2025
@dsgrieve dsgrieve deleted the 5958-remove-trailing-whitespace branch September 8, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants