theme-check 0.8.1 → 0.10.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 -0
- data/CHANGELOG.md +39 -0
- data/CONTRIBUTING.md +2 -1
- data/README.md +4 -1
- data/RELEASING.md +5 -3
- data/config/default.yml +46 -1
- data/data/shopify_liquid/tags.yml +3 -0
- data/docs/checks/asset_url_filters.md +56 -0
- data/docs/checks/content_for_header_modification.md +42 -0
- data/docs/checks/img_lazy_loading.md +61 -0
- data/docs/checks/nested_snippet.md +1 -1
- data/docs/checks/parser_blocking_script_tag.md +53 -0
- data/docs/checks/space_inside_braces.md +22 -0
- data/exe/theme-check-language-server +1 -2
- data/lib/theme_check.rb +9 -1
- data/lib/theme_check/analyzer.rb +72 -16
- data/lib/theme_check/bug.rb +20 -0
- data/lib/theme_check/check.rb +31 -6
- data/lib/theme_check/checks.rb +49 -4
- data/lib/theme_check/checks/asset_url_filters.rb +46 -0
- data/lib/theme_check/checks/content_for_header_modification.rb +41 -0
- data/lib/theme_check/checks/img_lazy_loading.rb +25 -0
- data/lib/theme_check/checks/img_width_and_height.rb +18 -49
- data/lib/theme_check/checks/missing_template.rb +1 -0
- data/lib/theme_check/checks/nested_snippet.rb +1 -1
- data/lib/theme_check/checks/parser_blocking_javascript.rb +6 -38
- data/lib/theme_check/checks/parser_blocking_script_tag.rb +20 -0
- data/lib/theme_check/checks/remote_asset.rb +21 -79
- data/lib/theme_check/checks/space_inside_braces.rb +5 -5
- data/lib/theme_check/checks/template_length.rb +3 -0
- data/lib/theme_check/checks/valid_html_translation.rb +1 -0
- data/lib/theme_check/config.rb +2 -0
- data/lib/theme_check/disabled_check.rb +6 -4
- data/lib/theme_check/disabled_checks.rb +25 -9
- data/lib/theme_check/html_check.rb +7 -0
- data/lib/theme_check/html_node.rb +56 -0
- data/lib/theme_check/html_visitor.rb +38 -0
- data/lib/theme_check/json_file.rb +8 -0
- data/lib/theme_check/language_server.rb +2 -0
- data/lib/theme_check/language_server/completion_providers/filter_completion_provider.rb +1 -0
- data/lib/theme_check/language_server/completion_providers/object_completion_provider.rb +10 -8
- data/lib/theme_check/language_server/diagnostics_tracker.rb +64 -0
- data/lib/theme_check/language_server/handler.rb +31 -26
- data/lib/theme_check/language_server/server.rb +1 -1
- data/lib/theme_check/language_server/variable_lookup_finder.rb +295 -0
- data/lib/theme_check/liquid_check.rb +1 -4
- data/lib/theme_check/offense.rb +18 -0
- data/lib/theme_check/shopify_liquid/tag.rb +13 -0
- data/lib/theme_check/template.rb +8 -0
- data/lib/theme_check/theme.rb +7 -2
- data/lib/theme_check/version.rb +1 -1
- data/lib/theme_check/visitor.rb +2 -11
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b606fffc2525680e6d47cf1d45b3fbdd514c79cf426dfd28baaec20e1cc083f
|
4
|
+
data.tar.gz: f0b9e3b0da8f41ae48e11d91ff1ccd780e0ed6cc5b8ba80694c3cd70a33e04a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ce6e8b332e57cf523db93cf14ca9c948e569703633d5b82f106e95e66dd613ab30fa448226cf4f624b24da2675179220e7fc9fe206bfa9521f722c74356ba2
|
7
|
+
data.tar.gz: 22e2469eba1fc8aca4e881cfc5d0ad5ea7c16a057cdba6327310906099497b72d18dbef2d4f69d328528d6801f0abb91fac78a692f68387f7378d2c8fd3986dd
|
@@ -34,3 +34,6 @@ jobs:
|
|
34
34
|
run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
|
35
35
|
- name: Run tests
|
36
36
|
run: bundle exec rake
|
37
|
+
- name: Test runtime
|
38
|
+
# Testing that runtime can execute, not testing the results themselves
|
39
|
+
run: bundle exec theme-check ./test/theme | grep -q "files inspected"
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,43 @@
|
|
1
1
|
|
2
|
+
v0.10.0 / 2021-06-08
|
3
|
+
==================
|
4
|
+
|
5
|
+
* Add ImgLazyLoading check for recommending loading="lazy" attribute
|
6
|
+
|
7
|
+
v0.9.1 / 2021-06-04
|
8
|
+
==================
|
9
|
+
|
10
|
+
* Convert `RemoteAsset` into an `HtmlCheck`
|
11
|
+
* Move Liquid logic from `RemoteAsset` to a new `AssetUrlFilters` check
|
12
|
+
|
13
|
+
v0.9.0 / 2021-05-28
|
14
|
+
==================
|
15
|
+
|
16
|
+
* Introduce HtmlCheck, and convert ParserBlockingJavaScript & ImgWidthAndHeight to it
|
17
|
+
* Move `script-tag` validation from ParserBlockingJavaScript to ParserBlockingScriptTag
|
18
|
+
* Add ability to ignore individual checks using file patterns
|
19
|
+
* Introduce single file and whole theme checks to optimize LSP diagnostics
|
20
|
+
* Fix TemplateLength counter not being reseted on each document
|
21
|
+
* Add missing category to ValidHTMLTranslation
|
22
|
+
* Set Ruby default encodings to UTF-8 to fix encoding issues
|
23
|
+
* Add ContentForHeaderModification check to prevent relying on the content of ``content_for_header`
|
24
|
+
* Fix `Content-Length` in LSP responses
|
25
|
+
* Fix disabling checks that emit offences in `on_end`
|
26
|
+
* Fix completion bug in `filter_completion_provider`
|
27
|
+
|
28
|
+
v0.8.3 / 2021-05-17
|
29
|
+
==================
|
30
|
+
|
31
|
+
* Making sure VERSION is set before referencing it
|
32
|
+
|
33
|
+
v0.8.2 / 2021-05-14
|
34
|
+
===================
|
35
|
+
|
36
|
+
* Bump NestedSnippet max_nesting_level to 3
|
37
|
+
* Add a message to help debug errors, and timeout checks after 5 sec
|
38
|
+
* Object Completions Everywhere!
|
39
|
+
* Include operators to space inside braces check
|
40
|
+
|
2
41
|
0.8.1 / 2021-04-22
|
3
42
|
==================
|
4
43
|
|
data/CONTRIBUTING.md
CHANGED
@@ -41,7 +41,8 @@ Under `lib/theme_check/checks`, create new Ruby file with a unique name describi
|
|
41
41
|
```ruby
|
42
42
|
module ThemeCheck
|
43
43
|
# Does one thing, and does it well!
|
44
|
-
# NOTE: inherit from JsonCheck to implement a JSON
|
44
|
+
# NOTE: inherit from `JsonCheck` to implement a JSON-based check, and from `HtmlCheck`
|
45
|
+
# to implement an HTML-based one. See other checks in `lib/theme_check/checks` for examples.
|
45
46
|
class MyCheckName < LiquidCheck
|
46
47
|
severity :suggestion # :error or :style
|
47
48
|
|
data/README.md
CHANGED
@@ -92,11 +92,14 @@ root: dist
|
|
92
92
|
require:
|
93
93
|
- ./path/to/my_custom_check.rb
|
94
94
|
|
95
|
-
# Disable some checks
|
96
95
|
TemplateLength:
|
96
|
+
# Disable some checks
|
97
97
|
enabled: false
|
98
98
|
# Or configure options
|
99
99
|
max_length: 300
|
100
|
+
# Or ignore certain paths
|
101
|
+
ignore:
|
102
|
+
- snippets/icon-*
|
100
103
|
|
101
104
|
# Enable a custom check
|
102
105
|
MyCustomCheck
|
data/RELEASING.md
CHANGED
@@ -9,11 +9,13 @@
|
|
9
9
|
rake prerelease[$VERSION]
|
10
10
|
```
|
11
11
|
|
12
|
-
3.
|
12
|
+
3. Run [`git changelog`](https://github.com/tj/git-extras) to update `CHANGELOG.md`.
|
13
13
|
|
14
|
-
4.
|
14
|
+
4. Commit your changes and make a PR.
|
15
15
|
|
16
|
-
5.
|
16
|
+
5. Merge your PR to master.
|
17
|
+
|
18
|
+
6. On [Shipit](https://shipit.shopify.io/shopify/theme-check/rubygems), deploy your commit.
|
17
19
|
|
18
20
|
## Homebrew Release Process
|
19
21
|
|
data/config/default.yml
CHANGED
@@ -7,92 +7,137 @@ ignore:
|
|
7
7
|
|
8
8
|
ConvertIncludeToRender:
|
9
9
|
enabled: true
|
10
|
+
ignore: []
|
10
11
|
|
11
12
|
LiquidTag:
|
12
13
|
enabled: true
|
14
|
+
ignore: []
|
13
15
|
min_consecutive_statements: 4
|
14
16
|
|
15
17
|
MissingTemplate:
|
16
18
|
enabled: true
|
19
|
+
ignore: []
|
17
20
|
|
18
21
|
NestedSnippet:
|
19
22
|
enabled: true
|
20
|
-
|
23
|
+
ignore: []
|
24
|
+
max_nesting_level: 3
|
21
25
|
|
22
26
|
RequiredLayoutThemeObject:
|
23
27
|
enabled: true
|
28
|
+
ignore: []
|
24
29
|
|
25
30
|
SpaceInsideBraces:
|
26
31
|
enabled: true
|
32
|
+
ignore: []
|
27
33
|
|
28
34
|
SyntaxError:
|
29
35
|
enabled: true
|
36
|
+
ignore: []
|
30
37
|
|
31
38
|
TemplateLength:
|
32
39
|
enabled: true
|
40
|
+
ignore: []
|
33
41
|
max_length: 200
|
34
42
|
# Exclude content of {% schema %} in line count
|
35
43
|
exclude_schema: true
|
36
44
|
|
37
45
|
UnknownFilter:
|
38
46
|
enabled: true
|
47
|
+
ignore: []
|
39
48
|
|
40
49
|
UnusedAssign:
|
41
50
|
enabled: true
|
51
|
+
ignore: []
|
42
52
|
|
43
53
|
UnusedSnippet:
|
44
54
|
enabled: true
|
55
|
+
ignore: []
|
45
56
|
|
46
57
|
MatchingSchemaTranslations:
|
47
58
|
enabled: true
|
59
|
+
ignore: []
|
48
60
|
|
49
61
|
MatchingTranslations:
|
50
62
|
enabled: true
|
63
|
+
ignore: []
|
51
64
|
|
52
65
|
DefaultLocale:
|
53
66
|
enabled: true
|
67
|
+
ignore: []
|
54
68
|
|
55
69
|
TranslationKeyExists:
|
56
70
|
enabled: true
|
71
|
+
ignore: []
|
57
72
|
|
58
73
|
ValidHTMLTranslation:
|
59
74
|
enabled: true
|
75
|
+
ignore: []
|
60
76
|
|
61
77
|
ValidJson:
|
62
78
|
enabled: true
|
79
|
+
ignore: []
|
63
80
|
|
64
81
|
ValidSchema:
|
65
82
|
enabled: true
|
83
|
+
ignore: []
|
66
84
|
|
67
85
|
MissingRequiredTemplateFiles:
|
68
86
|
enabled: true
|
87
|
+
ignore: []
|
69
88
|
|
70
89
|
UndefinedObject:
|
71
90
|
enabled: true
|
91
|
+
ignore: []
|
72
92
|
exclude_snippets: true
|
73
93
|
|
74
94
|
RequiredDirectories:
|
75
95
|
enabled: true
|
96
|
+
ignore: []
|
76
97
|
|
77
98
|
DeprecatedFilter:
|
78
99
|
enabled: true
|
100
|
+
ignore: []
|
79
101
|
|
80
102
|
MissingEnableComment:
|
81
103
|
enabled: true
|
104
|
+
ignore: []
|
82
105
|
|
83
106
|
ParserBlockingJavaScript:
|
84
107
|
enabled: true
|
108
|
+
ignore: []
|
109
|
+
|
110
|
+
ParserBlockingScriptTag:
|
111
|
+
enabled: true
|
85
112
|
|
86
113
|
AssetSizeJavaScript:
|
87
114
|
enabled: false
|
115
|
+
ignore: []
|
88
116
|
threshold_in_bytes: 10_000
|
117
|
+
ignore: []
|
89
118
|
|
90
119
|
AssetSizeCSS:
|
91
120
|
enabled: false
|
121
|
+
ignore: []
|
92
122
|
threshold_in_bytes: 100_000
|
123
|
+
ignore: []
|
93
124
|
|
94
125
|
ImgWidthAndHeight:
|
95
126
|
enabled: true
|
127
|
+
ignore: []
|
96
128
|
|
97
129
|
RemoteAsset:
|
98
130
|
enabled: true
|
131
|
+
ignore: []
|
132
|
+
|
133
|
+
AssetUrlFilters:
|
134
|
+
enabled: true
|
135
|
+
ignore: []
|
136
|
+
|
137
|
+
ContentForHeaderModification:
|
138
|
+
enabled: true
|
139
|
+
ignore: []
|
140
|
+
|
141
|
+
ImgLazyLoading:
|
142
|
+
enabled: true
|
143
|
+
ignore: []
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Ensure `asset_url` filters are used when serving assets (`AssetUrlFilters`)
|
2
|
+
|
3
|
+
See the [`RemoteAsset` check documentation][remote_asset] for a detailed explanation on why remote assets are discouraged.
|
4
|
+
|
5
|
+
## Check Details
|
6
|
+
|
7
|
+
This check is aimed at eliminating unnecessary HTTP connections.
|
8
|
+
|
9
|
+
:-1: Examples of **incorrect** code for this check:
|
10
|
+
|
11
|
+
```liquid
|
12
|
+
<!-- Using multiple CDNs -->
|
13
|
+
{{ "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" | stylesheet_tag }}
|
14
|
+
|
15
|
+
<!-- Missing img_url filter -->
|
16
|
+
{{ url | img_tag }}
|
17
|
+
```
|
18
|
+
|
19
|
+
:+1: Examples of **correct** code for this check:
|
20
|
+
|
21
|
+
```liquid
|
22
|
+
{{ 'bootstrap.min.css' | asset_url | stylesheet_tag }}
|
23
|
+
|
24
|
+
<!-- Images -->
|
25
|
+
{{ url | img_url | img_tag }}
|
26
|
+
```
|
27
|
+
|
28
|
+
Use the [`assets_url`](asset_url) or [`img_url`](img_url) filter to load the files in your theme's `assets/` folder from the Shopify CDN.
|
29
|
+
|
30
|
+
## Check Options
|
31
|
+
|
32
|
+
The default configuration for this check is the following:
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
AssetUrlFilters:
|
36
|
+
enabled: true
|
37
|
+
```
|
38
|
+
|
39
|
+
## When Not To Use It
|
40
|
+
|
41
|
+
When the remote content is highly dynamic.
|
42
|
+
|
43
|
+
## Version
|
44
|
+
|
45
|
+
This check has been introduced in Theme Check 0.9.1.
|
46
|
+
|
47
|
+
## Resources
|
48
|
+
|
49
|
+
- [Rule Source][codesource]
|
50
|
+
- [Documentation Source][docsource]
|
51
|
+
|
52
|
+
[codesource]: /lib/theme_check/checks/remote_asset_filters.rb
|
53
|
+
[docsource]: /docs/checks/remote_asset_filters.md
|
54
|
+
[remote_asset]: /docs/checks/remote_asset.md
|
55
|
+
[asset_url]: https://shopify.dev/docs/themes/liquid/reference/filters/url-filters#assert_url
|
56
|
+
[img_url]: https://shopify.dev/docs/themes/liquid/reference/filters/url-filters#img_url
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Do not depend on the content of `content_for_header` (`ContentForHeaderModification`)
|
2
|
+
|
3
|
+
Do not rely on the content of `content_for_header` as it might change in the future, which could cause your Liquid code behavior to change.
|
4
|
+
|
5
|
+
## Check Details
|
6
|
+
|
7
|
+
:-1: Examples of **incorrect** code for this check:
|
8
|
+
|
9
|
+
```liquid
|
10
|
+
{% assign parts = content_for_header | split: ',' %}
|
11
|
+
```
|
12
|
+
|
13
|
+
:+1: Examples of **correct** code for this check:
|
14
|
+
|
15
|
+
The only acceptable usage of `content_for_header` is:
|
16
|
+
|
17
|
+
```liquid
|
18
|
+
{{ content_for_header }}
|
19
|
+
```
|
20
|
+
|
21
|
+
## Check Options
|
22
|
+
|
23
|
+
The default configuration for this check is the following:
|
24
|
+
|
25
|
+
```yaml
|
26
|
+
ContentForHeaderModification:
|
27
|
+
enabled: true
|
28
|
+
```
|
29
|
+
|
30
|
+
## Version
|
31
|
+
|
32
|
+
This check has been introduced in Theme Check 0.9.0.
|
33
|
+
|
34
|
+
## Resources
|
35
|
+
|
36
|
+
- [Rule Source][codesource]
|
37
|
+
- [Documentation Source][docsource]
|
38
|
+
- [`theme.liquid` template considerations][considerations]
|
39
|
+
|
40
|
+
[codesource]: /lib/theme_check/checks/check_class_name.rb
|
41
|
+
[docsource]: /docs/checks/check_class_name.md
|
42
|
+
[considerations]: https://shopify.dev/docs/themes/theme-templates/theme-liquid#template-considerations
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Lazy loading image tags (`ImgLazyLoading`)
|
2
|
+
|
3
|
+
Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the length of the critical rendering path, which translates into reduced page load times.
|
4
|
+
|
5
|
+
Lazy loading can occur on different moments in the application, but it typically happens on some user interactions such as scrolling and navigation.
|
6
|
+
|
7
|
+
Very often, webpages contain many images that contribute to data-usage and how fast a page can load. Most of those images are off-screen (non-critical), requiring user interaction (an example being scroll) in order to view them.
|
8
|
+
|
9
|
+
_Quoted from [MDN - Lazy loading][mdn]_
|
10
|
+
|
11
|
+
## Check Details
|
12
|
+
|
13
|
+
This check is aimed at defering loading non-critical images.
|
14
|
+
|
15
|
+
:-1: Examples of **incorrect** code for this check:
|
16
|
+
|
17
|
+
```liquid
|
18
|
+
<img src="a.jpg">
|
19
|
+
|
20
|
+
<!-- Replaces lazysize.js -->
|
21
|
+
<img src="a.jpg" class="lazyload">
|
22
|
+
|
23
|
+
<!-- `auto` is deprecated -->
|
24
|
+
<img src="a.jpg" loading="auto">
|
25
|
+
```
|
26
|
+
|
27
|
+
:+1: Examples of **correct** code for this check:
|
28
|
+
|
29
|
+
```liquid
|
30
|
+
<img src="a.jpg" loading="lazy">
|
31
|
+
|
32
|
+
<!-- `eager` is also accepted, but prefer `lazy` -->
|
33
|
+
<img src="a.jpg" loading="eager">
|
34
|
+
```
|
35
|
+
|
36
|
+
## Check Options
|
37
|
+
|
38
|
+
The default configuration for this check is the following:
|
39
|
+
|
40
|
+
```yaml
|
41
|
+
ImgLazyLoading:
|
42
|
+
enabled: true
|
43
|
+
```
|
44
|
+
|
45
|
+
## When Not To Use It
|
46
|
+
|
47
|
+
If you don't want to defer loading of images, then it's safe to disable this rule.
|
48
|
+
|
49
|
+
## Version
|
50
|
+
|
51
|
+
This check has been introduced in Theme Check 0.10.0.
|
52
|
+
|
53
|
+
## Resources
|
54
|
+
|
55
|
+
- [Rule Source][codesource]
|
56
|
+
- [Documentation Source][docsource]
|
57
|
+
- [MDN - Lazy loading][mdn]
|
58
|
+
|
59
|
+
[codesource]: /lib/theme_check/checks/img_lazy_loading.rb
|
60
|
+
[docsource]: /docs/checks/img_lazy_loading.md
|
61
|
+
[mdn]: https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Discourage use of parser-blocking `script_tag` filter (`ParserBlockingScriptTag`)
|
2
|
+
|
3
|
+
The `script_tag` filter emits a parser-blocking script tag.
|
4
|
+
|
5
|
+
See the [ParserBlockingJavaScript check documentation][parser_blocking_javascript] for why this is generally discouraged.
|
6
|
+
|
7
|
+
## Check Details
|
8
|
+
|
9
|
+
This check is aimed at eliminating parser-blocking JavaScript on themes.
|
10
|
+
|
11
|
+
:-1: Examples of **incorrect** code for this check:
|
12
|
+
|
13
|
+
```liquid
|
14
|
+
<!-- The script_tag filter outputs a parser-blocking script -->
|
15
|
+
{{ 'app-code.js' | asset_url | script_tag }}
|
16
|
+
```
|
17
|
+
|
18
|
+
:+1: Examples of **correct** code for this check:
|
19
|
+
|
20
|
+
```liquid
|
21
|
+
<!-- Good. Using the asset_url filter + defer -->
|
22
|
+
<script src="{{ 'theme.js' | asset_url }}" defer></script>
|
23
|
+
|
24
|
+
<!-- Also good. Using the asset_url filter + async -->
|
25
|
+
<script src="{{ 'theme.js' | asset_url }}" async></script>
|
26
|
+
```
|
27
|
+
|
28
|
+
## Check Options
|
29
|
+
|
30
|
+
The default configuration for this check is the following:
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
ParserBlockingScriptTag:
|
34
|
+
enabled: true
|
35
|
+
```
|
36
|
+
|
37
|
+
## When Not To Use It
|
38
|
+
|
39
|
+
This should only be turned off with the `theme-check-disable` comment when there's no better way to accomplish what you're doing than with a parser-blocking script.
|
40
|
+
|
41
|
+
It is discouraged to turn this rule off.
|
42
|
+
|
43
|
+
## Version
|
44
|
+
|
45
|
+
This check has been introduced in Theme Check 0.9.0.
|
46
|
+
|
47
|
+
## Resources
|
48
|
+
|
49
|
+
- [ParserBlockingJavaScript check][parser_blocking_javascript]
|
50
|
+
- [Documentation Source][docsource]
|
51
|
+
|
52
|
+
[parser_blocking_javascript]: /docs/checks/parser_blocking_javascript.md
|
53
|
+
[docsource]: /docs/checks/parser_blocking_script_tag.md
|