Class: ThemeCheck::DeprecateLazysizes

Inherits:
HtmlCheck show all
Defined in:
lib/theme_check/checks/deprecate_lazysizes.rb

Constant Summary

Constants inherited from HtmlCheck

HtmlCheck::START_OR_END_QUOTE

Constants inherited from Check

Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES

Instance Attribute Summary

Attributes inherited from Check

#ignored_patterns, #offenses, #options, #theme

Instance Method Summary collapse

Methods included from ChecksTracking

#inherited

Methods inherited from Check

#==, #add_offense, all, can_disable, #can_disable?, categories, #categories, category, #code_name, doc, #doc, docs_url, #ignore!, #ignored?, #severity, severity, #severity=, #severity_value, severity_value, single_file, #single_file?, #to_s, #whole_theme?

Methods included from JsonHelpers

#format_json_parse_error, #pretty_json

Instance Method Details

#on_img(node) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/theme_check/checks/deprecate_lazysizes.rb', line 8

def on_img(node)
  class_list = node.attributes["class"]&.split(" ")
  has_loading_lazy = node.attributes["loading"] == "lazy"
  has_native_source = node.attributes["src"] || node.attributes["srcset"]
  return if has_native_source && has_loading_lazy
  has_lazysize_source = node.attributes["data-srcset"] || node.attributes["data-src"]
  has_lazysize_class = class_list&.include?("lazyload")
  return unless has_lazysize_class && has_lazysize_source
  add_offense("Use the native loading=\"lazy\" attribute instead of lazysizes", node: node) if class_list&.include?("lazyload")
end