theme-check 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/cla.yml +22 -0
- data/.github/workflows/theme-check.yml +1 -1
- data/CHANGELOG.md +58 -0
- data/README.md +7 -8
- data/config/default.yml +5 -0
- data/config/theme_app_extension.yml +1 -0
- data/data/shopify_liquid/filters.yml +18 -0
- data/data/shopify_liquid/theme_app_extension_objects.yml +2 -0
- data/dev.yml +1 -1
- data/docs/api/check.md +1 -1
- data/docs/checks/TEMPLATE.md.erb +1 -1
- data/docs/checks/asset_preload.md +60 -0
- data/docs/checks/asset_size_javascript.md +2 -2
- data/docs/checks/missing_enable_comment.md +3 -3
- data/docs/checks/nested_snippet.md +8 -8
- data/docs/checks/schema_json_format.md +1 -1
- data/docs/checks/translation_key_exists.md +4 -4
- data/docs/checks/valid_html_translation.md +1 -1
- data/lib/theme_check/analyzer.rb +18 -3
- data/lib/theme_check/check.rb +6 -1
- data/lib/theme_check/checks/asset_preload.rb +20 -0
- data/lib/theme_check/checks/deprecated_filter.rb +29 -5
- data/lib/theme_check/checks/missing_enable_comment.rb +4 -0
- data/lib/theme_check/checks/missing_required_template_files.rb +5 -1
- data/lib/theme_check/checks/missing_template.rb +5 -1
- data/lib/theme_check/checks/translation_key_exists.rb +1 -0
- data/lib/theme_check/checks/undefined_object.rb +9 -1
- data/lib/theme_check/checks/unused_assign.rb +6 -1
- data/lib/theme_check/checks/unused_snippet.rb +50 -2
- data/lib/theme_check/config.rb +4 -3
- data/lib/theme_check/disabled_checks.rb +11 -4
- data/lib/theme_check/file_system_storage.rb +2 -0
- data/lib/theme_check/in_memory_storage.rb +1 -1
- data/lib/theme_check/json_printer.rb +1 -1
- data/lib/theme_check/language_server/bridge.rb +31 -6
- data/lib/theme_check/language_server/diagnostics_engine.rb +80 -34
- data/lib/theme_check/language_server/diagnostics_manager.rb +27 -6
- data/lib/theme_check/language_server/execute_command_providers/run_checks_execute_command_provider.rb +7 -6
- data/lib/theme_check/language_server/handler.rb +90 -8
- data/lib/theme_check/language_server/server.rb +42 -14
- data/lib/theme_check/language_server/versioned_in_memory_storage.rb +17 -2
- data/lib/theme_check/liquid_file.rb +22 -1
- data/lib/theme_check/liquid_node.rb +33 -1
- data/lib/theme_check/liquid_visitor.rb +1 -1
- data/lib/theme_check/schema_helper.rb +1 -1
- data/lib/theme_check/shopify_liquid/object.rb +4 -0
- data/lib/theme_check/tags.rb +20 -3
- data/lib/theme_check/version.rb +1 -1
- data/theme-check.gemspec +2 -2
- metadata +12 -7
- data/.github/probots.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99089d8a9e02b33f55c11e18d0d0dea02f8b4b9be24f548c2ba4852823d54d2e
|
4
|
+
data.tar.gz: aa7c80503782d3817fe49fd4460ff565144339c19ea87a1ec9c516573116299f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99f92709c2d233e05f5ba79b9c83243fc3fe3cd0ce640c7b2444b24c7922f57e76d40910997fab8ac7aa10ffe553ae3fcfde68bc310e0330279f0bb4419bd9d8
|
7
|
+
data.tar.gz: 6e43b16af119f881d5ae36501d638b7bb1459fe4fdfe124f396338012d28b5e5c8f4ad9b28b8ab3e3afd83c92044391ae31af6ca3f3914f898501d08e7710ca3
|
@@ -0,0 +1,29 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
<!--A clear and concise description of what the bug is.-->
|
12
|
+
|
13
|
+
**Expected**
|
14
|
+
<!-- Include what you expect should happen here -->
|
15
|
+
|
16
|
+
**Actual**
|
17
|
+
<!-- Include a description of what actually happens here -->
|
18
|
+
|
19
|
+
**Stack trace**
|
20
|
+
```
|
21
|
+
<!-- When provided, please include the entire error message in here -->
|
22
|
+
```
|
23
|
+
|
24
|
+
**Debugging information**
|
25
|
+
- OS [e.g. Windows, Mac, Linux]
|
26
|
+
- Version (output of `theme-check --version` in a terminal)
|
27
|
+
|
28
|
+
**Additional context**
|
29
|
+
<!-- Add any other context or screenshots about the problem here. -->
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
<!-- A clear and concise description of what you want to happen. -->
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
<!-- Add any other context or screenshots about the feature request here. -->
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Contributor License Agreement (CLA)
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types: [opened, synchronize]
|
6
|
+
issue_comment:
|
7
|
+
types: [created]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
cla:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
if: |
|
13
|
+
(github.event.issue.pull_request
|
14
|
+
&& !github.event.issue.pull_request.merged_at
|
15
|
+
&& contains(github.event.comment.body, 'signed')
|
16
|
+
)
|
17
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
18
|
+
steps:
|
19
|
+
- uses: Shopify/shopify-cla-action@v1
|
20
|
+
with:
|
21
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
22
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,62 @@
|
|
1
1
|
|
2
|
+
v1.11.0 / 2022-08-22
|
3
|
+
====================
|
4
|
+
|
5
|
+
## TL;DR
|
6
|
+
|
7
|
+
* New check, overdue fixes and dropped support for ruby 2.6.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
* :new: [AssetPreload](https://github.com/Shopify/theme-check/blob/main/docs/checks/asset_preload.md) check ([#605](https://github.com/shopify/theme-check/issues/605)). Thanks @krzksz!
|
12
|
+
* Encourages the use of the new platform features for some sweet 103 Early Hints gains powered by the `preload_tag` and `preload: true` media filter argument.
|
13
|
+
|
14
|
+
## Fixes:
|
15
|
+
|
16
|
+
### General
|
17
|
+
|
18
|
+
* Add support for new comment syntax `{% # this is an inline comment %}` ([#533](https://github.com/shopify/theme-check/issues/533))
|
19
|
+
* Fix UnusedAssign false positives from `{% render ... with|for var %}` ([#608](https://github.com/shopify/theme-check/issues/608))
|
20
|
+
* Update list of platform filters ([#626](https://github.com/shopify/theme-check/issues/626))
|
21
|
+
|
22
|
+
### Language Server
|
23
|
+
|
24
|
+
* Make `runChecks` command respect `onlySingleFileChecks` LSP config ([#624](https://github.com/shopify/theme-check/issues/624))
|
25
|
+
* Handle file delete|rename ([#611](https://github.com/shopify/theme-check/issues/611))
|
26
|
+
* Prevent server from hanging on error ([#623](https://github.com/shopify/theme-check/issues/623))
|
27
|
+
|
28
|
+
### Linter
|
29
|
+
|
30
|
+
* Help migrate named sizes (master|pico|etc.) in `img_url` with `DeprecatedFilter` corrector ([#619](https://github.com/shopify/theme-check/issues/619))
|
31
|
+
* Fix MissingTemplate `ignore` config interactions (#613)
|
32
|
+
* Fix MissingRequiredTemplateFiles JSON file corrector ([#616](https://github.com/shopify/theme-check/issues/616))
|
33
|
+
* Fixes theme-check-disable when disable comment is followed by another (#617)
|
34
|
+
* Fix handling of `{% render block %}` in UnusedSnippet ([#615](https://github.com/shopify/theme-check/issues/615))
|
35
|
+
* Fix IndexError: string not matched in matching translation keys fixer ([#602](https://github.com/shopify/theme-check/issues/602))
|
36
|
+
* Handle variable lookup as names in UnusedAssign ([#612](https://github.com/shopify/theme-check/issues/612))
|
37
|
+
|
38
|
+
## Breaking change (maybe)
|
39
|
+
|
40
|
+
* Bump min version of ruby to 2.7 ([#609](https://github.com/shopify/theme-check/issues/609))
|
41
|
+
* Upstream change from Shopify/liquid as ruby 2.6 is now EOL.
|
42
|
+
|
43
|
+
v1.10.3 / 2022-06-16
|
44
|
+
==================
|
45
|
+
|
46
|
+
* Support app drop in theme app extensions ([#566](https://github.com/shopify/theme-check/issues/566))
|
47
|
+
* Fix requiring custom check when root is specified ([#565](https://github.com/shopify/theme-check/issues/565))
|
48
|
+
* Fix TranslationKeyExists.on_end issue ([#587](https://github.com/shopify/theme-check/issues/587))
|
49
|
+
* Fix bad link on check documentation ([#575](https://github.com/shopify/theme-check/issues/575))
|
50
|
+
* Update TEMPLATE.md.erb to use shopify.dev URL
|
51
|
+
* Fixed broken URL ([#574](https://github.com/shopify/theme-check/issues/574))
|
52
|
+
* Fix unknown configuration issue for UndefinedObject checker ([#568](https://github.com/shopify/theme-check/issues/568))
|
53
|
+
|
54
|
+
v1.10.2 / 2022-03-07
|
55
|
+
====================
|
56
|
+
|
57
|
+
* Handle nil paths in json_printer's sort_by ([#561](https://github.com/shopify/theme-check/issues/561))
|
58
|
+
* Prevent bad render tags from passing theme-check ([#559](https://github.com/shopify/theme-check/issues/559))
|
59
|
+
|
2
60
|
v1.10.1 / 2022-02-24
|
3
61
|
====================
|
4
62
|
|
data/README.md
CHANGED
@@ -115,32 +115,31 @@ See [config/default.yml](config/default.yml) for available options & defaults.
|
|
115
115
|
Use Liquid comments to disable and re-enable all checks for a section of your template:
|
116
116
|
|
117
117
|
```liquid
|
118
|
-
{%
|
118
|
+
{% # theme-check-disable %}
|
119
119
|
{% assign x = 1 %}
|
120
|
-
{%
|
120
|
+
{% # theme-check-enable %}
|
121
121
|
```
|
122
122
|
|
123
123
|
Disable a specific check by including it in the comment:
|
124
124
|
|
125
125
|
```liquid
|
126
|
-
{%
|
126
|
+
{% # theme-check-disable UnusedAssign %}
|
127
127
|
{% assign x = 1 %}
|
128
|
-
{%
|
128
|
+
{% # theme-check-enable UnusedAssign %}
|
129
129
|
```
|
130
130
|
|
131
131
|
Disable multiple checks by including them as a comma-separated list:
|
132
132
|
|
133
133
|
```liquid
|
134
|
-
{%
|
134
|
+
{% # theme-check-disable UnusedAssign,SpaceInsideBraces %}
|
135
135
|
{%assign x = 1%}
|
136
|
-
{%
|
136
|
+
{% # theme-check-enable UnusedAssign,SpaceInsideBraces %}
|
137
137
|
```
|
138
138
|
|
139
139
|
Disable checks for the _entire document_ by placing the comment on the first line:
|
140
140
|
|
141
141
|
```liquid
|
142
|
-
{%
|
143
|
-
|
142
|
+
{% # theme-check-disable SpaceInsideBraces %}
|
144
143
|
{%assign x = 1%}
|
145
144
|
```
|
146
145
|
|
data/config/default.yml
CHANGED
@@ -101,6 +101,7 @@ UndefinedObject:
|
|
101
101
|
enabled: true
|
102
102
|
ignore: []
|
103
103
|
exclude_snippets: true
|
104
|
+
config_type: :default
|
104
105
|
|
105
106
|
RequiredDirectories:
|
106
107
|
enabled: true
|
@@ -130,6 +131,10 @@ ParserBlockingScriptTag:
|
|
130
131
|
enabled: true
|
131
132
|
ignore: []
|
132
133
|
|
134
|
+
AssetPreload:
|
135
|
+
enabled: true
|
136
|
+
ignore: []
|
137
|
+
|
133
138
|
AssetSizeJavaScript:
|
134
139
|
enabled: false
|
135
140
|
threshold_in_bytes: 10_000
|
@@ -1,4 +1,20 @@
|
|
1
1
|
---
|
2
|
+
# Here's an example workflow that's going to get ya the list of filters available
|
3
|
+
# ```bash
|
4
|
+
# spin up storefront-renderer
|
5
|
+
# spin ssh
|
6
|
+
# cd storefront-renderer
|
7
|
+
# bundle exec rake console
|
8
|
+
# ```
|
9
|
+
# ```ruby
|
10
|
+
# Pathname(ENV["HOME"]).join('filters.yml').write(YAML.dump(Liquid::StrainerFactory.global_filter_names))
|
11
|
+
# ```
|
12
|
+
# ```bash
|
13
|
+
# exit
|
14
|
+
# scp $(spin show -o fqdn):/filters.yml .
|
15
|
+
# ```
|
16
|
+
# The list of filters is now in a file named filters.yml in your $(pwd).
|
17
|
+
# Note that it'll probably need a bit of massaging before including here...
|
2
18
|
Liquid::StandardFilters:
|
3
19
|
- times
|
4
20
|
- h
|
@@ -19,7 +35,9 @@ Liquid::StandardFilters:
|
|
19
35
|
- remove
|
20
36
|
- sort_natural
|
21
37
|
- replace_first
|
38
|
+
- replace_last
|
22
39
|
- remove_first
|
40
|
+
- remove_last
|
23
41
|
- newline_to_br
|
24
42
|
- upcase
|
25
43
|
- downcase
|
data/dev.yml
CHANGED
data/docs/api/check.md
CHANGED
data/docs/checks/TEMPLATE.md.erb
CHANGED
@@ -34,7 +34,7 @@ The following example contains the default configuration for this check:
|
|
34
34
|
| Parameter | Description |
|
35
35
|
| --- | --- |
|
36
36
|
| enabled | Whether the check is enabled. |
|
37
|
-
| severity | The [severity](https://shopify.
|
37
|
+
| severity | The [severity](https://shopify.dev/themes/tools/theme-check/configuration#check-severity) of the check. |
|
38
38
|
| other_option | A description of the option. |
|
39
39
|
|
40
40
|
## Disabling this check
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Prevent Manual Preloading of Assets (`AssetPreload`)
|
2
|
+
|
3
|
+
_Version 1.11.0+_
|
4
|
+
|
5
|
+
Preloading can be a useful way of making sure that critical assets are downloaded by the browser as soon as possible for better rendering performance.
|
6
|
+
|
7
|
+
Liquid provides multiple filters to [preload key resources][preload_key_resources] so they can be converted into `Link` headers automatically. This enables them to be discovered even faster, especially when combined with Early Hints that Shopify supports.
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
The following examples contain code snippets that either fail or pass this check.
|
12
|
+
|
13
|
+
### ✗ Fail
|
14
|
+
|
15
|
+
```liquid
|
16
|
+
<link href="{{ 'script.js' | asset_url }}" rel="preload" as="script">
|
17
|
+
<link href="{{ 'style.css' | asset_url }}" rel="preload" as="style">
|
18
|
+
<link href="{{ 'image.png' | asset_url }}" rel="preload" as="image">
|
19
|
+
```
|
20
|
+
|
21
|
+
### ✓ Pass
|
22
|
+
|
23
|
+
```liquid
|
24
|
+
{{ 'script.js' | asset_url | preload_tag: as: 'script' }}
|
25
|
+
{{ 'style.css' | asset_url | stylesheet_tag: preload: true }}
|
26
|
+
{{
|
27
|
+
product.featured_image
|
28
|
+
| image_url: width: 600
|
29
|
+
| image_tag: preload: true
|
30
|
+
}}
|
31
|
+
```
|
32
|
+
|
33
|
+
## Options
|
34
|
+
|
35
|
+
The following example contains the default configuration for this check:
|
36
|
+
|
37
|
+
```yaml
|
38
|
+
AssetPreload:
|
39
|
+
enabled: true
|
40
|
+
severity: suggestion
|
41
|
+
```
|
42
|
+
|
43
|
+
| Parameter | Description |
|
44
|
+
| --- | --- |
|
45
|
+
| enabled | Whether the check is enabled. |
|
46
|
+
| severity | The [severity](https://shopify.dev/themes/tools/theme-check/configuration#check-severity) of the check. |
|
47
|
+
|
48
|
+
## Disabling this check
|
49
|
+
|
50
|
+
It's safe to disable this rule. You may want to do it when trying to preload assets from external domain and it is not possible
|
51
|
+
to move them to Shopify because they change frequently or are dynamically generated.
|
52
|
+
|
53
|
+
## Resources
|
54
|
+
|
55
|
+
- [Rule source][codesource]
|
56
|
+
- [Documentation source][docsource]
|
57
|
+
|
58
|
+
[codesource]: /lib/theme_check/checks/asset_preload.rb
|
59
|
+
[docsource]: /docs/checks/asset_preload.md
|
60
|
+
[preload_key_resources]: https://shopify.dev/themes/best-practices/performance#use-resource-hints-to-preload-key-resources
|
@@ -57,9 +57,9 @@ This includes theme and remote scripts.
|
|
57
57
|
When you can't do anything about it, it is preferable to disable this rule using the comment syntax:
|
58
58
|
|
59
59
|
```
|
60
|
-
{%
|
60
|
+
{% # theme-check-disable AssetSizeJavaScript %}
|
61
61
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js" defer></script>
|
62
|
-
{%
|
62
|
+
{% # theme-check-enable AssetSizeJavaScript %}
|
63
63
|
```
|
64
64
|
|
65
65
|
This makes disabling the rule an explicit affair and shows that the code is smelly.
|
@@ -12,7 +12,7 @@ This check aims at eliminating missing `theme-check-enable` comments.
|
|
12
12
|
<!doctype html>
|
13
13
|
<html>
|
14
14
|
<head>
|
15
|
-
{%
|
15
|
+
{% # theme-check-disable ParserBlockingJavaScript %}
|
16
16
|
<script src="https://cdnjs.com/jquery.min.js"></script>
|
17
17
|
</head>
|
18
18
|
<body>
|
@@ -27,9 +27,9 @@ This check aims at eliminating missing `theme-check-enable` comments.
|
|
27
27
|
<!doctype html>
|
28
28
|
<html>
|
29
29
|
<head>
|
30
|
-
{%
|
30
|
+
{% # theme-check-disable ParserBlockingJavaScript %}
|
31
31
|
<script src="https://cdnjs.com/jquery.min.js"></script>
|
32
|
-
{%
|
32
|
+
{% # theme-check-enable ParserBlockingJavaScript %}
|
33
33
|
</head>
|
34
34
|
<body>
|
35
35
|
<!-- ... -->
|
@@ -9,32 +9,32 @@ This check is aimed at eliminating excessive nesting of snippets.
|
|
9
9
|
:-1: Examples of **incorrect** code for this check:
|
10
10
|
|
11
11
|
```liquid
|
12
|
-
{%
|
12
|
+
{% # templates/index.liquid %}
|
13
13
|
{% render 'one' %}
|
14
14
|
|
15
|
-
{%
|
15
|
+
{% # snippets/one.liquid %}
|
16
16
|
{% render 'two' %}
|
17
17
|
|
18
|
-
{%
|
18
|
+
{% # snippets/two.liquid %}
|
19
19
|
{% render 'three' %}
|
20
20
|
|
21
|
-
{%
|
21
|
+
{% # snippets/three.liquid %}
|
22
22
|
{% render 'four' %}
|
23
23
|
|
24
|
-
{%
|
24
|
+
{% # snippets/four.liquid %}
|
25
25
|
ok
|
26
26
|
```
|
27
27
|
|
28
28
|
:+1: Examples of **correct** code for this check:
|
29
29
|
|
30
30
|
```liquid
|
31
|
-
{%
|
31
|
+
{% # templates/index.liquid %}
|
32
32
|
{% render 'one' %}
|
33
33
|
|
34
|
-
{%
|
34
|
+
{% # snippets/one.liquid %}
|
35
35
|
{% render 'two' %}
|
36
36
|
|
37
|
-
{%
|
37
|
+
{% # snippets/two.liquid %}
|
38
38
|
ok
|
39
39
|
```
|
40
40
|
|
@@ -59,7 +59,7 @@ SchemaJsonFormat:
|
|
59
59
|
| Parameter | Description |
|
60
60
|
| --- | --- |
|
61
61
|
| enabled | Whether the check is enabled. |
|
62
|
-
| severity | The [severity](https://shopify.
|
62
|
+
| severity | The [severity](https://shopify.dev/themes/tools/theme-check/configuration#check-severity) of the check. |
|
63
63
|
| start_level | The indentation level. If you prefer an indented schema, set this to 1. |
|
64
64
|
| indent | The character(s) used for indentation levels. |
|
65
65
|
|
@@ -9,7 +9,7 @@ This check is aimed at eliminating the use of translations that do not exist.
|
|
9
9
|
:-1: Examples of **incorrect** code for this check:
|
10
10
|
|
11
11
|
```liquid
|
12
|
-
{%
|
12
|
+
{% # locales/en.default.json %}
|
13
13
|
{
|
14
14
|
"greetings": "Hello, world!",
|
15
15
|
"general": {
|
@@ -17,14 +17,14 @@ This check is aimed at eliminating the use of translations that do not exist.
|
|
17
17
|
}
|
18
18
|
}
|
19
19
|
|
20
|
-
{%
|
20
|
+
{% # templates/index.liquid %}
|
21
21
|
{{ "notfound" | t }}
|
22
22
|
```
|
23
23
|
|
24
24
|
:+1: Examples of **correct** code for this check:
|
25
25
|
|
26
26
|
```liquid
|
27
|
-
{%
|
27
|
+
{% # locales/en.default.json %}
|
28
28
|
{
|
29
29
|
"greetings": "Hello, world!",
|
30
30
|
"general": {
|
@@ -32,7 +32,7 @@ This check is aimed at eliminating the use of translations that do not exist.
|
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
|
-
{%
|
35
|
+
{% # templates/index.liquid %}
|
36
36
|
{{ "greetings" | t }}
|
37
37
|
{{ "general.close" | t }}
|
38
38
|
```
|
@@ -18,7 +18,7 @@ This check is aimed at eliminating invalid HTML in translations.
|
|
18
18
|
:+1: Examples of **correct** code for this check:
|
19
19
|
|
20
20
|
```liquid
|
21
|
-
{%
|
21
|
+
{% # locales/en.default.json %}
|
22
22
|
{
|
23
23
|
"hello_html": "<h1>Hello, world</h1>",
|
24
24
|
"image_html": "<img src='spongebob.png'>",
|
data/lib/theme_check/analyzer.rb
CHANGED
@@ -41,6 +41,7 @@ module ThemeCheck
|
|
41
41
|
json_file_count + liquid_file_count
|
42
42
|
end
|
43
43
|
|
44
|
+
# Returns all offenses for all files in theme
|
44
45
|
def analyze_theme
|
45
46
|
reset
|
46
47
|
|
@@ -60,9 +61,23 @@ module ThemeCheck
|
|
60
61
|
@json_checks.call(:on_file, json_file)
|
61
62
|
end
|
62
63
|
|
63
|
-
finish
|
64
|
+
finish(false)
|
65
|
+
|
66
|
+
offenses
|
64
67
|
end
|
65
68
|
|
69
|
+
# When only_single_file is false:
|
70
|
+
# Runs single file checks for each file in `files`
|
71
|
+
# Runs whole theme checks
|
72
|
+
# Returns single file checks offenses for file in `files` + whole theme checks
|
73
|
+
# When only_single_file is true:
|
74
|
+
# Runs single file checks for each file in `files`
|
75
|
+
# Does not run whole theme checks
|
76
|
+
# Returns single file checks offenses for file in `files`
|
77
|
+
# When files is empty and only_single_file is false:
|
78
|
+
# Only returns whole theme checks
|
79
|
+
# When files is empty and only_single_file is true:
|
80
|
+
# Returns empty array
|
66
81
|
def analyze_files(files, only_single_file: false)
|
67
82
|
reset
|
68
83
|
|
@@ -103,6 +118,8 @@ module ThemeCheck
|
|
103
118
|
end
|
104
119
|
|
105
120
|
finish(only_single_file)
|
121
|
+
|
122
|
+
offenses
|
106
123
|
end
|
107
124
|
|
108
125
|
def uncorrectable_offenses
|
@@ -158,8 +175,6 @@ module ThemeCheck
|
|
158
175
|
@disabled_checks.remove_disabled_offenses(@liquid_checks)
|
159
176
|
@disabled_checks.remove_disabled_offenses(@json_checks)
|
160
177
|
@disabled_checks.remove_disabled_offenses(@html_checks)
|
161
|
-
|
162
|
-
offenses
|
163
178
|
end
|
164
179
|
end
|
165
180
|
end
|
data/lib/theme_check/check.rb
CHANGED
@@ -6,7 +6,8 @@ module ThemeCheck
|
|
6
6
|
include JsonHelpers
|
7
7
|
|
8
8
|
attr_accessor :theme
|
9
|
-
attr_accessor :options
|
9
|
+
attr_accessor :options
|
10
|
+
attr_writer :ignored_patterns
|
10
11
|
attr_writer :offenses
|
11
12
|
|
12
13
|
# The order matters.
|
@@ -130,6 +131,10 @@ module ThemeCheck
|
|
130
131
|
defined?(@ignored) && @ignored
|
131
132
|
end
|
132
133
|
|
134
|
+
def ignored_patterns
|
135
|
+
@ignored_patterns ||= []
|
136
|
+
end
|
137
|
+
|
133
138
|
def can_disable?
|
134
139
|
self.class.can_disable
|
135
140
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ThemeCheck
|
3
|
+
class AssetPreload < HtmlCheck
|
4
|
+
severity :suggestion
|
5
|
+
categories :html, :performance
|
6
|
+
doc docs_url(__FILE__)
|
7
|
+
|
8
|
+
def on_link(node)
|
9
|
+
return if node.attributes["rel"]&.downcase != "preload"
|
10
|
+
case node.attributes["as"]&.downcase
|
11
|
+
when "style"
|
12
|
+
add_offense("For better performance, prefer using the preload argument of the stylesheet_tag filter", node: node)
|
13
|
+
when "image"
|
14
|
+
add_offense("For better performance, prefer using the preload argument of the image_tag filter", node: node)
|
15
|
+
else
|
16
|
+
add_offense("For better performance, prefer using the preload_tag filter", node: node)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module ThemeCheck
|
3
4
|
class DeprecatedFilter < LiquidCheck
|
4
5
|
doc docs_url(__FILE__)
|
@@ -8,6 +9,19 @@ module ThemeCheck
|
|
8
9
|
# The image_url filter does not accept width or height values
|
9
10
|
# greater than this numbr.
|
10
11
|
MAX_SIZE = 5760
|
12
|
+
SIZE_REGEX = /^\d*x\d*$/
|
13
|
+
NAMED_SIZES = {
|
14
|
+
"pico" => 16,
|
15
|
+
"icon" => 32,
|
16
|
+
"thumb" => 50,
|
17
|
+
"small" => 100,
|
18
|
+
"compact" => 160,
|
19
|
+
"medium" => 240,
|
20
|
+
"large" => 480,
|
21
|
+
"grande" => 600,
|
22
|
+
"original" => 1024,
|
23
|
+
"master" => nil,
|
24
|
+
}
|
11
25
|
|
12
26
|
def on_variable(node)
|
13
27
|
used_filters = node.filters.map { |name, *_rest| name }
|
@@ -40,19 +54,29 @@ module ThemeCheck
|
|
40
54
|
|
41
55
|
# Can't correct those.
|
42
56
|
return add_default_offense(node, 'img_url', ['image_url']) unless
|
43
|
-
|
44
|
-
|
45
|
-
|
57
|
+
(size_spec.nil? || size_spec.is_a?(String)) &&
|
58
|
+
(scale.nil? || scale.is_a?(Numeric))
|
59
|
+
|
60
|
+
return add_default_offense(node, 'img_url', ['image_url']) if
|
61
|
+
size_spec.is_a?(String) &&
|
62
|
+
size_spec !~ SIZE_REGEX &&
|
63
|
+
!NAMED_SIZES.key?(size_spec)
|
46
64
|
|
47
65
|
node_source = node.markup
|
66
|
+
|
48
67
|
node_start_index = node.start_index
|
49
68
|
match = node_source.match(/img_url[^|]*/)
|
50
69
|
img_url_character_range =
|
51
70
|
(node_start_index + match.begin(0))...(node_start_index + match.end(0))
|
52
71
|
|
53
72
|
scale = (scale || 1).to_i
|
54
|
-
width, height =
|
55
|
-
|
73
|
+
width, height = if size_spec.nil?
|
74
|
+
[100, 100]
|
75
|
+
elsif NAMED_SIZES.key?(size_spec)
|
76
|
+
[NAMED_SIZES[size_spec], NAMED_SIZES[size_spec]]
|
77
|
+
else
|
78
|
+
size_spec.split('x')
|
79
|
+
end.map { |v| v.to_i * scale }
|
56
80
|
|
57
81
|
image_url_filter_params = [
|
58
82
|
width && width > 0 ? "width: #{[width, MAX_SIZE].min}" : nil,
|
@@ -16,6 +16,10 @@ module ThemeCheck
|
|
16
16
|
@disabled_checks.update(node)
|
17
17
|
end
|
18
18
|
|
19
|
+
def on_inline_comment(node)
|
20
|
+
@disabled_checks.update(node)
|
21
|
+
end
|
22
|
+
|
19
23
|
def after_document(node)
|
20
24
|
checks_missing_end_index = @disabled_checks.checks_missing_end_index
|
21
25
|
return if checks_missing_end_index.empty?
|
@@ -33,7 +33,11 @@ module ThemeCheck
|
|
33
33
|
if REQUIRED_LIQUID_TEMPLATE_FILES.include?(file)
|
34
34
|
corrector.create_file(@theme.storage, "#{file}.liquid", "")
|
35
35
|
else
|
36
|
-
corrector.create_file(@theme.storage, "#{file}.json",
|
36
|
+
corrector.create_file(@theme.storage, "#{file}.json", JSON.pretty_generate({
|
37
|
+
name: "TODO",
|
38
|
+
sections: {},
|
39
|
+
order: [],
|
40
|
+
}))
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|