Skip to content

no-repeated-structured-string-literal

Exact SQL or route literals repeated across callable scopes should share one named binding.

Why

When exact copies represent one SQL, route, or protocol contract, editing one copy can silently diverge the others. Identical text can also represent independent concepts, so this rule is advisory.

Fix

If the occurrences are one maintained concept, reuse an existing constant or extract a descriptive module-level constant within that ownership boundary. If equality is intentional but ownership is independent, suppress with a rationale.

Examples

Before — flagged SQL literal is copied across functions
queries.py
def load(cursor):
cursor.execute("SELECT id, name, created_at FROM organization")
def refresh(cursor):
cursor.execute("SELECT id, name, created_at FROM organization")
After — preferred Functions reuse one SQL constant
queries.py
_SELECT_ORGANIZATIONS = "SELECT id, name, created_at FROM organization"
def load(cursor):
cursor.execute(_SELECT_ORGANIZATIONS)
def refresh(cursor):
cursor.execute(_SELECT_ORGANIZATIONS)

Formerly: no-repeated-string-literal