Sha256: 9a40c9db42edd1862ee4ab2218473bb6e4a1c6791c7e7ed38b8eab76fe7bea93

Contents?: true

Size: 1.78 KB

Versions: 28

Compression:

Stored size: 1.78 KB

Contents

# Encourage use of liquid tag for consecutive statements (LiquidTag)

Recommends using `{% liquid ... %}` if 4 or more consecutive liquid tags (`{% ... %}`) are found.

## Check Details

This check is aimed at eliminating repetitive tag markers (`{%` and `%}`) in theme files.

:-1: Example of **incorrect** code for this check:

```liquid
{% if collection.image.size != 0 %}
{%   assign collection_image = collection.image %}
{% elsif collection.products.first.size != 0 and collection.products.first.media != empty %}
{%   assign collection_image = collection.products.first.featured_media.preview_image %}
{% else %}
{%   assign collection_image = nil %}
{% endif %}
```

:+1: Example of **correct** code for this check:

```liquid
{%- liquid
  if collection.image.size != 0
    assign collection_image = collection.image
  elsif collection.products.first.size != 0 and collection.products.first.media != empty
    assign collection_image = collection.products.first.featured_media.preview_image
  else
    assign collection_image = nil
  endif
-%}
```

## Check Options

The default configuration for this check is the following:

```yaml
LiquidTag:
  enabled: true
  min_consecutive_statements: 5
```

### `min_consecutive_statements`

The `min_consecutive_statements` option (Default: `5`) determines the maximum (inclusive) number of consecutive statements before the check recommends a refactor.

## When Not To Use It

It's safe to disable this rule.

## Version

This check has been introduced in Theme Check 0.1.0.

## Resources

- [`{% liquid %}` Tag Reference][liquid]
- [Rule Source][codesource]
- [Documentation Source][docsource]

[liquid]: https://shopify.dev/docs/themes/liquid/reference/tags/theme-tags#liquid
[codesource]: /lib/theme_check/checks/liquid_tag.rb
[docsource]: /docs/checks/liquid_tag.md

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
theme-check-1.15.0 docs/checks/liquid_tag.md
theme-check-1.14.0 docs/checks/liquid_tag.md
theme-check-1.13.0 docs/checks/liquid_tag.md
theme-check-1.12.1 docs/checks/liquid_tag.md
theme-check-1.12.0 docs/checks/liquid_tag.md
theme-check-1.11.0 docs/checks/liquid_tag.md
theme-check-1.10.3 docs/checks/liquid_tag.md
theme-check-1.10.2 docs/checks/liquid_tag.md
theme-check-1.10.1 docs/checks/liquid_tag.md
theme-check-1.10.0 docs/checks/liquid_tag.md
theme-check-1.9.2 docs/checks/liquid_tag.md
theme-check-1.9.1 docs/checks/liquid_tag.md
theme-check-1.9.0 docs/checks/liquid_tag.md
theme-check-1.8.0 docs/checks/liquid_tag.md
theme-check-1.7.2 docs/checks/liquid_tag.md
theme-check-1.7.1 docs/checks/liquid_tag.md
theme-check-1.7.0 docs/checks/liquid_tag.md
theme-check-1.6.2 docs/checks/liquid_tag.md
theme-check-1.6.1 docs/checks/liquid_tag.md
theme-check-1.6.0 docs/checks/liquid_tag.md