Sha256: ae337c137a0ec28dde73358eed50324ad156d882031c9412a189a3ea58eef7e9

Contents?: true

Size: 603 Bytes

Versions: 3

Compression:

Stored size: 603 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"]&.value&.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

3 entries across 3 versions & 1 rubygems

Version Path
theme-check-1.2.0 lib/theme_check/checks/img_lazy_loading.rb
theme-check-1.1.0 lib/theme_check/checks/img_lazy_loading.rb
theme-check-1.0.0 lib/theme_check/checks/img_lazy_loading.rb