theme-check 1.5.1 → 1.6.2
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/.github/workflows/theme-check.yml +12 -4
- data/CHANGELOG.md +35 -0
- data/docs/api/html_check.md +7 -7
- data/docs/api/liquid_check.md +10 -10
- data/docs/checks/convert_include_to_render.md +1 -1
- data/docs/checks/missing_enable_comment.md +1 -1
- data/lib/theme_check/analyzer.rb +20 -15
- data/lib/theme_check/asset_file.rb +13 -2
- data/lib/theme_check/check.rb +3 -3
- data/lib/theme_check/checks/asset_size_css.rb +15 -0
- data/lib/theme_check/checks/asset_size_css_stylesheet_tag.rb +18 -1
- data/lib/theme_check/checks/convert_include_to_render.rb +2 -1
- data/lib/theme_check/checks/html_parsing_error.rb +2 -2
- data/lib/theme_check/checks/liquid_tag.rb +1 -1
- data/lib/theme_check/checks/matching_translations.rb +1 -1
- data/lib/theme_check/checks/missing_required_template_files.rb +21 -7
- data/lib/theme_check/checks/missing_template.rb +6 -6
- data/lib/theme_check/checks/nested_snippet.rb +2 -2
- data/lib/theme_check/checks/required_directories.rb +3 -1
- data/lib/theme_check/checks/required_layout_theme_object.rb +2 -2
- data/lib/theme_check/checks/space_inside_braces.rb +47 -24
- data/lib/theme_check/checks/syntax_error.rb +5 -5
- data/lib/theme_check/checks/template_length.rb +2 -2
- data/lib/theme_check/checks/translation_key_exists.rb +3 -1
- data/lib/theme_check/checks/undefined_object.rb +7 -7
- data/lib/theme_check/checks/unused_assign.rb +4 -4
- data/lib/theme_check/checks/unused_snippet.rb +8 -6
- data/lib/theme_check/checks/valid_json.rb +1 -1
- data/lib/theme_check/checks.rb +4 -2
- data/lib/theme_check/cli.rb +7 -4
- data/lib/theme_check/corrector.rb +25 -12
- data/lib/theme_check/disabled_check.rb +3 -3
- data/lib/theme_check/disabled_checks.rb +9 -9
- data/lib/theme_check/file_system_storage.rb +13 -2
- data/lib/theme_check/html_node.rb +40 -32
- data/lib/theme_check/html_visitor.rb +24 -12
- data/lib/theme_check/in_memory_storage.rb +9 -1
- data/lib/theme_check/json_check.rb +2 -2
- data/lib/theme_check/json_file.rb +9 -4
- data/lib/theme_check/language_server/diagnostics_tracker.rb +8 -8
- data/lib/theme_check/{template.rb → liquid_file.rb} +6 -20
- data/lib/theme_check/liquid_node.rb +291 -0
- data/lib/theme_check/{visitor.rb → liquid_visitor.rb} +4 -4
- data/lib/theme_check/locale_diff.rb +5 -5
- data/lib/theme_check/node.rb +12 -118
- data/lib/theme_check/offense.rb +41 -15
- data/lib/theme_check/position.rb +28 -17
- data/lib/theme_check/position_helper.rb +13 -15
- data/lib/theme_check/regex_helpers.rb +1 -15
- data/lib/theme_check/remote_asset_file.rb +4 -0
- data/lib/theme_check/theme.rb +1 -1
- data/lib/theme_check/theme_file.rb +18 -1
- data/lib/theme_check/theme_file_rewriter.rb +57 -0
- data/lib/theme_check/version.rb +1 -1
- data/lib/theme_check.rb +11 -9
- data/theme-check.gemspec +2 -1
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e992338f154cdf5da965bae74af6907af89156170b5bdcf599f8f15b9708bb87
|
4
|
+
data.tar.gz: 27071bf8d98359410d2486a62502f2e7453465771b932a77a6c27785ba00abbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33969efb3cc9bd670ce7a15a419e7419824e8e48ab5951e1f527f116e3aec42ca01c214eb50cd0eb1058fd6c5975c353f3b84024b990dcbad3a45f27cbb9380f
|
7
|
+
data.tar.gz: 410dd3f410c5dd0fe23533eae5716d8bfefec6fd4bc57e68c77dfe14832e7c498854d2dc6728b25467188d887860d97d92747cf915ab1c669f40226b46a371ad
|
@@ -8,15 +8,23 @@ jobs:
|
|
8
8
|
|
9
9
|
strategy:
|
10
10
|
matrix:
|
11
|
-
platform:
|
11
|
+
platform:
|
12
|
+
- ubuntu-latest
|
13
|
+
- windows-latest
|
12
14
|
version:
|
13
15
|
- 3.0.0
|
14
16
|
- 2.6.6
|
17
|
+
theme:
|
18
|
+
- Shopify/dawn
|
15
19
|
|
16
20
|
name: Ruby ${{ matrix.platform }} ${{ matrix.version }}
|
17
21
|
|
18
22
|
steps:
|
19
23
|
- uses: actions/checkout@v2
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
with:
|
26
|
+
repository: ${{ matrix.theme }}
|
27
|
+
path: ./crash-test-theme
|
20
28
|
- name: Set up Ruby ${{ matrix.version }}
|
21
29
|
uses: ruby/setup-ruby@v1
|
22
30
|
with:
|
@@ -30,6 +38,6 @@ jobs:
|
|
30
38
|
run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
|
31
39
|
- name: Run tests
|
32
40
|
run: bundle exec rake
|
33
|
-
- name:
|
34
|
-
|
35
|
-
|
41
|
+
- name: Crash test
|
42
|
+
run: |
|
43
|
+
bundle exec theme-check --fail-level crash ./crash-test-theme
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,39 @@
|
|
1
1
|
|
2
|
+
v1.6.2 / 2021-09-16
|
3
|
+
===================
|
4
|
+
|
5
|
+
* SpaceInsideBraces fixup for tags without arguments ([#458](https://github.com/shopify/theme-check/issues/458))
|
6
|
+
* Fix UnusedAssign bug when variable used in for loop range by bumping Liquid to 5.1 ([#456](https://github.com/shopify/theme-check/issues/456))
|
7
|
+
|
8
|
+
v1.6.1 / 2021-09-15
|
9
|
+
===================
|
10
|
+
|
11
|
+
* Fix `Undefined method `-' for nil:NilClass` in Node when tag was missing surrounding spaces ([#454](https://github.com/shopify/theme-check/issues/454), [#452](https://github.com/shopify/theme-check/issues/452))
|
12
|
+
|
13
|
+
v1.6.0 / 2021-09-14
|
14
|
+
===================
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* Add `--auto-correct` support to `TranslationKeyExists` (add missing translation as TODO to default locale) ([#422](https://github.com/shopify/theme-check/issues/422))
|
19
|
+
* Add `--auto-correct` support to `UnusedSnippet` (delete unused file) ([#416](https://github.com/shopify/theme-check/issues/416))
|
20
|
+
* Add `--auto-correct` support to `MissingRequiredTemplateFiles` (create missing files) ([#385](https://github.com/shopify/theme-check/issues/385))
|
21
|
+
|
22
|
+
### Fixes
|
23
|
+
|
24
|
+
* Fix `undefined method [] of nil` in `replace_placeholders` ([#441](https://github.com/shopify/theme-check/issues/441), [#444](https://github.com/shopify/theme-check/issues/444))
|
25
|
+
* Disable ConvertIncludeToRender corrector until we fix [#445](https://github.com/shopify/theme-check/issues/445) ([#446](https://github.com/shopify/theme-check/issues/446))
|
26
|
+
* Fix a couple of correction bugs ([#442](https://github.com/shopify/theme-check/issues/442), [#439](https://github.com/shopify/theme-check/issues/439))
|
27
|
+
* Fix `AssetSizeCSS` error when size is nil ([#419](https://github.com/shopify/theme-check/issues/419))
|
28
|
+
* Write JSON to file, not a Ruby Hash. ([#434](https://github.com/shopify/theme-check/issues/434), [#432](https://github.com/shopify/theme-check/issues/432))
|
29
|
+
|
30
|
+
v1.5.2 / 2021-09-09
|
31
|
+
===================
|
32
|
+
|
33
|
+
* Handle invalid URIs in RemoteAssetFile ([#418](https://github.com/shopify/theme-check/issues/418), [#438](https://github.com/shopify/theme-check/issues/438))
|
34
|
+
* Fix `Bad start_index` error in SpaceInsideBraces ([#423](https://github.com/shopify/theme-check/issues/423))
|
35
|
+
* Autocorrect missing directories ([#389](https://github.com/shopify/theme-check/issues/389))
|
36
|
+
|
2
37
|
v1.5.1 / 2021-09-08
|
3
38
|
===================
|
4
39
|
|
data/docs/api/html_check.md
CHANGED
@@ -16,18 +16,18 @@ module ThemeCheck
|
|
16
16
|
severity :suggestion # :error or :style
|
17
17
|
|
18
18
|
def on_document(node)
|
19
|
-
# Called with the root node of all
|
20
|
-
node.value
|
21
|
-
node.
|
22
|
-
node.parent
|
23
|
-
node.children
|
19
|
+
# Called with the root node of all theme files
|
20
|
+
node.value # is an instance of Nokogiri::XML::Node
|
21
|
+
node.theme_file # is the html_file being analyzed, See lib/theme_check/theme_file.rb.
|
22
|
+
node.parent # is the parent node.
|
23
|
+
node.children # are the children nodes.
|
24
24
|
# See lib/theme_check/html_node.rb for more helper methods
|
25
|
-
theme # Gives you access to all the
|
25
|
+
theme # Gives you access to all the theme files in the theme. See lib/theme_check/theme.rb.
|
26
26
|
end
|
27
27
|
|
28
28
|
def on_img(node)
|
29
29
|
# Called for every <img> element in the file.
|
30
|
-
node.
|
30
|
+
node.attributes["class"] # Get the class attribute of the img element.
|
31
31
|
end
|
32
32
|
|
33
33
|
def on_a(node)
|
data/docs/api/liquid_check.md
CHANGED
@@ -16,13 +16,13 @@ module ThemeCheck
|
|
16
16
|
severity :suggestion # :error or :style
|
17
17
|
|
18
18
|
def on_document(node)
|
19
|
-
# Called with the root node of all
|
20
|
-
node.value
|
21
|
-
node.
|
22
|
-
node.parent
|
23
|
-
node.children
|
19
|
+
# Called with the root node of all liquid_file
|
20
|
+
node.value # is the original Liquid object for this node. See Liquid source code for details.
|
21
|
+
node.theme_file # is the liquid_file being analyzed, See lib/theme_check/liquid_file.rb.
|
22
|
+
node.parent # is the parent node.
|
23
|
+
node.children # are the children nodes.
|
24
24
|
# See lib/theme_check/node.rb for more helper methods
|
25
|
-
theme # Gives you access to all the
|
25
|
+
theme # Gives you access to all the theme files in the theme. See lib/theme_check/theme.rb.
|
26
26
|
end
|
27
27
|
|
28
28
|
def on_node(node)
|
@@ -38,8 +38,8 @@ module ThemeCheck
|
|
38
38
|
|
39
39
|
# If you find an issue, add an offense:
|
40
40
|
add_offense("Describe the problem...", node: node)
|
41
|
-
# Or, if the offense is related to the whole
|
42
|
-
add_offense("Describe the problem...",
|
41
|
+
# Or, if the offense is related to the whole theme file:
|
42
|
+
add_offense("Describe the problem...", theme_file: node.theme_file)
|
43
43
|
end
|
44
44
|
|
45
45
|
def on_assign(node)
|
@@ -50,7 +50,7 @@ module ThemeCheck
|
|
50
50
|
# Called for every `String` (including inside if conditions).
|
51
51
|
if node.parent.block?
|
52
52
|
# If parent is a block, `node.value` is a String written directly to the output when
|
53
|
-
# the
|
53
|
+
# the theme file is rendered.
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -59,7 +59,7 @@ module ThemeCheck
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def on_error(exception)
|
62
|
-
# Called each time a Liquid exception is raised while parsing the
|
62
|
+
# Called each time a Liquid exception is raised while parsing the theme file
|
63
63
|
end
|
64
64
|
|
65
65
|
def on_end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
The `include` tag is [deprecated][deprecated]. This tag exists to enforce the use of the `render` tag instead of `include`.
|
4
4
|
|
5
|
-
The `include` tag works similarly to the `render` tag, but it lets the code inside of the snippet to access and overwrite the variables within its parent
|
5
|
+
The `include` tag works similarly to the `render` tag, but it lets the code inside of the snippet to access and overwrite the variables within its parent theme file. The `include` tag has been deprecated because the way that it handles variables reduces performance and makes theme code harder to both read and maintain.
|
6
6
|
|
7
7
|
## Check Details
|
8
8
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Prevent missing theme-check-enable comments (`MissingEnableComment`)
|
2
2
|
|
3
|
-
When `theme-check-disable` is used in the middle of a
|
3
|
+
When `theme-check-disable` is used in the middle of a theme file, the corresponding `theme-check-enable` comment should also be included.
|
4
4
|
|
5
5
|
## Check Details
|
6
6
|
|
data/lib/theme_check/analyzer.rb
CHANGED
@@ -32,12 +32,12 @@ module ThemeCheck
|
|
32
32
|
def analyze_theme
|
33
33
|
reset
|
34
34
|
|
35
|
-
liquid_visitor =
|
35
|
+
liquid_visitor = LiquidVisitor.new(@liquid_checks, @disabled_checks)
|
36
36
|
html_visitor = HtmlVisitor.new(@html_checks)
|
37
37
|
ThemeCheck.with_liquid_c_disabled do
|
38
|
-
@theme.liquid.each do |
|
39
|
-
liquid_visitor.
|
40
|
-
html_visitor.
|
38
|
+
@theme.liquid.each do |liquid_file|
|
39
|
+
liquid_visitor.visit_liquid_file(liquid_file)
|
40
|
+
html_visitor.visit_liquid_file(liquid_file)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -51,23 +51,23 @@ module ThemeCheck
|
|
51
51
|
|
52
52
|
ThemeCheck.with_liquid_c_disabled do
|
53
53
|
# Call all checks that run on the whole theme
|
54
|
-
liquid_visitor =
|
54
|
+
liquid_visitor = LiquidVisitor.new(@liquid_checks.whole_theme, @disabled_checks)
|
55
55
|
html_visitor = HtmlVisitor.new(@html_checks.whole_theme)
|
56
|
-
@theme.liquid.each do |
|
57
|
-
liquid_visitor.
|
58
|
-
html_visitor.
|
56
|
+
@theme.liquid.each do |liquid_file|
|
57
|
+
liquid_visitor.visit_liquid_file(liquid_file)
|
58
|
+
html_visitor.visit_liquid_file(liquid_file)
|
59
59
|
end
|
60
60
|
@theme.json.each { |json_file| @json_checks.whole_theme.call(:on_file, json_file) }
|
61
61
|
|
62
62
|
# Call checks that run on a single files, only on specified file
|
63
|
-
liquid_visitor =
|
63
|
+
liquid_visitor = LiquidVisitor.new(@liquid_checks.single_file, @disabled_checks)
|
64
64
|
html_visitor = HtmlVisitor.new(@html_checks.single_file)
|
65
|
-
files.each do |
|
66
|
-
if
|
67
|
-
liquid_visitor.
|
68
|
-
html_visitor.
|
69
|
-
elsif
|
70
|
-
@json_checks.single_file.call(:on_file,
|
65
|
+
files.each do |theme_file|
|
66
|
+
if theme_file.liquid?
|
67
|
+
liquid_visitor.visit_liquid_file(theme_file)
|
68
|
+
html_visitor.visit_liquid_file(theme_file)
|
69
|
+
elsif theme_file.json?
|
70
|
+
@json_checks.single_file.call(:on_file, theme_file)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -86,6 +86,11 @@ module ThemeCheck
|
|
86
86
|
def correct_offenses
|
87
87
|
if @auto_correct
|
88
88
|
offenses.each(&:correct)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def write_corrections
|
93
|
+
if @auto_correct
|
89
94
|
@theme.liquid.each(&:write)
|
90
95
|
@theme.json.each(&:write)
|
91
96
|
end
|
@@ -9,10 +9,21 @@ module ThemeCheck
|
|
9
9
|
@content = nil
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
def rewriter
|
13
|
+
@rewriter ||= ThemeFileRewriter.new(@relative_path, source)
|
14
|
+
end
|
15
|
+
|
16
|
+
def write
|
17
|
+
content = rewriter.to_s
|
18
|
+
if source != content
|
19
|
+
@storage.write(@relative_path, content.gsub("\n", @eol))
|
20
|
+
@source = content
|
21
|
+
@rewriter = nil
|
22
|
+
end
|
23
|
+
end
|
13
24
|
|
14
25
|
def gzipped_size
|
15
|
-
@gzipped_size ||= Zlib.gzip(
|
26
|
+
@gzipped_size ||= Zlib.gzip(source).bytesize
|
16
27
|
end
|
17
28
|
|
18
29
|
def name
|
data/lib/theme_check/check.rb
CHANGED
@@ -46,7 +46,7 @@ module ThemeCheck
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def severity_value(severity)
|
49
|
-
SEVERITY_VALUES[severity]
|
49
|
+
SEVERITY_VALUES[severity] || -1
|
50
50
|
end
|
51
51
|
|
52
52
|
def categories(*categories)
|
@@ -91,8 +91,8 @@ module ThemeCheck
|
|
91
91
|
@offenses ||= []
|
92
92
|
end
|
93
93
|
|
94
|
-
def add_offense(message, node: nil,
|
95
|
-
offenses << Offense.new(check: self, message: message,
|
94
|
+
def add_offense(message, node: nil, theme_file: node&.theme_file, markup: nil, line_number: nil, node_markup_offset: 0, &block)
|
95
|
+
offenses << Offense.new(check: self, message: message, theme_file: theme_file, node: node, markup: markup, line_number: line_number, node_markup_offset: node_markup_offset, correction: block)
|
96
96
|
end
|
97
97
|
|
98
98
|
def severity
|
@@ -22,5 +22,20 @@ module ThemeCheck
|
|
22
22
|
node: node
|
23
23
|
)
|
24
24
|
end
|
25
|
+
|
26
|
+
def href_to_file_size(href)
|
27
|
+
# asset_url (+ optional stylesheet_tag) variables
|
28
|
+
if href =~ /^#{LIQUID_VARIABLE}$/o && href =~ /asset_url/ && href =~ Liquid::QuotedString
|
29
|
+
asset_id = Regexp.last_match(0).gsub(START_OR_END_QUOTE, "")
|
30
|
+
asset = @theme.assets.find { |a| a.name.end_with?("/" + asset_id) }
|
31
|
+
return if asset.nil?
|
32
|
+
asset.gzipped_size
|
33
|
+
|
34
|
+
# remote URLs
|
35
|
+
elsif href =~ %r{^(https?:)?//}
|
36
|
+
asset = RemoteAssetFile.from_src(href)
|
37
|
+
asset.gzipped_size
|
38
|
+
end
|
39
|
+
end
|
25
40
|
end
|
26
41
|
end
|
@@ -13,12 +13,29 @@ module ThemeCheck
|
|
13
13
|
def on_variable(node)
|
14
14
|
used_filters = node.value.filters.map { |name, *_rest| name }
|
15
15
|
return unless used_filters.include?("stylesheet_tag")
|
16
|
-
file_size =
|
16
|
+
file_size = stylesheet_tag_pipeline_to_file_size(node.markup)
|
17
|
+
return if file_size.nil?
|
17
18
|
return if file_size <= @threshold_in_bytes
|
18
19
|
add_offense(
|
19
20
|
"CSS on every page load exceeding compressed size threshold (#{@threshold_in_bytes} Bytes).",
|
20
21
|
node: node
|
21
22
|
)
|
22
23
|
end
|
24
|
+
|
25
|
+
def stylesheet_tag_pipeline_to_file_size(href)
|
26
|
+
# asset_url
|
27
|
+
if href =~ /asset_url/ && href =~ Liquid::QuotedString
|
28
|
+
asset_id = Regexp.last_match(0).gsub(START_OR_END_QUOTE, "")
|
29
|
+
asset = @theme.assets.find { |a| a.name.end_with?("/" + asset_id) }
|
30
|
+
return if asset.nil?
|
31
|
+
asset.gzipped_size
|
32
|
+
|
33
|
+
# remote URLs
|
34
|
+
elsif href =~ %r{(https?:)?//[^'"]+}
|
35
|
+
url = Regexp.last_match(0)
|
36
|
+
asset = RemoteAssetFile.from_src(url)
|
37
|
+
asset.gzipped_size
|
38
|
+
end
|
39
|
+
end
|
23
40
|
end
|
24
41
|
end
|
@@ -8,7 +8,8 @@ module ThemeCheck
|
|
8
8
|
|
9
9
|
def on_include(node)
|
10
10
|
add_offense("`include` is deprecated - convert it to `render`", node: node) do |corrector|
|
11
|
-
|
11
|
+
# We need to fix #445 and pass the variables from the context or don't replace at all.
|
12
|
+
# corrector.replace(node, "render \'#{node.value.template_name_expr}\' ")
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -5,8 +5,8 @@ module ThemeCheck
|
|
5
5
|
category :html
|
6
6
|
doc docs_url(__FILE__)
|
7
7
|
|
8
|
-
def on_parse_error(exception,
|
9
|
-
add_offense("HTML in this template can not be parsed: #{exception.message}",
|
8
|
+
def on_parse_error(exception, theme_file)
|
9
|
+
add_offense("HTML in this template can not be parsed: #{exception.message}", theme_file: theme_file)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -9,19 +9,33 @@ module ThemeCheck
|
|
9
9
|
doc docs_url(__FILE__)
|
10
10
|
|
11
11
|
REQUIRED_LIQUID_FILES = %w(layout/theme)
|
12
|
-
|
13
|
-
|
12
|
+
|
13
|
+
REQUIRED_LIQUID_TEMPLATE_FILES = %w(
|
14
14
|
gift_card customers/account customers/activate_account customers/addresses
|
15
|
-
customers/login customers/order customers/register customers/reset_password
|
16
|
-
)
|
17
|
-
|
15
|
+
customers/login customers/order customers/register customers/reset_password
|
16
|
+
).map { |file| "templates/#{file}" }
|
17
|
+
|
18
|
+
REQUIRED_JSON_TEMPLATE_FILES = %w(
|
19
|
+
index product collection cart blog article page list-collections search 404
|
20
|
+
password
|
21
|
+
).map { |file| "templates/#{file}" }
|
22
|
+
|
23
|
+
REQUIRED_TEMPLATE_FILES = (REQUIRED_LIQUID_TEMPLATE_FILES + REQUIRED_JSON_TEMPLATE_FILES)
|
18
24
|
|
19
25
|
def on_end
|
20
26
|
(REQUIRED_LIQUID_FILES - theme.liquid.map(&:name)).each do |file|
|
21
|
-
add_offense("'#{file}.liquid' is missing")
|
27
|
+
add_offense("'#{file}.liquid' is missing") do |corrector|
|
28
|
+
corrector.create(@theme, "#{file}.liquid", "")
|
29
|
+
end
|
22
30
|
end
|
23
31
|
(REQUIRED_TEMPLATE_FILES - (theme.liquid + theme.json).map(&:name)).each do |file|
|
24
|
-
add_offense("'#{file}.liquid' or '#{file}.json' is missing")
|
32
|
+
add_offense("'#{file}.liquid' or '#{file}.json' is missing") do |corrector|
|
33
|
+
if REQUIRED_LIQUID_TEMPLATE_FILES.include?(file)
|
34
|
+
corrector.create(@theme, "#{file}.liquid", "")
|
35
|
+
else
|
36
|
+
corrector.create(@theme, "#{file}.json", "")
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module ThemeCheck
|
3
|
-
# Reports missing include/render/section
|
3
|
+
# Reports missing include/render/section liquid file
|
4
4
|
class MissingTemplate < LiquidCheck
|
5
5
|
severity :suggestion
|
6
6
|
category :liquid
|
@@ -12,17 +12,17 @@ module ThemeCheck
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def on_include(node)
|
15
|
-
|
16
|
-
if
|
17
|
-
add_missing_offense("snippets/#{
|
15
|
+
snippet = node.value.template_name_expr
|
16
|
+
if snippet.is_a?(String)
|
17
|
+
add_missing_offense("snippets/#{snippet}", node: node)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
alias_method :on_render, :on_include
|
22
22
|
|
23
23
|
def on_section(node)
|
24
|
-
|
25
|
-
add_missing_offense("sections/#{
|
24
|
+
section = node.value.section_name
|
25
|
+
add_missing_offense("sections/#{section}", node: node)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|