Class: ThemeCheck::ImgLazyLoading
- 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, HtmlCheck::VARIABLE
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
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
Instance Method Details
#on_img(node) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/theme_check/checks/img_lazy_loading.rb', line 10 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 |