OpenRewrite recipe best practices
MSALBest practices for OpenRewrite recipe development.
org. openrewrite. recipes. rewrite. OpenRewriteRecipeBestPracticesmod run . --recipe= org. openrewrite. recipes. rewrite. OpenRewriteRecipeBestPracticesInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Append to text file
- Inline calls to deprecated OpenRewrite methods
- Get data table rows by class
- Find visitor instances shared across
getVisitor()calls - Find LST elements converted to strings
- Java Recipe best practices
- Recipe testing best practices
- Recipe nullability best practices
- Declarative recipe best practices
- Remove elements annotated with
@ToBeRemovedpast their date - Migrate tests to Java 25
- Remove test Java parsers provided by the build plugin
- Delete files
{,**/}src/main/resources/META-INF/rewrite/examples.yml - Remove the generated
InlineDeprecatedMethodsrecipe - Order imports
- Remove unused imports
- Simplify single-element annotation
- End files with a single newline
- Remove trailing whitespace
- Inline variable
- Operator wrapping
- Remove unused local variables
- Remove unused private fields
- Remove unused private methods
- Unwrap else block after return or throw statement
- Equals avoids null
- Add missing
@Overrideto overriding and implementing methods - Week Year (YYYY) should not be used for date formatting
hashCode()should not be called on array instances- Remove
toString()calls on arrays - Replace
Object.notify()withObject.notifyAll() - Remove garbage collection invocations
- Remove
Object.finalize()invocations URL#equals()andURL#hashCode()- Find ignored results of
@CheckReturnValuemethods - Simplify lambda blocks to expressions
- Use method references in lambda
- Use the diamond operator
- Remove unnecessary parentheses
- Remove redundant null checks before
instanceof - Replace
StringBuilder#appendwithString - Use
Collectioninterfaces - Enum values should be compared with
== - Combine semantically equal catch blocks
- Use
String::replace()when first parameter is not a real regular expression - Use
StandardCharsetsconstants - Use
System.lineSeparator() - Remove redundant casts
- Replace invocations of
Collections#sort(List, Comparator)withList#sort(Comparator) - Use
String.contentEquals(CharSequence)instead ofString.equals(CharSequence.toString()) - Use static import
java.util.stream.Collectors *(..) - Use static import
java.util.Collections *(..)