Support Postcondition in DeclarativeRecipe

Open
#5,258 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
devtools

Research direction

Start by reading DeclarativeRecipe and the existing Precondition feature to understand how filtering is represented and applied. Define the expected postcondition behavior, including how failed validation discards edits, and identify the tests needed to demonstrate that behavior.

Written by the indexing model from the issue text.

Description

enhancement

What problem are you trying to solve?

The Precondition feature in DeclarativeRecipe is great for filtering out files that are either unsupported or skipped for some other reasons. However, identifying which files a recipe can or cannot migrate isn’t always straightforward. Even if we define a precondition accurately, we might still encounter issues due to bugs in edit recipes or missing type attribution caused by parsing errors.

In such cases, a Postcondition feature would be extremely helpful. Since I know what the expected end state of the code should be, writing a recipe to validate that state is much more straightforward. If the postcondition is not met, I could simply discard the edits for that file.

Why this is important

Consider a scenario where I’m migrating a package with 1,000 files. If my recipe fails to correctly migrate even 10 of those files, running the build or tests post-migration could fail, halting the entire process. To continue, I’d need to manually fix the issues or update the recipe to handle those cases.

Having a Postcondition would allow me to automatically verify and discard edits in problematic files.

Describe the solution you'd like

A postcondition feature for DeclarativeRecipe similar to Precondition.

Are you interested in [contributing this feature to OpenRewrite]

Yes, but I’d appreciate feedback on this feature request before starting any work.

Dominant language
Java
Stars
3.7k
Forks
571
Avg merge
13h 12m
Merged PRs (30d)
261

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openrewrite/rewrite

All issues in openrewrite/rewrite

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.