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
@@ -5,6 +5,7 @@ module ThemeCheck
|
|
5
5
|
LIQUID_TAG = /#{Liquid::TagStart}.*?#{Liquid::TagEnd}/om
|
6
6
|
LIQUID_VARIABLE = /#{Liquid::VariableStart}.*?#{Liquid::VariableEnd}/om
|
7
7
|
LIQUID_TAG_OR_VARIABLE = /#{LIQUID_TAG}|#{LIQUID_VARIABLE}/om
|
8
|
+
HTML_LIQUID_PLACEHOLDER = /≬[0-9a-z]+#*≬/m
|
8
9
|
START_OR_END_QUOTE = /(^['"])|(['"]$)/
|
9
10
|
|
10
11
|
def matches(s, re)
|
@@ -16,20 +17,5 @@ module ThemeCheck
|
|
16
17
|
end
|
17
18
|
matches
|
18
19
|
end
|
19
|
-
|
20
|
-
def href_to_file_size(href)
|
21
|
-
# asset_url (+ optional stylesheet_tag) variables
|
22
|
-
if href =~ /^#{LIQUID_VARIABLE}$/o && href =~ /asset_url/ && href =~ Liquid::QuotedString
|
23
|
-
asset_id = Regexp.last_match(0).gsub(START_OR_END_QUOTE, "")
|
24
|
-
asset = @theme.assets.find { |a| a.name.end_with?("/" + asset_id) }
|
25
|
-
return if asset.nil?
|
26
|
-
asset.gzipped_size
|
27
|
-
|
28
|
-
# remote URLs
|
29
|
-
elsif href =~ %r{^(https?:)?//}
|
30
|
-
asset = RemoteAssetFile.from_src(href)
|
31
|
-
asset.gzipped_size
|
32
|
-
end
|
33
|
-
end
|
34
20
|
end
|
35
21
|
end
|
@@ -17,6 +17,8 @@ module ThemeCheck
|
|
17
17
|
|
18
18
|
def uri(src)
|
19
19
|
URI.parse(src.sub(%r{^//}, "https://"))
|
20
|
+
rescue URI::InvalidURIError
|
21
|
+
nil
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -26,6 +28,7 @@ module ThemeCheck
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def content
|
31
|
+
return if @uri.nil?
|
29
32
|
return @content unless @content.nil?
|
30
33
|
|
31
34
|
res = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: @uri.scheme == 'https') do |http|
|
@@ -41,6 +44,7 @@ module ThemeCheck
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def gzipped_size
|
47
|
+
return if @uri.nil?
|
44
48
|
@gzipped_size ||= content.bytesize
|
45
49
|
end
|
46
50
|
end
|
data/lib/theme_check/theme.rb
CHANGED
@@ -6,6 +6,8 @@ module ThemeCheck
|
|
6
6
|
def initialize(relative_path, storage)
|
7
7
|
@relative_path = relative_path
|
8
8
|
@storage = storage
|
9
|
+
@source = nil
|
10
|
+
@eol = "\n"
|
9
11
|
end
|
10
12
|
|
11
13
|
def path
|
@@ -20,8 +22,23 @@ module ThemeCheck
|
|
20
22
|
relative_path.sub_ext('').to_s
|
21
23
|
end
|
22
24
|
|
25
|
+
# For the corrector to work properly, we should have a
|
26
|
+
# simple mental model of the internal representation of eol
|
27
|
+
# characters (Windows uses \r\n, Linux uses \n).
|
28
|
+
#
|
29
|
+
# Parser::Source::Buffer strips the \r from the source file, so if
|
30
|
+
# you are autocorrecting the file you might lose that info and
|
31
|
+
# cause a git diff. It also makes the node.start_index/end_index
|
32
|
+
# calculation break. That's not cool.
|
33
|
+
#
|
34
|
+
# So in here we track whether the source file has \r\n in it and
|
35
|
+
# we'll make sure that the file we write has the same eol as the
|
36
|
+
# source file.
|
23
37
|
def source
|
24
|
-
@source
|
38
|
+
return @source if @source
|
39
|
+
@source = @storage.read(@relative_path)
|
40
|
+
@eol = @source.include?("\r\n") ? "\r\n" : "\n"
|
41
|
+
@source = @source.gsub("\r\n", "\n")
|
25
42
|
end
|
26
43
|
|
27
44
|
def json?
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'parser'
|
4
|
+
|
5
|
+
module ThemeCheck
|
6
|
+
class ThemeFileRewriter
|
7
|
+
def initialize(name, source)
|
8
|
+
@buffer = Parser::Source::Buffer.new(name, source: source)
|
9
|
+
@rewriter = Parser::Source::TreeRewriter.new(
|
10
|
+
@buffer
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def insert_before(node, content)
|
15
|
+
@rewriter.insert_before(
|
16
|
+
range(node.start_index, node.end_index),
|
17
|
+
content
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def insert_after(node, content)
|
22
|
+
@rewriter.insert_after(
|
23
|
+
range(node.start_index, node.end_index),
|
24
|
+
content
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def replace(node, content)
|
29
|
+
@rewriter.replace(
|
30
|
+
range(node.start_index, node.end_index),
|
31
|
+
content
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def wrap(node, insert_before, insert_after)
|
36
|
+
@rewriter.wrap(
|
37
|
+
range(node.start_index, node.end_index),
|
38
|
+
insert_before,
|
39
|
+
insert_after,
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
@rewriter.process
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def range(start_index, end_index)
|
50
|
+
Parser::Source::Range.new(
|
51
|
+
@buffer,
|
52
|
+
start_index,
|
53
|
+
end_index,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/theme_check/version.rb
CHANGED
data/lib/theme_check.rb
CHANGED
@@ -4,20 +4,23 @@ require "liquid"
|
|
4
4
|
require_relative "theme_check/version"
|
5
5
|
require_relative "theme_check/bug"
|
6
6
|
require_relative "theme_check/exceptions"
|
7
|
+
require_relative "theme_check/theme_file_rewriter"
|
7
8
|
require_relative "theme_check/theme_file"
|
9
|
+
require_relative "theme_check/liquid_file"
|
10
|
+
require_relative "theme_check/asset_file"
|
11
|
+
require_relative "theme_check/json_file"
|
8
12
|
require_relative "theme_check/analyzer"
|
9
13
|
require_relative "theme_check/check"
|
10
14
|
require_relative "theme_check/checks_tracking"
|
15
|
+
require_relative "theme_check/liquid_check"
|
16
|
+
require_relative "theme_check/html_check"
|
17
|
+
require_relative "theme_check/json_check"
|
11
18
|
require_relative "theme_check/cli"
|
12
19
|
require_relative "theme_check/disabled_check"
|
13
20
|
require_relative "theme_check/disabled_checks"
|
14
|
-
require_relative "theme_check/liquid_check"
|
15
21
|
require_relative "theme_check/locale_diff"
|
16
|
-
require_relative "theme_check/asset_file"
|
17
22
|
require_relative "theme_check/remote_asset_file"
|
18
23
|
require_relative "theme_check/regex_helpers"
|
19
|
-
require_relative "theme_check/json_check"
|
20
|
-
require_relative "theme_check/json_file"
|
21
24
|
require_relative "theme_check/json_helpers"
|
22
25
|
require_relative "theme_check/position_helper"
|
23
26
|
require_relative "theme_check/position"
|
@@ -25,22 +28,21 @@ require_relative "theme_check/language_server"
|
|
25
28
|
require_relative "theme_check/checks"
|
26
29
|
require_relative "theme_check/config"
|
27
30
|
require_relative "theme_check/node"
|
31
|
+
require_relative "theme_check/liquid_node"
|
32
|
+
require_relative "theme_check/html_node"
|
28
33
|
require_relative "theme_check/offense"
|
29
34
|
require_relative "theme_check/printer"
|
30
35
|
require_relative "theme_check/json_printer"
|
31
36
|
require_relative "theme_check/shopify_liquid"
|
32
|
-
require_relative "theme_check/storage"
|
33
37
|
require_relative "theme_check/string_helpers"
|
38
|
+
require_relative "theme_check/storage"
|
34
39
|
require_relative "theme_check/file_system_storage"
|
35
40
|
require_relative "theme_check/in_memory_storage"
|
36
41
|
require_relative "theme_check/tags"
|
37
|
-
require_relative "theme_check/template"
|
38
42
|
require_relative "theme_check/theme"
|
39
|
-
require_relative "theme_check/visitor"
|
40
43
|
require_relative "theme_check/corrector"
|
41
|
-
require_relative "theme_check/
|
44
|
+
require_relative "theme_check/liquid_visitor"
|
42
45
|
require_relative "theme_check/html_visitor"
|
43
|
-
require_relative "theme_check/html_check"
|
44
46
|
|
45
47
|
Dir[__dir__ + "/theme_check/checks/*.rb"].each { |file| require file }
|
46
48
|
|
data/theme-check.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency('liquid', '>= 5.0
|
27
|
+
spec.add_dependency('liquid', '>= 5.1.0')
|
28
28
|
spec.add_dependency('nokogiri', '>= 1.12')
|
29
|
+
spec.add_dependency('parser', '~> 3')
|
29
30
|
end
|
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.
|
4
|
+
version: 1.6.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-09-
|
11
|
+
date: 2021-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.0
|
19
|
+
version: 5.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.0
|
26
|
+
version: 5.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: parser
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- marcandre.cournoyer@shopify.com
|
@@ -209,6 +223,9 @@ files:
|
|
209
223
|
- lib/theme_check/language_server/uri_helper.rb
|
210
224
|
- lib/theme_check/language_server/variable_lookup_finder.rb
|
211
225
|
- lib/theme_check/liquid_check.rb
|
226
|
+
- lib/theme_check/liquid_file.rb
|
227
|
+
- lib/theme_check/liquid_node.rb
|
228
|
+
- lib/theme_check/liquid_visitor.rb
|
212
229
|
- lib/theme_check/locale_diff.rb
|
213
230
|
- lib/theme_check/node.rb
|
214
231
|
- lib/theme_check/offense.rb
|
@@ -228,11 +245,10 @@ files:
|
|
228
245
|
- lib/theme_check/storage.rb
|
229
246
|
- lib/theme_check/string_helpers.rb
|
230
247
|
- lib/theme_check/tags.rb
|
231
|
-
- lib/theme_check/template.rb
|
232
248
|
- lib/theme_check/theme.rb
|
233
249
|
- lib/theme_check/theme_file.rb
|
250
|
+
- lib/theme_check/theme_file_rewriter.rb
|
234
251
|
- lib/theme_check/version.rb
|
235
|
-
- lib/theme_check/visitor.rb
|
236
252
|
- packaging/homebrew/theme_check.base.rb
|
237
253
|
- theme-check.gemspec
|
238
254
|
homepage: https://github.com/Shopify/theme-check
|