Class: ThemeCheck::AssetSizeCSSStylesheetTag

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

Constant Summary

Constants included from RegexHelpers

RegexHelpers::START_OR_END_QUOTE, RegexHelpers::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 RegexHelpers

#href_to_file_size, #matches

Methods included from ChecksTracking

#inherited

Methods included from ParsingHelpers

#outside_of_strings

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

Constructor Details

#initialize(threshold_in_bytes: 100_000) ⇒ AssetSizeCSSStylesheetTag

Returns a new instance of AssetSizeCSSStylesheetTag.



9
10
11
# File 'lib/theme_check/checks/asset_size_css_stylesheet_tag.rb', line 9

def initialize(threshold_in_bytes: 100_000)
  @threshold_in_bytes = threshold_in_bytes
end

Instance Method Details

#on_variable(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/theme_check/checks/asset_size_css_stylesheet_tag.rb', line 13

def on_variable(node)
  used_filters = node.value.filters.map { |name, *_rest| name }
  return unless used_filters.include?("stylesheet_tag")
  file_size = href_to_file_size('{{' + node.markup + '}}')
  return if file_size <= @threshold_in_bytes
  add_offense(
    "CSS on every page load exceeding compressed size threshold (#{@threshold_in_bytes} Bytes).",
    node: node
  )
end