openrewrite / rewrite-python

OpenRewrite recipes for Python.
Apache License 2.0
12 stars 5 forks source link

Recipe StartsWithEndsWith #69

Closed JLLeitschuh closed 5 months ago

JLLeitschuh commented 5 months ago

Python recipe that merges chains of calls of x.startswith("a") or x.startswtih("ab") to a single call of x.startswith(("a", "ab")).

Signed-off-by: Jonathan Leitschuh Jonathan.Leitschuh@gmail.com

What's changed?

Adds the first Python cleanup recipe!

What's your motivation?

I wanted to try out writing a python recipe to actually fix a simple issue.

Going to be completely honest, found this quite painful to do.

Without a PythonTemplate similar to JavaTemplate as well no working AutoFormat for python, you have to consider all of the formatting manually.

Anything in particular you'd like reviewers to focus on?

Any edge cases that you think I likely missed?

Any additional context

Checklist

JLLeitschuh commented 5 months ago

@JLLeitschuh what about the 3+ argument use cases or where there is already a tuple on one side?

Bah... You're absolutely right. This sounds annoying to deal with 😆 but you're right

JLLeitschuh commented 5 months ago

@shanman190 covered those additional cases too now 😄

JLLeitschuh commented 5 months ago

🎉 first cleanup recipe for python!