theme-check 1.4.0 → 1.5.0
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 +3 -3
- data/.gitignore +1 -0
- data/CHANGELOG.md +13 -0
- data/config/default.yml +3 -0
- data/docs/checks/deprecated_global_app_block_type.md +65 -0
- data/lib/theme_check/checks/deprecated_global_app_block_type.rb +57 -0
- data/lib/theme_check/checks/pagination_size.rb +5 -6
- data/lib/theme_check/json_printer.rb +1 -0
- data/lib/theme_check/language_server/document_link_provider.rb +2 -1
- data/lib/theme_check/language_server/handler.rb +16 -11
- data/lib/theme_check/language_server/server.rb +11 -13
- data/lib/theme_check/language_server/uri_helper.rb +37 -0
- data/lib/theme_check/language_server.rb +1 -0
- data/lib/theme_check/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bfe8af624c0fe355dedcf6036609fc1366196011af2207b8365c0bb3389f3f5
|
4
|
+
data.tar.gz: 526353e93c6d8bc3bb902b24d81084c581cecdbd0bd98e29d9c1fd95ff00aff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49b583b1bbfa5fb7a59370ec6d09e6b1099ecf3ffa22a6fc55cf099fe26ab682637bf3c943c54786b0a36b80b20501491bb9623255af3323901d33f7cdbb8897
|
7
|
+
data.tar.gz: 02ed21413f0d437a77a8859cd7a4df76d296e4bf51f88c4470c8b9f74c89fefe32431cbb2658159fecc48bc79bdf4762f1db00bf21f2ff78fa81c239b29d765e
|
@@ -4,16 +4,16 @@ on: [push]
|
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
test:
|
7
|
-
runs-on:
|
7
|
+
runs-on: ${{ matrix.platform }}
|
8
8
|
|
9
9
|
strategy:
|
10
10
|
matrix:
|
11
|
+
platform: [ubuntu-latest, windows-latest]
|
11
12
|
version:
|
12
13
|
- 3.0.0
|
13
|
-
- 2.7.1
|
14
14
|
- 2.6.6
|
15
15
|
|
16
|
-
name: Ruby ${{ matrix.version }}
|
16
|
+
name: Ruby ${{ matrix.platform }} ${{ matrix.version }}
|
17
17
|
|
18
18
|
steps:
|
19
19
|
- uses: actions/checkout@v2
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
|
2
|
+
v1.5.0 / 2021-09-07
|
3
|
+
==================
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
* Add [DeprecatedGlobalAppBlockType](docs/checks/deprecated_global_app_block_type.md) ([#402](https://github.com/shopify/theme-check/issues/402))
|
8
|
+
|
9
|
+
### Fixes
|
10
|
+
|
11
|
+
* Add Windows CI
|
12
|
+
* Fix multiple Windows bugs ([#413](https://github.com/shopify/theme-check/issues/413), [#415](https://github.com/shopify/theme-check/issues/415))
|
13
|
+
* Fix pagination size as string bug in PaginationSize ([#417](https://github.com/shopify/theme-check/issues/417), [#421](https://github.com/shopify/theme-check/issues/421))
|
14
|
+
|
2
15
|
v1.4.0 / 2021-08-30
|
3
16
|
==================
|
4
17
|
|
data/config/default.yml
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Check for deprecated global app block type `@global`
|
2
|
+
This check makes sure theme sections are not using [deprecated (`@global`)][change_log] global app block type.
|
3
|
+
|
4
|
+
## Check Details
|
5
|
+
In order for theme sections to [support app blocks][support_app_blocks_in_theme_section], sections need to define a block of type `@app`. This check makes sure that theme sections are not using the deprecated (`@global`) global app block type in theme sections.
|
6
|
+
|
7
|
+
:-1: Example of **incorrect** theme section for this check:
|
8
|
+
```
|
9
|
+
{% for block in section.blocks %}
|
10
|
+
{% if block.type = "@global" %}
|
11
|
+
{% render block %}
|
12
|
+
{% endif %}
|
13
|
+
{% endfor %}
|
14
|
+
|
15
|
+
{% schema %}
|
16
|
+
{
|
17
|
+
"name": "Product section",
|
18
|
+
"blocks": [{"type": "@global"}]
|
19
|
+
}
|
20
|
+
{% endschema %}
|
21
|
+
```
|
22
|
+
|
23
|
+
:+1: Examples of **correct** theme section for this check:
|
24
|
+
```
|
25
|
+
{% for block in section.blocks %}
|
26
|
+
{% if block.type = "@app" %}
|
27
|
+
{% render block %}
|
28
|
+
{% endif %}
|
29
|
+
{% endfor %}
|
30
|
+
|
31
|
+
{% schema %}
|
32
|
+
{
|
33
|
+
"name": "Product section",
|
34
|
+
"blocks": [{"type": "@app"}]
|
35
|
+
}
|
36
|
+
{% endschema %}
|
37
|
+
```
|
38
|
+
|
39
|
+
## Check Options
|
40
|
+
|
41
|
+
The default configuration for this check is the following:
|
42
|
+
|
43
|
+
```yaml
|
44
|
+
DeprecatedGlobalAppBlockType:
|
45
|
+
enabled: true
|
46
|
+
```
|
47
|
+
|
48
|
+
## When Not To Use It
|
49
|
+
|
50
|
+
It is discouraged to disable this check.
|
51
|
+
|
52
|
+
## Version
|
53
|
+
|
54
|
+
This check has been introduced in Theme Check 1.5.0.
|
55
|
+
|
56
|
+
## Resources
|
57
|
+
|
58
|
+
- [Rule Source][codesource]
|
59
|
+
- [Documentation Source][docsource]
|
60
|
+
|
61
|
+
[codesource]: /lib/theme_check/checks/deprecated_global_app_block_type.rb
|
62
|
+
[docsource]: /docs/checks/deprecated_global_app_block_type.md
|
63
|
+
[remote_asset]: /docs/checks/deprecated_global_app_block_type.md
|
64
|
+
[support_app_blocks_in_theme_section]: https://shopify.dev/themes/migration#step-8-add-support-for-app-blocks-to-sections
|
65
|
+
[change_log]: https://shopify.dev/changelog/removing-the-global-block-type-in-favour-of-the-app-block-type-in-theme-sections
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ThemeCheck
|
3
|
+
class DeprecatedGlobalAppBlockType < LiquidCheck
|
4
|
+
severity :error
|
5
|
+
category :liquid
|
6
|
+
doc docs_url(__FILE__)
|
7
|
+
|
8
|
+
INVALID_GLOBAL_APP_BLOCK_TYPE = "@global"
|
9
|
+
VALID_GLOBAL_APP_BLOCK_TYPE = "@app"
|
10
|
+
|
11
|
+
def on_schema(node)
|
12
|
+
schema = JSON.parse(node.value.nodelist.join)
|
13
|
+
|
14
|
+
if block_types_from(schema).include?(INVALID_GLOBAL_APP_BLOCK_TYPE)
|
15
|
+
add_offense(
|
16
|
+
"Deprecated '#{INVALID_GLOBAL_APP_BLOCK_TYPE}' block type defined in the schema, use '#{VALID_GLOBAL_APP_BLOCK_TYPE}' block type instead.",
|
17
|
+
node: node
|
18
|
+
)
|
19
|
+
end
|
20
|
+
rescue JSON::ParserError
|
21
|
+
# Ignored, handled in ValidSchema.
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_case(node)
|
25
|
+
if node.value == INVALID_GLOBAL_APP_BLOCK_TYPE
|
26
|
+
report_offense(node)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def on_condition(node)
|
31
|
+
if node.value.right == INVALID_GLOBAL_APP_BLOCK_TYPE || node.value.left == INVALID_GLOBAL_APP_BLOCK_TYPE
|
32
|
+
report_offense(node)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_variable(node)
|
37
|
+
if node.value.name == INVALID_GLOBAL_APP_BLOCK_TYPE
|
38
|
+
report_offense(node)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def report_offense(node)
|
45
|
+
add_offense(
|
46
|
+
"Deprecated '#{INVALID_GLOBAL_APP_BLOCK_TYPE}' block type, use '#{VALID_GLOBAL_APP_BLOCK_TYPE}' block type instead.",
|
47
|
+
node: node
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def block_types_from(schema)
|
52
|
+
schema.fetch("blocks", []).map do |block|
|
53
|
+
block.fetch("type", "")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -54,12 +54,11 @@ module ThemeCheck
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def get_setting_default_value(setting_id)
|
57
|
-
setting = @schema_settings.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
nil
|
57
|
+
setting = @schema_settings.find { |s| s['id'] == setting_id }
|
58
|
+
return nil if setting.empty?
|
59
|
+
default_value = setting['default'].to_i
|
60
|
+
return nil if default_value == 0
|
61
|
+
default_value
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|
@@ -5,6 +5,7 @@ module ThemeCheck
|
|
5
5
|
class DocumentLinkProvider
|
6
6
|
include RegexHelpers
|
7
7
|
include PositionHelper
|
8
|
+
include URIHelper
|
8
9
|
|
9
10
|
class << self
|
10
11
|
attr_accessor :partial_regexp, :destination_directory, :destination_postfix
|
@@ -63,7 +64,7 @@ module ThemeCheck
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def file_link(partial)
|
66
|
-
|
67
|
+
file_uri(@storage.path(destination_directory + '/' + partial + destination_postfix))
|
67
68
|
end
|
68
69
|
end
|
69
70
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "benchmark"
|
3
|
-
require "uri"
|
4
|
-
require "cgi"
|
5
4
|
|
6
5
|
module ThemeCheck
|
7
6
|
module LanguageServer
|
8
7
|
class Handler
|
8
|
+
include URIHelper
|
9
|
+
|
9
10
|
CAPABILITIES = {
|
10
11
|
completionProvider: {
|
11
12
|
triggerCharacters: ['.', '{{ ', '{% '],
|
@@ -26,7 +27,7 @@ module ThemeCheck
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def on_initialize(id, params)
|
29
|
-
@root_path =
|
30
|
+
@root_path = root_path_from_params(params)
|
30
31
|
|
31
32
|
# Tell the client we don't support anything if there's no rootPath
|
32
33
|
return send_response(id, { capabilities: {} }) if @root_path.nil?
|
@@ -96,19 +97,23 @@ module ThemeCheck
|
|
96
97
|
end
|
97
98
|
|
98
99
|
def text_document_uri(params)
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def path_from_uri(uri_string)
|
103
|
-
return if uri_string.nil?
|
104
|
-
uri = URI(uri_string)
|
105
|
-
CGI.unescape(uri.path)
|
100
|
+
file_path(params.dig('textDocument', 'uri'))
|
106
101
|
end
|
107
102
|
|
108
103
|
def relative_path_from_text_document_uri(params)
|
109
104
|
@storage.relative_path(text_document_uri(params))
|
110
105
|
end
|
111
106
|
|
107
|
+
def root_path_from_params(params)
|
108
|
+
root_uri = params["rootUri"]
|
109
|
+
root_path = params["rootPath"]
|
110
|
+
if root_uri
|
111
|
+
file_path(root_uri)
|
112
|
+
elsif root_path
|
113
|
+
root_path
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
112
117
|
def text_document_text(params)
|
113
118
|
params.dig('textDocument', 'text')
|
114
119
|
end
|
@@ -174,7 +179,7 @@ module ThemeCheck
|
|
174
179
|
def send_diagnostic(path, offenses)
|
175
180
|
# https://microsoft.github.io/language-server-protocol/specifications/specification-current/#notificationMessage
|
176
181
|
send_notification('textDocument/publishDiagnostics', {
|
177
|
-
uri:
|
182
|
+
uri: file_uri(path),
|
178
183
|
diagnostics: offenses.map { |offense| offense_to_diagnostic(offense) },
|
179
184
|
})
|
180
185
|
end
|
@@ -25,6 +25,15 @@ module ThemeCheck
|
|
25
25
|
@out = out_stream
|
26
26
|
@err = err_stream
|
27
27
|
|
28
|
+
# Because programming is fun,
|
29
|
+
#
|
30
|
+
# Ruby on Windows turns \n into \r\n. Which means that \r\n
|
31
|
+
# gets turned into \r\r\n. Which means that the protocol
|
32
|
+
# breaks on windows unless we turn STDOUT into binary mode.
|
33
|
+
#
|
34
|
+
# Hours wasted: 9.
|
35
|
+
@out.binmode
|
36
|
+
|
28
37
|
@out.sync = true # do not buffer
|
29
38
|
@err.sync = true # do not buffer
|
30
39
|
|
@@ -52,19 +61,8 @@ module ThemeCheck
|
|
52
61
|
response_body = JSON.dump(response)
|
53
62
|
log(JSON.pretty_generate(response)) if $DEBUG
|
54
63
|
|
55
|
-
#
|
56
|
-
|
57
|
-
# Ruby on Windows turns \n into \r\n. Which means that \r\n
|
58
|
-
# gets turned into \r\r\n. Which means that the protocol
|
59
|
-
# breaks on windows unless we turn STDOUT into binary mode and
|
60
|
-
# set the encoding manually (yuk!) or we do this little hack
|
61
|
-
# here and put \n which gets transformed into \r\n on windows
|
62
|
-
# only...
|
63
|
-
#
|
64
|
-
# Hours wasted: 8.
|
65
|
-
eol = Gem.win_platform? ? "\n" : "\r\n"
|
66
|
-
@out.write("Content-Length: #{response_body.bytesize}#{eol}")
|
67
|
-
@out.write(eol)
|
64
|
+
@out.write("Content-Length: #{response_body.bytesize}\r\n")
|
65
|
+
@out.write("\r\n")
|
68
66
|
@out.write(response_body)
|
69
67
|
@out.flush
|
70
68
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "benchmark"
|
4
|
+
require "uri"
|
5
|
+
require "cgi"
|
6
|
+
|
7
|
+
module ThemeCheck
|
8
|
+
module LanguageServer
|
9
|
+
module URIHelper
|
10
|
+
# Will URI.encode a string the same way VS Code would. There are two things
|
11
|
+
# to watch out for:
|
12
|
+
#
|
13
|
+
# 1. VS Code still uses the outdated '%20' for spaces
|
14
|
+
# 2. VS Code prefixes Windows paths with / (so /C:/Users/... is expected)
|
15
|
+
#
|
16
|
+
# Exists because of https://github.com/Shopify/theme-check/issues/360
|
17
|
+
def file_uri(absolute_path)
|
18
|
+
"file://" + absolute_path
|
19
|
+
.to_s
|
20
|
+
.split('/')
|
21
|
+
.map { |x| CGI.escape(x).gsub('+', '%20') }
|
22
|
+
.join('/')
|
23
|
+
.sub(%r{^/?}, '/') # Windows paths should be prefixed by /c:
|
24
|
+
end
|
25
|
+
|
26
|
+
def file_path(uri_string)
|
27
|
+
return if uri_string.nil?
|
28
|
+
uri = URI(uri_string)
|
29
|
+
path = CGI.unescape(uri.path)
|
30
|
+
# On Windows, VS Code sends the URLs as file:///C:/...
|
31
|
+
# /C:/1234 is not a valid path in ruby. So we strip the slash.
|
32
|
+
path = path.sub(%r{^/([a-z]:/)}i, '\1')
|
33
|
+
path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require_relative "language_server/protocol"
|
3
3
|
require_relative "language_server/constants"
|
4
|
+
require_relative "language_server/uri_helper"
|
4
5
|
require_relative "language_server/handler"
|
5
6
|
require_relative "language_server/server"
|
6
7
|
require_relative "language_server/tokens"
|
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.
|
4
|
+
version: 1.5.0
|
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-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- docs/checks/deprecate_bgsizes.md
|
91
91
|
- docs/checks/deprecate_lazysizes.md
|
92
92
|
- docs/checks/deprecated_filter.md
|
93
|
+
- docs/checks/deprecated_global_app_block_type.md
|
93
94
|
- docs/checks/html_parsing_error.md
|
94
95
|
- docs/checks/img_lazy_loading.md
|
95
96
|
- docs/checks/img_width_and_height.md
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- lib/theme_check/checks/deprecate_bgsizes.rb
|
141
142
|
- lib/theme_check/checks/deprecate_lazysizes.rb
|
142
143
|
- lib/theme_check/checks/deprecated_filter.rb
|
144
|
+
- lib/theme_check/checks/deprecated_global_app_block_type.rb
|
143
145
|
- lib/theme_check/checks/html_parsing_error.rb
|
144
146
|
- lib/theme_check/checks/img_lazy_loading.rb
|
145
147
|
- lib/theme_check/checks/img_width_and_height.rb
|
@@ -203,6 +205,7 @@ files:
|
|
203
205
|
- lib/theme_check/language_server/protocol.rb
|
204
206
|
- lib/theme_check/language_server/server.rb
|
205
207
|
- lib/theme_check/language_server/tokens.rb
|
208
|
+
- lib/theme_check/language_server/uri_helper.rb
|
206
209
|
- lib/theme_check/language_server/variable_lookup_finder.rb
|
207
210
|
- lib/theme_check/liquid_check.rb
|
208
211
|
- lib/theme_check/locale_diff.rb
|