Class: ThemeCheck::ImgLazyLoading

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

Constant Summary collapse

ACCEPTED_LOADING_VALUES =
%w[lazy eager]

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



10
11
12
13
14
# File 'lib/theme_check/checks/img_lazy_loading.rb', line 10

def on_img(node)
  loading = node.attributes["loading"]&.downcase
  return if ACCEPTED_LOADING_VALUES.include?(loading)
  add_offense("Use loading=\"eager\" for images visible in the viewport on load and loading=\"lazy\" for others", node: node)
end