Skip to content

redundant-json-script-id

Added in NEXT_DJANGOFMT_VERSION · Related issues · View source

Fix is always available.

What it does

Checks for the json_script filter called with an empty element id.

Why is this bad?

json_script renders an id attribute only for a non-empty element id, so json_script:"" emits the same <script> tag as json_script on its own. The argument was mandatory until Django 4.1 made it optional, and since then only adds noise.

The rule is version-gated: it reports nothing until lint.target-version names Django 4.1 or newer, because dropping the argument is a template syntax error on older releases.

Example

{{ user_data|json_script:"" }}

Use instead:

{{ user_data|json_script }}

Options

References