Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

theme-check-disable does not work for ImgWidthAndHeight #242

Closed
dzschille opened this issue Mar 31, 2021 · 4 comments · Fixed by #268
Closed

theme-check-disable does not work for ImgWidthAndHeight #242

dzschille opened this issue Mar 31, 2021 · 4 comments · Fixed by #268
Assignees
Labels
bug Something isn't working

Comments

@dzschille
Copy link

In snippets/product-card-list.liquid i have

<div class="list-view-item__image-wrapper product-card__image-wrapper">
      {% comment %}theme-check-disable{% endcomment %}       <--- works
      {% unless product.featured_media == null%}
      {% comment %}theme-check-enable{% endcomment %}
        {% comment %}theme-check-disable{% endcomment %}     <---- does not work
        <img class="list-view-item__image" src="{{ product.featured_media | img_url: '95x95', scale: 2 }}" alt="{{ product.featured_media.alt }}">
        {% comment %}theme-check-enable{% endcomment %}
      {%endunless%}
</div>

When i run theme-check . i still get for this file this error:

snippets/product-card-list.liquid:23: error: ImgWidthAndHeight: Missing width and height attributes.
	<img class="list-view-item__image" src="{{ product.featured_media | img_url: '95x95', scale: 2 }}" alt="{{ product.fe...
@charlespwd charlespwd added the bug Something isn't working label Mar 31, 2021
@charlespwd
Copy link
Contributor

charlespwd commented Mar 31, 2021

Thanks for the bug report! Looks like a bug in the disable/enable logic for regex based checks.

In the meantime, you should be able to do the following to prevent layout shift in your theme:

<img 
  class="list-view-item__image" 
  src="{{ product.featured_media | img_url: '95x95', scale: 2 }}" 
  alt="{{ product.featured_media.alt }}"
  width="95" 
  height="95"
/>

@dzschille
Copy link
Author

Thank @charlespwd , but hardcode the width and height in this case seems risky to me because img_url preserves the original aspect ratio. So when the original image is not a square the result would look distorted. Or am i missing something?

@charlespwd
Copy link
Contributor

In this case, I believe featured_media.width + height would do!

<img 
  class="list-view-item__image" 
  src="{{ product.featured_media | img_url: '95x95', scale: 2 }}" 
  alt="{{ product.featured_media.alt }}"
  width="{{ product.featured_media.width }}" 
  height="{{ product.featured_media.height }}"
/>

Side note: That's what I actually put in before the edit 😅. I saw 95x95 and forgot about that the AR is maintained. I'm more used to the img_url: '95x' syntax when you want to maintain the aspect-ratio.

@charlespwd charlespwd self-assigned this Apr 19, 2021
charlespwd added a commit that referenced this issue Apr 20, 2021
charlespwd added a commit that referenced this issue Apr 21, 2021
charlespwd added a commit that referenced this issue Apr 21, 2021
charlespwd added a commit that referenced this issue Apr 21, 2021
@charlespwd
Copy link
Contributor

Fixed in 0.8.1.

brew update
brew upgrade theme-check

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants