-
Notifications
You must be signed in to change notification settings - Fork 90
732: Remove trailing whitespace #733
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
base: main
Are you sure you want to change the base?
Conversation
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceVisitor.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespace.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
…tespace.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveTrailingWhitespaceTest.java
Show resolved
Hide resolved
| input.append("Line ").append(i); | ||
| expected.append("Line ").append(i); | ||
|
|
||
| // Add i spaces as trailing whitespace | ||
| for (int j = 0; j < i; j++) { | ||
| input.append(" "); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| input.append("Line ").append(i); | |
| expected.append("Line ").append(i); | |
| // Add i spaces as trailing whitespace | |
| for (int j = 0; j < i; j++) { | |
| input.append(" "); | |
| } | |
| input.append("Line ").append(i).repeat(" ", i); | |
| expected.append("Line ").append(i); |
Java 21 has this new repeat method on StringBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in Java 11, IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant: the tests run in Java 21, so this could be used here, no?
|
|
||
| @Override | ||
| public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
| return new PlainTextVisitor<ExecutionContext>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A PlainTextVisitor does not act on Java files. If you would want to "downcast" the Java lst as a text lst, you could build a generic TreeVisitor that does that conversion.
In this case though you do not want to do that as you will loose all rich information of the lst and every recipe that should run on java files after this one will not make any changes as the Lst's at that moment are no longer JavaSourceFiles but PlainText Sourcefiles causing the isAcceptable of the JavaVisitor to skip the converted files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…tespaceTest.java Co-authored-by: Jente Sondervorst <[email protected]>
What's changed?
Recipe to remove trailing whitespace
What's your motivation?
Fixes #732
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 in openrewrite/rewrite.
Checklist