Class: ThemeCheck::Check
Constant Summary
collapse
- SEVERITIES =
[
:error,
:suggestion,
:style,
]
- CATEGORIES =
[
:liquid,
:translation,
:html,
:json,
:performance,
]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#format_json_parse_error
Instance Attribute Details
#ignored_patterns ⇒ Object
Returns the value of attribute ignored_patterns.
9
10
11
|
# File 'lib/theme_check/check.rb', line 9
def ignored_patterns
@ignored_patterns
end
|
#offenses ⇒ Object
79
80
81
|
# File 'lib/theme_check/check.rb', line 79
def offenses
@offenses ||= []
end
|
#options ⇒ Object
Returns the value of attribute options.
9
10
11
|
# File 'lib/theme_check/check.rb', line 9
def options
@options
end
|
#theme ⇒ Object
Returns the value of attribute theme.
8
9
10
|
# File 'lib/theme_check/check.rb', line 8
def theme
@theme
end
|
Class Method Details
.all ⇒ Object
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
|
.category ⇒ Object
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
|
.single_file(single_file = nil) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/theme_check/check.rb', line 71
def single_file(single_file = nil)
unless single_file.nil?
@single_file = single_file
end
defined?(@single_file) ? @single_file : !method_defined?(:on_end)
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
123
124
125
|
# File 'lib/theme_check/check.rb', line 123
def ==(other)
other.is_a?(Check) && code_name == other.code_name
end
|
#add_offense(message, node: nil, template: node&.template, markup: nil, line_number: nil, &block) ⇒ Object
83
84
85
|
# File 'lib/theme_check/check.rb', line 83
def add_offense(message, node: nil, template: node&.template, markup: nil, line_number: nil, &block)
offenses << Offense.new(check: self, message: message, template: template, node: node, markup: markup, line_number: line_number, correction: block)
end
|
#can_disable? ⇒ Boolean
111
112
113
|
# File 'lib/theme_check/check.rb', line 111
def can_disable?
self.class.can_disable
end
|
#categories ⇒ Object
91
92
93
|
# File 'lib/theme_check/check.rb', line 91
def categories
self.class.categories
end
|
#doc ⇒ Object
95
96
97
|
# File 'lib/theme_check/check.rb', line 95
def doc
self.class.doc
end
|
#ignore! ⇒ Object
103
104
105
|
# File 'lib/theme_check/check.rb', line 103
def ignore!
@ignored = true
end
|
#ignored? ⇒ Boolean
107
108
109
|
# File 'lib/theme_check/check.rb', line 107
def ignored?
defined?(@ignored) && @ignored
end
|
#severity ⇒ Object
87
88
89
|
# File 'lib/theme_check/check.rb', line 87
def severity
self.class.severity
end
|
#single_file? ⇒ Boolean
115
116
117
|
# File 'lib/theme_check/check.rb', line 115
def single_file?
self.class.single_file
end
|
#to_s ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/theme_check/check.rb', line 128
def to_s
s = +"#{code_name}:\n"
properties = {
severity: severity,
categories: categories,
doc: doc,
ignored_patterns: ignored_patterns,
}.merge(options)
properties.each_pair do |name, value|
s << " #{name}: #{value}\n" if value
end
s
end
|
#whole_theme? ⇒ Boolean
119
120
121
|
# File 'lib/theme_check/check.rb', line 119
def whole_theme?
!single_file?
end
|