Sha256: 31c339282836a7db949cb7e437c65acb8af31622a4ff4f3235ba48de68b95bd2

Contents?: true

Size: 596 Bytes

Versions: 24

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  class ImgLazyLoading < HtmlCheck
    severity :suggestion
    categories :html, :performance
    doc docs_url(__FILE__)

    ACCEPTED_LOADING_VALUES = %w[lazy eager]

    def on_img(node)
      loading = node.attributes["loading"]&.downcase
      return if ACCEPTED_LOADING_VALUES.include?(loading)
      if loading == "auto"
        add_offense("Prefer loading=\"lazy\" to defer loading of images", node: node)
      else
        add_offense("Add a loading=\"lazy\" attribute to defer loading of images", node: node)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
theme-check-1.5.1 lib/theme_check/checks/img_lazy_loading.rb
theme-check-1.5.0 lib/theme_check/checks/img_lazy_loading.rb
theme-check-1.4.0 lib/theme_check/checks/img_lazy_loading.rb
theme-check-1.3.0 lib/theme_check/checks/img_lazy_loading.rb