Class: ThemeCheck::RemoteAsset

Inherits:
LiquidCheck show all
Includes:
RegexHelpers
Defined in:
lib/theme_check/checks/remote_asset.rb

Constant Summary collapse

OFFENSE_MESSAGE =
"Asset should be served by the Shopify CDN for better performance."
HTML_FILTERS =
[
  'stylesheet_tag',
  'script_tag',
  'img_tag',
]
ASSET_URL_FILTERS =
[
  'asset_url',
  'asset_img_url',
  'file_img_url',
  'file_url',
  'global_asset_url',
  'img_url',
  'payment_type_img_url',
  'shopify_asset_url',
]
RESOURCE_TAG =
/<(?<tag_name>img|script|link|source)#{HTML_ATTRIBUTES}>/oim
RESOURCE_URL =
/\s(?:src|href)=(?<resource_url>#{QUOTED_LIQUID_ATTRIBUTE})/oim
ASSET_URL_FILTER =
/[\|\s]*(#{ASSET_URL_FILTERS.join('|')})/omi
PROTOCOL =
%r{(https?:)?//}
ABSOLUTE_PATH =
%r{\A/[^/]}im
RELATIVE_PATH =
%r{\A(?!#{PROTOCOL})[^/\{]}oim
REL =
/\srel=(?<rel>#{QUOTED_LIQUID_ATTRIBUTE})/oim

Constants inherited from LiquidCheck

LiquidCheck::ATTR, LiquidCheck::HTML_ATTRIBUTE, LiquidCheck::HTML_ATTRIBUTES, LiquidCheck::QUOTED_LIQUID_ATTRIBUTE, LiquidCheck::START_OR_END_QUOTE, LiquidCheck::TAG, LiquidCheck::VARIABLE

Constants inherited from Check

Check::CATEGORIES, Check::SEVERITIES

Instance Attribute Summary

Attributes inherited from Check

#offenses, #options, #theme

Instance Method Summary collapse

Methods included from RegexHelpers

#matches

Methods inherited from LiquidCheck

#add_offense

Methods included from ChecksTracking

#inherited

Methods included from ParsingHelpers

#outside_of_strings

Methods inherited from Check

all, can_disable, #can_disable?, categories, #categories, category, #code_name, #doc, doc, docs_url, #ignore!, #ignored?, #severity, severity, #to_s, #unignore!

Methods included from JsonHelpers

#format_json_parse_error

Instance Method Details

#on_document(node) ⇒ Object



39
40
41
42
# File 'lib/theme_check/checks/remote_asset.rb', line 39

def on_document(node)
  source = node.template.source
  record_html_offenses(node, source)
end

#on_variable(node) ⇒ Object



35
36
37
# File 'lib/theme_check/checks/remote_asset.rb', line 35

def on_variable(node)
  record_variable_offense(node)
end