form-action-whitespace¶
Added in NEXT_DJANGOFMT_VERSION · Related issues · View source
Fix is always available.
What it does¶
Checks for leading or trailing whitespace in the action attribute of <form> elements.
Why is this bad?¶
The URL parser strips leading and trailing ASCII whitespace when resolving an HTML URL attribute, so the spaces are inert at runtime and only add noise to the source. They are commonly an accidental artefact of inserting a template tag inside the quotes.
Values containing template interpolation are skipped: the surrounding whitespace is usually
intentional padding around a {% url %} tag and cannot be safely trimmed without knowing the
rendered output. Only the action attribute is checked; sibling attributes such as
data-action may legitimately span multiple lines.
Example¶
Use instead:
Fix safety¶
This rule's fix is marked as safe: the URL parser strips leading and trailing ASCII
whitespace from URL attribute values, so trimming the literal source preserves runtime
semantics. Author code reading the raw attribute (e.g. form.getAttribute("action"),
strict-equality dispatch, HTMX or web-component integrations that observe the literal
string) would see the trimmed value, but relying on the surrounding whitespace is
vanishingly rare.