---
title: LiquidComplexity
description: Reports Liquid files with high cyclomatic complexity.
source_url:
  html: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-complexity
  md: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-complexity.md
api_name: liquid
---

# Liquid​Complexity

Identifies Liquid files whose cyclomatic complexity is greater than the configured [`maxComplexity`](#options). 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.

***

## Examples

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

### ✗ Fail

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

```liquid
{% 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 %}
```

### ✓ Pass

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

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


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

***

## Options

The following example contains the default configuration for this check:

```yaml
LiquidComplexity:
  enabled: true
  severity: warning
  maxComplexity: 120
```

| Parameter | Description |
| - | - |
| `enabled` | Whether this check is enabled. |
| `severity` | The [severity](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#check-severity) of the check. |
| `maxComplexity` | The maximum allowed Liquid complexity for a single file. |

***

## Disabling this check

This check is safe to [disable](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration).

***
