Class: ThemeCheck::Check

Inherits:
Object
  • Object
show all
Includes:
JsonHelpers
Defined in:
lib/theme_check/check.rb

Direct Known Subclasses

JsonCheck, LiquidCheck

Constant Summary collapse

SEVERITIES =
[
  :error,
  :suggestion,
  :style,
]
CATEGORIES =
[
  :liquid,
  :translation,
  :performance,
  :json,
  :performance,
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonHelpers

#format_json_parse_error

Instance Attribute Details

#offensesObject

Returns the value of attribute offenses.



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

def offenses
  @offenses
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/theme_check/check.rb', line 10

def options
  @options
end

#themeObject

Returns the value of attribute theme.



8
9
10
# File 'lib/theme_check/check.rb', line 8

def theme
  @theme
end

Class Method Details

.allObject



27
28
29
# File 'lib/theme_check/check.rb', line 27

def all
  @all ||= []
end

.can_disable(disableable = nil) ⇒ Object



64
65
66
67
68
69
# File 'lib/theme_check/check.rb', line 64

def can_disable(disableable = nil)
  unless disableable.nil?
    @can_disable = disableable
  end
  defined?(@can_disable) ? @can_disable : true
end

.categories(*categories) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/theme_check/check.rb', line 41

def categories(*categories)
  @categories ||= []
  if categories.any?
    unknown_categories = categories.select { |category| !CATEGORIES.include?(category) }
    if unknown_categories.any?
      raise ArgumentError,
        "unknown categories: #{unknown_categories.join(', ')}. Use: #{CATEGORIES.join(', ')}"
    end
    @categories = categories
  end
  @categories
end

.categoryObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/theme_check/check.rb', line 53

def categories(*categories)
  @categories ||= []
  if categories.any?
    unknown_categories = categories.select { |category| !CATEGORIES.include?(category) }
    if unknown_categories.any?
      raise ArgumentError,
        "unknown categories: #{unknown_categories.join(', ')}. Use: #{CATEGORIES.join(', ')}"
    end
    @categories = categories
  end
  @categories
end

.doc(doc = nil) ⇒ Object



55
56
57
58
# File 'lib/theme_check/check.rb', line 55

def doc(doc = nil)
  @doc = doc if doc
  @doc if defined?(@doc)
end

.docs_url(path) ⇒ Object



60
61
62
# File 'lib/theme_check/check.rb', line 60

def docs_url(path)
  "https://github.com/Shopify/theme-check/blob/master/docs/checks/#{File.basename(path, '.rb')}.md"
end

.severity(severity = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/theme_check/check.rb', line 31

def severity(severity = nil)
  if severity
    unless SEVERITIES.include?(severity)
      raise ArgumentError, "unknown severity. Use: #{SEVERITIES.join(', ')}"
    end
    @severity = severity
  end
  @severity if defined?(@severity)
end

Instance Method Details

#can_disable?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/theme_check/check.rb', line 100

def can_disable?
  self.class.can_disable
end

#categoriesObject



76
77
78
# File 'lib/theme_check/check.rb', line 76

def categories
  self.class.categories
end

#code_nameObject



84
85
86
# File 'lib/theme_check/check.rb', line 84

def code_name
  StringHelpers.demodulize(self.class.name)
end

#docObject



80
81
82
# File 'lib/theme_check/check.rb', line 80

def doc
  self.class.doc
end

#ignore!Object



88
89
90
# File 'lib/theme_check/check.rb', line 88

def ignore!
  @ignored = true
end

#ignored?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/theme_check/check.rb', line 96

def ignored?
  defined?(@ignored) && @ignored
end

#severityObject



72
73
74
# File 'lib/theme_check/check.rb', line 72

def severity
  self.class.severity
end

#to_sObject



104
105
106
107
108
109
110
111
# File 'lib/theme_check/check.rb', line 104

def to_s
  s = +"#{code_name}:\n"
  properties = { severity: severity, categories: categories, doc: doc }.merge(options)
  properties.each_pair do |name, value|
    s << "  #{name}: #{value}\n" if value
  end
  s
end

#unignore!Object



92
93
94
# File 'lib/theme_check/check.rb', line 92

def unignore!
  @ignored = false
end