theme-check 0.8.1 → 0.8.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/config/default.yml +1 -1
- data/data/shopify_liquid/tags.yml +3 -0
- data/docs/checks/nested_snippet.md +1 -1
- data/docs/checks/space_inside_braces.md +22 -0
- data/lib/theme_check.rb +1 -0
- data/lib/theme_check/bug.rb +19 -0
- data/lib/theme_check/checks.rb +40 -3
- data/lib/theme_check/checks/nested_snippet.rb +1 -1
- data/lib/theme_check/checks/space_inside_braces.rb +5 -5
- data/lib/theme_check/language_server.rb +1 -0
- data/lib/theme_check/language_server/completion_providers/object_completion_provider.rb +10 -8
- data/lib/theme_check/language_server/variable_lookup_finder.rb +295 -0
- data/lib/theme_check/shopify_liquid/tag.rb +13 -0
- data/lib/theme_check/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b455dde358a80264581b4c6b62e70c071510d5e50ff8b253e98550ac64be3db
|
4
|
+
data.tar.gz: 5fc99066d47dd69ba0d56bea7bf60b20ccf4c67364b19999c2e5feba8cc4da12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee8807bab14aa44d5d2f1722d846f2c07c58656c7aa23dcc1da7a2e0e4f8b76cf2ca862c2ad7a9c1fd88c470b7cc4517fc74684af55a31d36eba4e60b6990bd
|
7
|
+
data.tar.gz: fd0d6012b3f991df7de47f4f7de27348a35d9582908d8564140fd900e81da9e6203b4485c7fb13dec78ddd2201acf7829b893d0004dcd1436fea4b1ea6098767
|
data/config/default.yml
CHANGED
@@ -21,6 +21,10 @@ This check is aimed at eliminating ugly Liquid:
|
|
21
21
|
<!-- Arround filter pipelines -->
|
22
22
|
{{ url | asset_url | img_tag }}
|
23
23
|
{% assign my_upcase_string = "Hello world"| upcase %}
|
24
|
+
|
25
|
+
<!-- Arround symbol operators -->
|
26
|
+
{%- if target == product and product.price_varies -%}
|
27
|
+
{%- if product.featured_media.width >=165 -%}
|
24
28
|
```
|
25
29
|
|
26
30
|
:+1: Examples of **correct** code for this check:
|
@@ -39,6 +43,8 @@ This check is aimed at eliminating ugly Liquid:
|
|
39
43
|
%}
|
40
44
|
{{ url | asset_url | img_tag }}
|
41
45
|
{% assign my_upcase_string = "Hello world" | upcase %}
|
46
|
+
{%- if target == product and product.price_varies -%}
|
47
|
+
{%- if product.featured_media.width >= 165 -%}
|
42
48
|
```
|
43
49
|
|
44
50
|
## Check Options
|
@@ -50,6 +56,22 @@ SpaceInsideBraces:
|
|
50
56
|
enabled: true
|
51
57
|
```
|
52
58
|
|
59
|
+
## Auto-correction
|
60
|
+
|
61
|
+
This check can automatically trim or add spaces around `{{ ... }}`.
|
62
|
+
|
63
|
+
```liquid
|
64
|
+
{{ x}}
|
65
|
+
{{x}}
|
66
|
+
{{ x }}
|
67
|
+
```
|
68
|
+
|
69
|
+
Can all be auto-corrected with the `--auto-correct` option to:
|
70
|
+
|
71
|
+
```liquid
|
72
|
+
{{ x }}
|
73
|
+
```
|
74
|
+
|
53
75
|
## When Not To Use It
|
54
76
|
|
55
77
|
If you don't care about the look of your code.
|
data/lib/theme_check.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ThemeCheck
|
4
|
+
BUG_POSTAMBLE = <<~EOS
|
5
|
+
Theme Check Version: #{VERSION}
|
6
|
+
Ruby Version: #{RUBY_VERSION}
|
7
|
+
Platform: #{RUBY_PLATFORM}
|
8
|
+
Muffin mode: activated
|
9
|
+
|
10
|
+
------------------------
|
11
|
+
Whoops! It looks like you found a bug in Theme Check.
|
12
|
+
Please report it at https://github.com/Shopify/theme-check/issues, and include the message above.
|
13
|
+
Or cross your fingers real hard, and try again.
|
14
|
+
EOS
|
15
|
+
|
16
|
+
def self.bug(message)
|
17
|
+
abort(message + BUG_POSTAMBLE)
|
18
|
+
end
|
19
|
+
end
|
data/lib/theme_check/checks.rb
CHANGED
@@ -1,16 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "pp"
|
3
|
+
require "timeout"
|
4
|
+
|
2
5
|
module ThemeCheck
|
3
6
|
class Checks < Array
|
7
|
+
CHECK_METHOD_TIMEOUT = 5 # sec
|
8
|
+
|
4
9
|
def call(method, *args)
|
5
10
|
each do |check|
|
6
|
-
|
7
|
-
check.send(method, *args)
|
8
|
-
end
|
11
|
+
call_check_method(check, method, *args)
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
12
15
|
def disableable
|
13
16
|
self.class.new(select(&:can_disable?))
|
14
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def call_check_method(check, method, *args)
|
22
|
+
return unless check.respond_to?(method) && !check.ignored?
|
23
|
+
|
24
|
+
Timeout.timeout(CHECK_METHOD_TIMEOUT) do
|
25
|
+
check.send(method, *args)
|
26
|
+
end
|
27
|
+
rescue Liquid::Error
|
28
|
+
# Pass-through Liquid errors
|
29
|
+
raise
|
30
|
+
rescue => e
|
31
|
+
node = args.first
|
32
|
+
template = node.respond_to?(:template) ? node.template.relative_path : "?"
|
33
|
+
markup = node.respond_to?(:markup) ? node.markup : ""
|
34
|
+
node_class = node.respond_to?(:value) ? node.value.class : "?"
|
35
|
+
|
36
|
+
ThemeCheck.bug(<<~EOS)
|
37
|
+
Exception while running `#{check.code_name}##{method}`:
|
38
|
+
```
|
39
|
+
#{e.class}: #{e.message}
|
40
|
+
#{e.backtrace.join("\n ")}
|
41
|
+
```
|
42
|
+
|
43
|
+
Template: `#{template}`
|
44
|
+
Node: `#{node_class}`
|
45
|
+
Markup:
|
46
|
+
```
|
47
|
+
#{markup}
|
48
|
+
```
|
49
|
+
Check options: `#{check.options.pretty_inspect}`
|
50
|
+
EOS
|
51
|
+
end
|
15
52
|
end
|
16
53
|
end
|
@@ -15,17 +15,17 @@ module ThemeCheck
|
|
15
15
|
return if :assign == node.type_name
|
16
16
|
|
17
17
|
outside_of_strings(node.markup) do |chunk|
|
18
|
-
chunk.scan(/([,:|]) +/) do |_match|
|
18
|
+
chunk.scan(/([,:|]|==|<>|<=|>=|<|>|!=) +/) do |_match|
|
19
19
|
add_offense("Too many spaces after '#{Regexp.last_match(1)}'", node: node, markup: Regexp.last_match(0))
|
20
20
|
end
|
21
|
-
chunk.scan(/([,:|])\S/) do |_match|
|
21
|
+
chunk.scan(/([,:|]|==|<>|<=|>=|<\b|>\b|!=)(\S|\z)/) do |_match|
|
22
22
|
add_offense("Space missing after '#{Regexp.last_match(1)}'", node: node, markup: Regexp.last_match(0))
|
23
23
|
end
|
24
|
-
chunk.scan(/ (
|
24
|
+
chunk.scan(/ (\||==|<>|<=|>=|<|>|!=)+/) do |_match|
|
25
25
|
add_offense("Too many spaces before '#{Regexp.last_match(1)}'", node: node, markup: Regexp.last_match(0))
|
26
26
|
end
|
27
|
-
chunk.scan(
|
28
|
-
add_offense("Space missing before '#{Regexp.last_match(
|
27
|
+
chunk.scan(/(\A|\S)(?<match>\||==|<>|<=|>=|<|\b>|!=)/) do |_match|
|
28
|
+
add_offense("Space missing before '#{Regexp.last_match(1)}'", node: node, markup: Regexp.last_match(0))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -4,6 +4,7 @@ require_relative "language_server/constants"
|
|
4
4
|
require_relative "language_server/handler"
|
5
5
|
require_relative "language_server/server"
|
6
6
|
require_relative "language_server/tokens"
|
7
|
+
require_relative "language_server/variable_lookup_finder"
|
7
8
|
require_relative "language_server/completion_helper"
|
8
9
|
require_relative "language_server/completion_provider"
|
9
10
|
require_relative "language_server/completion_engine"
|
@@ -4,18 +4,20 @@ module ThemeCheck
|
|
4
4
|
module LanguageServer
|
5
5
|
class ObjectCompletionProvider < CompletionProvider
|
6
6
|
def completions(content, cursor)
|
7
|
-
return [] unless
|
8
|
-
|
7
|
+
return [] unless (variable_lookup = variable_lookup_at_cursor(content, cursor))
|
8
|
+
return [] unless variable_lookup.lookups.empty?
|
9
|
+
return [] if content[cursor - 1] == "."
|
9
10
|
ShopifyLiquid::Object.labels
|
10
|
-
.select { |w| w.start_with?(partial) }
|
11
|
+
.select { |w| w.start_with?(partial(variable_lookup)) }
|
11
12
|
.map { |object| object_to_completion(object) }
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def variable_lookup_at_cursor(content, cursor)
|
16
|
+
VariableLookupFinder.lookup(content, cursor)
|
17
|
+
end
|
18
|
+
|
19
|
+
def partial(variable_lookup)
|
20
|
+
variable_lookup.name || ''
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
@@ -0,0 +1,295 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ThemeCheck
|
4
|
+
module LanguageServer
|
5
|
+
module VariableLookupFinder
|
6
|
+
extend self
|
7
|
+
|
8
|
+
UNCLOSED_SQUARE_BRACKET = /\[[^\]]*\Z/
|
9
|
+
ENDS_IN_BRACKET_POSITION_THAT_CANT_BE_COMPLETED = %r{
|
10
|
+
(
|
11
|
+
# quotes not preceded by a [
|
12
|
+
(?<!\[)['"]|
|
13
|
+
# closing ]
|
14
|
+
\]|
|
15
|
+
# opening [
|
16
|
+
\[
|
17
|
+
)$
|
18
|
+
}x
|
19
|
+
|
20
|
+
VARIABLE_LOOKUP_CHARACTERS = /[a-z0-9_.'"\]\[]/i
|
21
|
+
VARIABLE_LOOKUP = /#{VARIABLE_LOOKUP_CHARACTERS}+/o
|
22
|
+
SYMBOLS_PRECEDING_POTENTIAL_LOOKUPS = %r{
|
23
|
+
(?:
|
24
|
+
\s(?:
|
25
|
+
if|elsif|unless|and|or|#{Liquid::Condition.operators.keys.join("|")}
|
26
|
+
|echo
|
27
|
+
|case|when
|
28
|
+
|cycle
|
29
|
+
|in
|
30
|
+
)
|
31
|
+
|[:,=]
|
32
|
+
)
|
33
|
+
\s+
|
34
|
+
}omix
|
35
|
+
ENDS_WITH_BLANK_POTENTIAL_LOOKUP = /#{SYMBOLS_PRECEDING_POTENTIAL_LOOKUPS}$/oimx
|
36
|
+
ENDS_WITH_POTENTIAL_LOOKUP = /#{SYMBOLS_PRECEDING_POTENTIAL_LOOKUPS}#{VARIABLE_LOOKUP}$/oimx
|
37
|
+
|
38
|
+
def lookup(content, cursor)
|
39
|
+
return if cursor_is_on_bracket_position_that_cant_be_completed(content, cursor)
|
40
|
+
potential_lookup = lookup_liquid_variable(content, cursor) || lookup_liquid_tag(content, cursor)
|
41
|
+
|
42
|
+
# And we only return it if it's parsed by Liquid as VariableLookup
|
43
|
+
return unless potential_lookup.is_a?(Liquid::VariableLookup)
|
44
|
+
potential_lookup
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def cursor_is_on_bracket_position_that_cant_be_completed(content, cursor)
|
50
|
+
content[0..cursor - 1] =~ ENDS_IN_BRACKET_POSITION_THAT_CANT_BE_COMPLETED
|
51
|
+
end
|
52
|
+
|
53
|
+
def cursor_is_on_liquid_variable_lookup_position(content, cursor)
|
54
|
+
previous_char = content[cursor - 1]
|
55
|
+
is_liquid_variable = content =~ Liquid::VariableStart
|
56
|
+
is_in_variable_segment = previous_char =~ VARIABLE_LOOKUP_CHARACTERS
|
57
|
+
is_on_blank_variable_lookup_position = content[0..cursor - 1] =~ /[{:,-]\s+$/
|
58
|
+
(
|
59
|
+
is_liquid_variable && (
|
60
|
+
is_in_variable_segment ||
|
61
|
+
is_on_blank_variable_lookup_position
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def lookup_liquid_variable(content, cursor)
|
67
|
+
return unless cursor_is_on_liquid_variable_lookup_position(content, cursor)
|
68
|
+
start_index = content.match(/#{Liquid::VariableStart}-?/o).end(0) + 1
|
69
|
+
end_index = cursor - 1
|
70
|
+
|
71
|
+
# We take the following content
|
72
|
+
# - start after the first two {{
|
73
|
+
# - end at cursor position
|
74
|
+
#
|
75
|
+
# That way, we'll have a partial liquid variable that
|
76
|
+
# can be parsed such that the "last" variable_lookup
|
77
|
+
# will be the one we're trying to complete.
|
78
|
+
markup = content[start_index..end_index]
|
79
|
+
|
80
|
+
# Early return for incomplete variables
|
81
|
+
return empty_lookup if markup =~ /\s+$/
|
82
|
+
|
83
|
+
# Now we go to hack city... The cursor might be in the middle
|
84
|
+
# of a string/square bracket lookup. We need to close those
|
85
|
+
# otherwise the variable parse won't work.
|
86
|
+
markup += "'" if markup.count("'").odd?
|
87
|
+
markup += '"' if markup.count('"').odd?
|
88
|
+
markup += "]" if markup =~ UNCLOSED_SQUARE_BRACKET
|
89
|
+
|
90
|
+
variable = variable_from_markup(markup)
|
91
|
+
|
92
|
+
variable_lookup_for_liquid_variable(variable)
|
93
|
+
end
|
94
|
+
|
95
|
+
def cursor_is_on_liquid_tag_lookup_position(content, cursor)
|
96
|
+
markup = content[0..cursor - 1]
|
97
|
+
is_liquid_tag = content.match?(Liquid::TagStart)
|
98
|
+
is_in_variable_segment = markup =~ ENDS_WITH_POTENTIAL_LOOKUP
|
99
|
+
is_on_blank_variable_lookup_position = markup =~ ENDS_WITH_BLANK_POTENTIAL_LOOKUP
|
100
|
+
(
|
101
|
+
is_liquid_tag && (
|
102
|
+
is_in_variable_segment ||
|
103
|
+
is_on_blank_variable_lookup_position
|
104
|
+
)
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Context:
|
109
|
+
#
|
110
|
+
# We know full well that the code as it is being typed is probably not
|
111
|
+
# something that can be parsed by liquid.
|
112
|
+
#
|
113
|
+
# How this works:
|
114
|
+
#
|
115
|
+
# 1. Attempt to turn the code of the token until the cursor position into
|
116
|
+
# valid liquid code with some hacks.
|
117
|
+
# 2. If the code ends in space at a "potential lookup" spot
|
118
|
+
# a. Then return an empty variable lookup
|
119
|
+
# 3. Parse the valid liquid code
|
120
|
+
# 4. Attempt to extract a VariableLookup from Liquid::Template
|
121
|
+
def lookup_liquid_tag(content, cursor)
|
122
|
+
return unless cursor_is_on_liquid_tag_lookup_position(content, cursor)
|
123
|
+
|
124
|
+
markup = parseable_markup(content, cursor)
|
125
|
+
return empty_lookup if markup == :empty_lookup_markup
|
126
|
+
|
127
|
+
template = Liquid::Template.parse(markup)
|
128
|
+
current_tag = template.root.nodelist[0]
|
129
|
+
|
130
|
+
case current_tag.tag_name
|
131
|
+
when "if", "unless"
|
132
|
+
variable_lookup_for_if_tag(current_tag)
|
133
|
+
when "case"
|
134
|
+
variable_lookup_for_case_tag(current_tag)
|
135
|
+
when "cycle"
|
136
|
+
variable_lookup_for_cycle_tag(current_tag)
|
137
|
+
when "for"
|
138
|
+
variable_lookup_for_for_tag(current_tag)
|
139
|
+
when "tablerow"
|
140
|
+
variable_lookup_for_tablerow_tag(current_tag)
|
141
|
+
when "render"
|
142
|
+
variable_lookup_for_render_tag(current_tag)
|
143
|
+
when "assign"
|
144
|
+
variable_lookup_for_assign_tag(current_tag)
|
145
|
+
when "echo"
|
146
|
+
variable_lookup_for_echo_tag(current_tag)
|
147
|
+
end
|
148
|
+
|
149
|
+
# rubocop:disable Style/RedundantReturn
|
150
|
+
rescue Liquid::SyntaxError
|
151
|
+
# We don't complete variable for liquid syntax errors
|
152
|
+
return
|
153
|
+
end
|
154
|
+
# rubocop:enable Style/RedundantReturn
|
155
|
+
|
156
|
+
def parseable_markup(content, cursor)
|
157
|
+
start_index = 0
|
158
|
+
end_index = cursor - 1
|
159
|
+
markup = content[start_index..end_index]
|
160
|
+
|
161
|
+
# Welcome to Hackcity
|
162
|
+
markup += "'" if markup.count("'").odd?
|
163
|
+
markup += '"' if markup.count('"').odd?
|
164
|
+
markup += "]" if markup =~ UNCLOSED_SQUARE_BRACKET
|
165
|
+
|
166
|
+
# Now check if it's a liquid tag
|
167
|
+
is_liquid_tag = markup =~ tag_regex('liquid')
|
168
|
+
ends_with_blank_potential_lookup = markup =~ ENDS_WITH_BLANK_POTENTIAL_LOOKUP
|
169
|
+
last_line = markup.rstrip.lines.last
|
170
|
+
markup = "{% #{last_line}" if is_liquid_tag
|
171
|
+
|
172
|
+
# Close the tag
|
173
|
+
markup += ' %}'
|
174
|
+
|
175
|
+
# if statements
|
176
|
+
is_if_tag = markup =~ tag_regex('if')
|
177
|
+
return :empty_lookup_markup if is_if_tag && ends_with_blank_potential_lookup
|
178
|
+
markup += '{% endif %}' if is_if_tag
|
179
|
+
|
180
|
+
# unless statements
|
181
|
+
is_unless_tag = markup =~ tag_regex('unless')
|
182
|
+
return :empty_lookup_markup if is_unless_tag && ends_with_blank_potential_lookup
|
183
|
+
markup += '{% endunless %}' if is_unless_tag
|
184
|
+
|
185
|
+
# elsif statements
|
186
|
+
is_elsif_tag = markup =~ tag_regex('elsif')
|
187
|
+
return :empty_lookup_markup if is_elsif_tag && ends_with_blank_potential_lookup
|
188
|
+
markup = '{% if x %}' + markup + '{% endif %}' if is_elsif_tag
|
189
|
+
|
190
|
+
# case statements
|
191
|
+
is_case_tag = markup =~ tag_regex('case')
|
192
|
+
return :empty_lookup_markup if is_case_tag && ends_with_blank_potential_lookup
|
193
|
+
markup += "{% endcase %}" if is_case_tag
|
194
|
+
|
195
|
+
# when
|
196
|
+
is_when_tag = markup =~ tag_regex('when')
|
197
|
+
return :empty_lookup_markup if is_when_tag && ends_with_blank_potential_lookup
|
198
|
+
markup = "{% case x %}" + markup + "{% endcase %}" if is_when_tag
|
199
|
+
|
200
|
+
# for statements
|
201
|
+
is_for_tag = markup =~ tag_regex('for')
|
202
|
+
return :empty_lookup_markup if is_for_tag && ends_with_blank_potential_lookup
|
203
|
+
markup += "{% endfor %}" if is_for_tag
|
204
|
+
|
205
|
+
# tablerow statements
|
206
|
+
is_tablerow_tag = markup =~ tag_regex('tablerow')
|
207
|
+
return :empty_lookup_markup if is_tablerow_tag && ends_with_blank_potential_lookup
|
208
|
+
markup += "{% endtablerow %}" if is_tablerow_tag
|
209
|
+
|
210
|
+
markup
|
211
|
+
end
|
212
|
+
|
213
|
+
def variable_lookup_for_if_tag(if_tag)
|
214
|
+
condition = if_tag.blocks.last
|
215
|
+
variable_lookup_for_condition(condition)
|
216
|
+
end
|
217
|
+
|
218
|
+
def variable_lookup_for_condition(condition)
|
219
|
+
return variable_lookup_for_condition(condition.child_condition) if condition.child_condition
|
220
|
+
return condition.right if condition.right
|
221
|
+
condition.left
|
222
|
+
end
|
223
|
+
|
224
|
+
def variable_lookup_for_case_tag(case_tag)
|
225
|
+
return variable_lookup_for_case_block(case_tag.blocks.last) unless case_tag.blocks.empty?
|
226
|
+
case_tag.left
|
227
|
+
end
|
228
|
+
|
229
|
+
def variable_lookup_for_case_block(condition)
|
230
|
+
condition.right
|
231
|
+
end
|
232
|
+
|
233
|
+
def variable_lookup_for_cycle_tag(cycle_tag)
|
234
|
+
cycle_tag.variables.last
|
235
|
+
end
|
236
|
+
|
237
|
+
def variable_lookup_for_for_tag(for_tag)
|
238
|
+
for_tag.collection_name
|
239
|
+
end
|
240
|
+
|
241
|
+
def variable_lookup_for_tablerow_tag(tablerow_tag)
|
242
|
+
tablerow_tag.collection_name
|
243
|
+
end
|
244
|
+
|
245
|
+
def variable_lookup_for_render_tag(render_tag)
|
246
|
+
return empty_lookup if render_tag.raw =~ /:\s*$/
|
247
|
+
render_tag.attributes.values.last
|
248
|
+
end
|
249
|
+
|
250
|
+
def variable_lookup_for_assign_tag(assign_tag)
|
251
|
+
variable_lookup_for_liquid_variable(assign_tag.from)
|
252
|
+
end
|
253
|
+
|
254
|
+
def variable_lookup_for_echo_tag(echo_tag)
|
255
|
+
variable_lookup_for_liquid_variable(echo_tag.variable)
|
256
|
+
end
|
257
|
+
|
258
|
+
def variable_lookup_for_liquid_variable(variable)
|
259
|
+
has_filters = !variable.filters.empty?
|
260
|
+
|
261
|
+
# Can complete after trailing comma or :
|
262
|
+
if has_filters && variable.raw =~ /[:,]\s*$/
|
263
|
+
empty_lookup
|
264
|
+
elsif has_filters
|
265
|
+
last_filter_argument(variable.filters)
|
266
|
+
elsif variable.name.nil?
|
267
|
+
empty_lookup
|
268
|
+
else
|
269
|
+
variable.name
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def empty_lookup
|
274
|
+
Liquid::VariableLookup.parse('')
|
275
|
+
end
|
276
|
+
|
277
|
+
# We want the last thing in variable.filters which is at most
|
278
|
+
# an array that looks like [name, positional_args, hash_arg]
|
279
|
+
def last_filter_argument(filters)
|
280
|
+
filter = filters.last
|
281
|
+
return filter[2].values.last if filter.size == 3
|
282
|
+
return filter[1].last if filter.size == 2
|
283
|
+
nil
|
284
|
+
end
|
285
|
+
|
286
|
+
def variable_from_markup(markup, parse_context = Liquid::ParseContext.new)
|
287
|
+
Liquid::Variable.new(markup, parse_context)
|
288
|
+
end
|
289
|
+
|
290
|
+
def tag_regex(tag)
|
291
|
+
ShopifyLiquid::Tag.tag_regex(tag)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
@@ -8,6 +8,19 @@ module ThemeCheck
|
|
8
8
|
|
9
9
|
def labels
|
10
10
|
@tags ||= YAML.load(File.read("#{__dir__}/../../../data/shopify_liquid/tags.yml"))
|
11
|
+
.to_set
|
12
|
+
end
|
13
|
+
|
14
|
+
def tag_regex(tag)
|
15
|
+
return unless labels.include?(tag)
|
16
|
+
@tag_regexes ||= {}
|
17
|
+
@tag_regexes[tag] ||= /\A#{Liquid::TagStart}-?\s*#{tag}/m
|
18
|
+
end
|
19
|
+
|
20
|
+
def liquid_tag_regex(tag)
|
21
|
+
return unless labels.include?(tag)
|
22
|
+
@tag_liquid_regexes ||= {}
|
23
|
+
@tag_liquid_regexes[tag] ||= /^\s*#{tag}/m
|
11
24
|
end
|
12
25
|
end
|
13
26
|
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: 0.8.
|
4
|
+
version: 0.8.2
|
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-
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/theme_check.rb
|
105
105
|
- lib/theme_check/analyzer.rb
|
106
106
|
- lib/theme_check/asset_file.rb
|
107
|
+
- lib/theme_check/bug.rb
|
107
108
|
- lib/theme_check/check.rb
|
108
109
|
- lib/theme_check/checks.rb
|
109
110
|
- lib/theme_check/checks/asset_size_css.rb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- lib/theme_check/language_server/protocol.rb
|
161
162
|
- lib/theme_check/language_server/server.rb
|
162
163
|
- lib/theme_check/language_server/tokens.rb
|
164
|
+
- lib/theme_check/language_server/variable_lookup_finder.rb
|
163
165
|
- lib/theme_check/liquid_check.rb
|
164
166
|
- lib/theme_check/locale_diff.rb
|
165
167
|
- lib/theme_check/node.rb
|
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
208
|
- !ruby/object:Gem::Version
|
207
209
|
version: '0'
|
208
210
|
requirements: []
|
209
|
-
rubygems_version: 3.
|
211
|
+
rubygems_version: 3.2.17
|
210
212
|
signing_key:
|
211
213
|
specification_version: 4
|
212
214
|
summary: A Shopify Theme Linter
|