theme-check 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +58 -0
- data/Gemfile +3 -0
- data/docs/flamegraph.svg +18488 -0
- data/lib/theme_check/checks/pagination_size.rb +30 -10
- data/lib/theme_check/cli.rb +28 -5
- data/lib/theme_check/json_printer.rb +5 -1
- data/lib/theme_check/printer.rb +9 -5
- data/lib/theme_check/version.rb +1 -1
- metadata +3 -2
@@ -36,16 +36,32 @@ module ThemeCheck
|
|
36
36
|
# Ignored, handled in ValidSchema.
|
37
37
|
end
|
38
38
|
|
39
|
+
##
|
40
|
+
# Section settings look like:
|
41
|
+
# #<Liquid::VariableLookup:0x00007fd699c50c48 @name="section", @lookups=["settings", "products_per_page"], @command_flags=0>
|
42
|
+
def size_is_a_section_setting?(size)
|
43
|
+
size.is_a?(Liquid::VariableLookup) &&
|
44
|
+
size.name == 'section' &&
|
45
|
+
size.lookups.first == 'settings'
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# We'll work with either an explicit value, or the default value of the section setting.
|
50
|
+
def get_value(size)
|
51
|
+
return size if size.is_a?(Numeric)
|
52
|
+
return get_setting_default_value(size) if size_is_a_section_setting?(size)
|
53
|
+
end
|
54
|
+
|
39
55
|
def after_document(_node)
|
40
56
|
@paginations.each_pair do |size, nodes|
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
get_setting_default_value(size.lookups.last)
|
45
|
-
end
|
46
|
-
if numerical_size.nil?
|
57
|
+
# Validate presence of default section setting.
|
58
|
+
if size_is_a_section_setting?(size) && !get_setting_default_value(size)
|
47
59
|
nodes.each { |node| add_offense("Default pagination size should be defined in the section settings", node: node) }
|
48
|
-
|
60
|
+
end
|
61
|
+
|
62
|
+
# Validate if size is within range.
|
63
|
+
next unless (numerical_size = get_value(size))
|
64
|
+
if numerical_size > @max_size || numerical_size < @min_size || !numerical_size.is_a?(Integer)
|
49
65
|
nodes.each { |node| add_offense("Pagination size must be a positive integer between #{@min_size} and #{@max_size}", node: node) }
|
50
66
|
end
|
51
67
|
end
|
@@ -53,11 +69,15 @@ module ThemeCheck
|
|
53
69
|
|
54
70
|
private
|
55
71
|
|
56
|
-
def get_setting_default_value(
|
57
|
-
setting = @schema_settings.
|
72
|
+
def get_setting_default_value(variable_lookup)
|
73
|
+
setting = @schema_settings.select { |s| s['id'] == variable_lookup.lookups.last }
|
74
|
+
|
75
|
+
# Setting does not exist.
|
58
76
|
return nil if setting.empty?
|
59
|
-
|
77
|
+
|
78
|
+
default_value = setting.last['default'].to_i
|
60
79
|
return nil if default_value == 0
|
80
|
+
|
61
81
|
default_value
|
62
82
|
end
|
63
83
|
end
|
data/lib/theme_check/cli.rb
CHANGED
@@ -78,6 +78,15 @@ module ThemeCheck
|
|
78
78
|
"Print Theme Check version"
|
79
79
|
) { @command = :version }
|
80
80
|
|
81
|
+
if ENV["THEME_CHECK_DEBUG"]
|
82
|
+
@option_parser.separator("")
|
83
|
+
@option_parser.separator("Debugging:")
|
84
|
+
@option_parser.on(
|
85
|
+
"--profile",
|
86
|
+
"Output a profile to STDOUT compatible with FlameGraph."
|
87
|
+
) { @command = :profile }
|
88
|
+
end
|
89
|
+
|
81
90
|
@option_parser.separator("")
|
82
91
|
@option_parser.separator(<<~EOS)
|
83
92
|
Description:
|
@@ -172,7 +181,7 @@ module ThemeCheck
|
|
172
181
|
puts option_parser.to_s
|
173
182
|
end
|
174
183
|
|
175
|
-
def check
|
184
|
+
def check(out_stream = STDOUT)
|
176
185
|
STDERR.puts "Checking #{@config.root} ..."
|
177
186
|
storage = ThemeCheck::FileSystemStorage.new(@config.root, ignored_patterns: @config.ignored_patterns)
|
178
187
|
theme = ThemeCheck::Theme.new(storage)
|
@@ -182,18 +191,32 @@ module ThemeCheck
|
|
182
191
|
analyzer = ThemeCheck::Analyzer.new(theme, @config.enabled_checks, @config.auto_correct)
|
183
192
|
analyzer.analyze_theme
|
184
193
|
analyzer.correct_offenses
|
185
|
-
output_with_format(theme, analyzer)
|
194
|
+
output_with_format(theme, analyzer, out_stream)
|
186
195
|
raise Abort, "" if analyzer.uncorrectable_offenses.any? do |offense|
|
187
196
|
offense.check.severity_value <= Check.severity_value(@fail_level)
|
188
197
|
end
|
189
198
|
end
|
190
199
|
|
191
|
-
def
|
200
|
+
def profile
|
201
|
+
require 'ruby-prof-flamegraph'
|
202
|
+
|
203
|
+
result = RubyProf.profile do
|
204
|
+
check(STDERR)
|
205
|
+
end
|
206
|
+
|
207
|
+
# Print a graph profile to text
|
208
|
+
printer = RubyProf::FlameGraphPrinter.new(result)
|
209
|
+
printer.print(STDOUT, {})
|
210
|
+
rescue LoadError
|
211
|
+
STDERR.puts "Profiling is only available in development"
|
212
|
+
end
|
213
|
+
|
214
|
+
def output_with_format(theme, analyzer, out_stream)
|
192
215
|
case @format
|
193
216
|
when :text
|
194
|
-
ThemeCheck::Printer.new.print(theme, analyzer.offenses, @config.auto_correct)
|
217
|
+
ThemeCheck::Printer.new(out_stream).print(theme, analyzer.offenses, @config.auto_correct)
|
195
218
|
when :json
|
196
|
-
ThemeCheck::JsonPrinter.new.print(analyzer.offenses)
|
219
|
+
ThemeCheck::JsonPrinter.new(out_stream).print(analyzer.offenses)
|
197
220
|
end
|
198
221
|
end
|
199
222
|
end
|
@@ -3,9 +3,13 @@ require 'json'
|
|
3
3
|
|
4
4
|
module ThemeCheck
|
5
5
|
class JsonPrinter
|
6
|
+
def initialize(out_stream = STDOUT)
|
7
|
+
@out = out_stream
|
8
|
+
end
|
9
|
+
|
6
10
|
def print(offenses)
|
7
11
|
json = offenses_by_path(offenses)
|
8
|
-
puts JSON.dump(json)
|
12
|
+
@out.puts JSON.dump(json)
|
9
13
|
end
|
10
14
|
|
11
15
|
def offenses_by_path(offenses)
|
data/lib/theme_check/printer.rb
CHANGED
@@ -2,14 +2,18 @@
|
|
2
2
|
|
3
3
|
module ThemeCheck
|
4
4
|
class Printer
|
5
|
+
def initialize(out_stream = STDOUT)
|
6
|
+
@out = out_stream
|
7
|
+
end
|
8
|
+
|
5
9
|
def print(theme, offenses, auto_correct)
|
6
10
|
offenses.each do |offense|
|
7
11
|
print_offense(offense, auto_correct)
|
8
|
-
puts
|
12
|
+
@out.puts
|
9
13
|
end
|
10
14
|
|
11
15
|
correctable = offenses.select(&:correctable?)
|
12
|
-
puts "#{theme.all.size} files inspected, #{red(offenses.size.to_s + ' offenses')} detected, \
|
16
|
+
@out.puts "#{theme.all.size} files inspected, #{red(offenses.size.to_s + ' offenses')} detected, \
|
13
17
|
#{yellow(correctable.size.to_s + ' offenses')} #{auto_correct ? 'corrected' : 'auto-correctable'}"
|
14
18
|
end
|
15
19
|
|
@@ -26,15 +30,15 @@ module ThemeCheck
|
|
26
30
|
""
|
27
31
|
end
|
28
32
|
|
29
|
-
puts location +
|
33
|
+
@out.puts location +
|
30
34
|
colorized_severity(offense.severity) + ": " +
|
31
35
|
yellow(offense.check_name) + ": " +
|
32
36
|
corrected +
|
33
37
|
offense.message + "."
|
34
38
|
if offense.source_excerpt
|
35
|
-
puts "\t#{offense.source_excerpt}"
|
39
|
+
@out.puts "\t#{offense.source_excerpt}"
|
36
40
|
if offense.markup_start_in_excerpt
|
37
|
-
puts "\t" + (" " * offense.markup_start_in_excerpt) + ("^" * offense.markup.size)
|
41
|
+
@out.puts "\t" + (" " * offense.markup_start_in_excerpt) + ("^" * offense.markup.size)
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
data/lib/theme_check/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theme-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-André Cournoyer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- docs/checks/valid_html_translation.md
|
119
119
|
- docs/checks/valid_json.md
|
120
120
|
- docs/checks/valid_schema.md
|
121
|
+
- docs/flamegraph.svg
|
121
122
|
- docs/preview.png
|
122
123
|
- exe/theme-check
|
123
124
|
- exe/theme-check-language-server
|