OpenRewrite recipe best practices

MSAL

Best practices for OpenRewrite recipe development.

org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices
mod run . --recipe=org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices

Install 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.

  1. Append to text file
  2. Inline calls to deprecated OpenRewrite methods
  3. Get data table rows by class
  4. Find visitor instances shared across getVisitor() calls
  5. Find LST elements converted to strings
  6. Java Recipe best practices
  7. Recipe testing best practices
  8. Recipe nullability best practices
  9. Declarative recipe best practices
  10. Remove elements annotated with @ToBeRemoved past their date
  11. Migrate tests to Java 25
  12. Remove test Java parsers provided by the build plugin
  13. Delete files {,**/}src/main/resources/META-INF/rewrite/examples.yml
  14. Remove the generated InlineDeprecatedMethods recipe
  15. Order imports
  16. Remove unused imports
  17. Simplify single-element annotation
  18. End files with a single newline
  19. Remove trailing whitespace
  20. Inline variable
  21. Operator wrapping
  22. Remove unused local variables
  23. Remove unused private fields
  24. Remove unused private methods
  25. Unwrap else block after return or throw statement
  26. Equals avoids null
  27. Add missing @Override to overriding and implementing methods
  28. Week Year (YYYY) should not be used for date formatting
  29. hashCode() should not be called on array instances
  30. Remove toString() calls on arrays
  31. Replace Object.notify() with Object.notifyAll()
  32. Remove garbage collection invocations
  33. Remove Object.finalize() invocations
  34. URL#equals() and URL#hashCode()
  35. Find ignored results of @CheckReturnValue methods
  36. Simplify lambda blocks to expressions
  37. Use method references in lambda
  38. Use the diamond operator
  39. Remove unnecessary parentheses
  40. Remove redundant null checks before instanceof
  41. Replace StringBuilder#append with String
  42. Use Collection interfaces
  43. Enum values should be compared with ==
  44. Combine semantically equal catch blocks
  45. Use String::replace() when first parameter is not a real regular expression
  46. Use StandardCharsets constants
  47. Use System.lineSeparator()
  48. Remove redundant casts
  49. Replace invocations of Collections#sort(List, Comparator) with List#sort(Comparator)
  50. Use String.contentEquals(CharSequence) instead of String.equals(CharSequence.toString())
  51. Use static import java.util.stream.Collectors *(..)
  52. Use static import java.util.Collections *(..)