← All recipes
Moderne licensed

Prefer `startswith/endswith` over slice comparison

Recipe IDorg.openrewrite.python.cleanup.StrPrefixSuffixArtifactopenrewrite-static-analysis

Rewrite `s[:N] == "lit" as s.startswith("lit") and s[-N:] == "lit" as s.endswith("lit")` when the slice length equals the literal length.

Single recipeProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.python.cleanup.StrPrefixSuffix

If the recipe isn’t available locally, install it with:

mod config recipes pip install openrewrite-static-analysis