Java Recipe best practices

MSAL

Best practices for Java recipe development.

org.openrewrite.java.recipes.JavaRecipeBestPractices
mod run . --recipe=org.openrewrite.java.recipes.JavaRecipeBestPractices

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. Add a blank line around fields with annotations
  2. Correctly spaced descriptions
  3. Use a standard name for ExecutionContext
  4. Find method calls and say what to do instead
  5. Find method calls and say what to do instead
  6. Find method calls and say what to do instead
  7. Find method calls and say what to do instead
  8. Find method calls and say what to do instead
  9. Find method calls and say what to do instead
  10. Inline nested visitor classes into the returning method
  11. Use J.Literal.isLiteralValue(expression, null)
  12. Use ListUtils.filter instead of mapping elements to null
  13. Find missing @Option example values
  14. Recipe classes should not have mutable static fields
  15. Use of @EqualsAndHashCode on Recipe
  16. Recipe classes should be public
  17. Drop redundant conditions around maybeAddImport and maybeRemoveImport
  18. Reorder maybeRemoveImport before maybeAddImport
  19. Make matcher fields static final constants
  20. Replace getDisplayName() and getDescription() methods with fields
  21. Replace getEstimatedEffortPerOccurrence() method with field
  22. Use StringUtils utility methods
  23. Replace getTags() method with field
  24. Use JavaTemplate.apply() static method
  25. Use UsesMethod and DeclaresMethod preconditions with MethodMatchers
  26. Use Tree.randomId() in LST constructors
  27. Use visit with parent cursor when calling from another visitor
  28. Use TreeVisitor#reduce instead of a captured accumulator
  29. Fix missing braces
  30. Remove System.out#println and System.err#println statements
  31. Remove @NlsRewrite annotations from Recipe classes