Class: ThemeCheck::ParserBlockingJavaScript

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

Overview

Reports errors when trying to use parser-blocking script tags

Constant Summary

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

#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

Instance Method Details

#on_script(node) ⇒ Object



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

def on_script(node)
  return unless node.attributes["src"]
  return if node.attributes["defer"] || node.attributes["async"] || node.attributes["type"]&.value == "module"

  add_offense("Missing async or defer attribute on script tag", node: node)
end