Replace string slicing with removeprefix/removesuffix

Proprietary

Replace if text.startswith(s): text = text[N:] with text = text.removeprefix(s) and the equivalent endswith pattern with removesuffix (Python 3.9+). It only fires where the type of text resolves to str, the affix is a non-empty literal and the slice has no step, and leaves an elif or a commented if alone.

org.openrewrite.python.cleanup.UseStringRemoveAffix
mod run . --recipe=org.openrewrite.python.cleanup.UseStringRemoveAffix

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.