openrewrite / rewrite

Automated mass refactoring of source code.

Home Page:https://docs.openrewrite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ChangePropertyValue regex does not allow for multiple replacements of same regex pattern.

Jenson3210 opened this issue · comments

What problem are you trying to solve?

In yaml’s ChangePropertyValue I am having issues finding the correct regex that works.
Based on this line, it should replace all occurences of the regex with its replacement.
However, replacement is not triggered as this matchesOldValue condition, renders false.

Besides that, I found that the properties recipe behaves similar to yaml recipe, but does not have the same checks/safeties built-in.

Describe the solution you'd like

Would it be an option if a create PR that accepts another boolean as optional input: eg. partialMatch or partialReplace.
That boolean would trigger for regex and string a contains mechanism instead of equals.
For replacement it would trigger all occurences to be changed for regex and for String (rather than sending back new value)

Have you considered any alternatives or workarounds?

Triggering this recipe multiple times with regex that does prefix/suffix optionals. (but then, how much occurences of the pattern can you have?)

Additional context

Are you interested in contributing this feature to OpenRewrite?

PR is following