Skip to main content

LiquidComplexity

Identifies Liquid files whose cyclomatic complexity is greater than the configured maxComplexity. Liquid complexity starts at 1 for each file and increases for each of the following:

  • Branching or looping tags: if, unless, case, for, tablerow, and paginate.
  • elsif and when branches.
  • Logical and and or expressions inside control-flow conditions.

Reducing complexity helps keep theme files easier to understand and maintain. When a file exceeds the configured maximum, simplify the conditional logic or move self-contained decision logic into snippets that are rendered from the original file.


The following examples contain code snippets that either fail or pass this check.

In the following example, the file has a complexity of 7. It fails when maxComplexity is set to 4:

{% if filter.type == 'list' and filter.values.size > 0 %}
{% for value in filter.values %}
{% if value.active %}
{{ value.label }}
{% elsif value.count > 0 or value.param_name == 'availability' %}
{{ value.label }}
{% endif %}
{% endfor %}
{% endif %}

In the following example, repeated output and assignment logic doesn't add branching complexity:

{% assign has_filters = filter.values.size > 0 %}
{% assign should_show_filter = has_filters and filter.active_values.size > 0 %}

{{ filter.label }}
{{ should_show_filter }}

The following example contains the default configuration for this check:

LiquidComplexity:
enabled: true
severity: warning
maxComplexity: 120
ParameterDescription
enabledWhether this check is enabled.
severityThe severity of the check.
maxComplexityThe maximum allowed Liquid complexity for a single file.

Anchor to Disabling this checkDisabling this check

This check is safe to disable.


Was this page helpful?