theme-check 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/CHANGELOG.md +10 -0
  4. data/CONTRIBUTING.md +5 -2
  5. data/README.md +9 -2
  6. data/RELEASING.md +1 -1
  7. data/config/default.yml +6 -0
  8. data/data/shopify_liquid/tags.yml +1 -0
  9. data/docs/checks/CHECK_DOCS_TEMPLATE.md +47 -0
  10. data/docs/checks/asset_size_javascript.md +79 -0
  11. data/docs/checks/convert_include_to_render.md +48 -0
  12. data/docs/checks/default_locale.md +46 -0
  13. data/docs/checks/deprecated_filter.md +46 -0
  14. data/docs/checks/liquid_tag.md +65 -0
  15. data/docs/checks/matching_schema_translations.md +93 -0
  16. data/docs/checks/matching_translations.md +72 -0
  17. data/docs/checks/missing_enable_comment.md +50 -0
  18. data/docs/checks/missing_required_template_files.md +26 -0
  19. data/docs/checks/missing_template.md +40 -0
  20. data/docs/checks/nested_snippet.md +69 -0
  21. data/docs/checks/parser_blocking_javascript.md +97 -0
  22. data/docs/checks/required_directories.md +25 -0
  23. data/docs/checks/required_layout_theme_object.md +28 -0
  24. data/docs/checks/space_inside_braces.md +63 -0
  25. data/docs/checks/syntax_error.md +49 -0
  26. data/docs/checks/template_length.md +50 -0
  27. data/docs/checks/translation_key_exists.md +63 -0
  28. data/docs/checks/undefined_object.md +53 -0
  29. data/docs/checks/unknown_filter.md +45 -0
  30. data/docs/checks/unused_assign.md +47 -0
  31. data/docs/checks/unused_snippet.md +32 -0
  32. data/docs/checks/valid_html_translation.md +53 -0
  33. data/docs/checks/valid_json.md +60 -0
  34. data/docs/checks/valid_schema.md +50 -0
  35. data/lib/theme_check.rb +3 -0
  36. data/lib/theme_check/asset_file.rb +34 -0
  37. data/lib/theme_check/check.rb +19 -9
  38. data/lib/theme_check/checks/asset_size_javascript.rb +74 -0
  39. data/lib/theme_check/checks/convert_include_to_render.rb +1 -1
  40. data/lib/theme_check/checks/default_locale.rb +1 -0
  41. data/lib/theme_check/checks/deprecated_filter.rb +1 -1
  42. data/lib/theme_check/checks/liquid_tag.rb +3 -3
  43. data/lib/theme_check/checks/matching_schema_translations.rb +1 -0
  44. data/lib/theme_check/checks/matching_translations.rb +1 -0
  45. data/lib/theme_check/checks/missing_enable_comment.rb +1 -0
  46. data/lib/theme_check/checks/missing_required_template_files.rb +1 -2
  47. data/lib/theme_check/checks/missing_template.rb +1 -0
  48. data/lib/theme_check/checks/nested_snippet.rb +1 -0
  49. data/lib/theme_check/checks/parser_blocking_javascript.rb +2 -1
  50. data/lib/theme_check/checks/required_directories.rb +1 -1
  51. data/lib/theme_check/checks/required_layout_theme_object.rb +1 -1
  52. data/lib/theme_check/checks/space_inside_braces.rb +1 -0
  53. data/lib/theme_check/checks/syntax_error.rb +1 -0
  54. data/lib/theme_check/checks/template_length.rb +1 -0
  55. data/lib/theme_check/checks/translation_key_exists.rb +1 -0
  56. data/lib/theme_check/checks/undefined_object.rb +10 -4
  57. data/lib/theme_check/checks/unknown_filter.rb +1 -0
  58. data/lib/theme_check/checks/unused_assign.rb +1 -0
  59. data/lib/theme_check/checks/unused_snippet.rb +1 -0
  60. data/lib/theme_check/checks/valid_html_translation.rb +1 -0
  61. data/lib/theme_check/checks/valid_json.rb +1 -0
  62. data/lib/theme_check/checks/valid_schema.rb +1 -0
  63. data/lib/theme_check/config.rb +2 -2
  64. data/lib/theme_check/language_server/completion_helper.rb +0 -10
  65. data/lib/theme_check/language_server/completion_provider.rb +1 -0
  66. data/lib/theme_check/language_server/handler.rb +11 -3
  67. data/lib/theme_check/language_server/server.rb +6 -1
  68. data/lib/theme_check/regex_helpers.rb +15 -0
  69. data/lib/theme_check/remote_asset_file.rb +44 -0
  70. data/lib/theme_check/theme.rb +7 -1
  71. data/lib/theme_check/version.rb +1 -1
  72. metadata +32 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5543690a150f2a864a5a9900feca80286ffe4c00d545885ee31dc02c9d389b71
4
- data.tar.gz: c1c518e2013a1106dc7ace3a14ef5158853e06929694503777a37c0fc695025a
3
+ metadata.gz: 7beb3a827afcd22a262b82b436ed03a7130a1237ab11351bf4e1b36769c62d1a
4
+ data.tar.gz: a92529eac6dcaa689b708ecfda3e53a6b132e61ae01f26ae3ebb0bf3ec03e962
5
5
  SHA512:
6
- metadata.gz: 405832fbd93d17f3412abb83181b8c76c0aee43e2405bc7329b7ace746c20887c32ab638bf49c99adf4598532fc92d5840a46dc24d2a20b89909849b8c2813a3
7
- data.tar.gz: 40316910f51d646017059d4256cba23dfcb9e20822a0987b65a04ab79c40c160c882d4bdf7e0cc4d646b08971ba04bb58999a7c5b93a4741233a8ce1c5ce4ad9
6
+ metadata.gz: dd4554837884b203c2bca10cdbd09e29d0f485d814c8aff72d8680d1d7f44e82e8bef74b192953aba8a61622434ff3f466a24109f6eb3bee83500585f462672f
7
+ data.tar.gz: 75ece7d25c463748ae1d810920b488e732e50602988f3dd40bccb25a649af4d9336d4a3dc12310dbb1b53e1492728f8900da1050759e43e826457991f0bf6a11
data/.rubocop.yml CHANGED
@@ -17,3 +17,9 @@ Layout/LineLength:
17
17
 
18
18
  Lint/MissingSuper:
19
19
  Enabled: false
20
+
21
+ Style/StringLiterals:
22
+ Enabled: false
23
+
24
+ Style/StringLiteralsInInterpolation:
25
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ 0.5.0 / 2021-03-12
3
+ ==================
4
+
5
+ * Add [AssetSizeJavaScript](/docs/checks/asset_size_javascript.md) check ([#194](https://github.com/Shopify/theme-check/pull/194))
6
+ * Add [documentation for all checks](/docs/checks)
7
+ * Make documentation for checks mandatory
8
+ * Add link to documentation from within the editor (via `codeDescription` in the Language Server) (![Demo](https://screenshot.click/10-29-cjx7r-4asor.mp4))
9
+ * Allow checks to have multiple categories
10
+ * Fix multiple occurrences of UndefinedObject not being reported ([#192](https://github.com/shopify/theme-check/issues/192))
11
+
2
12
  v0.4.0 / 2021-02-25
3
13
  ==================
4
14
 
data/CONTRIBUTING.md CHANGED
@@ -44,7 +44,6 @@ module ThemeCheck
44
44
  # NOTE: inherit from JsonCheck to implement a JSON based check.
45
45
  class MyCheckName < LiquidCheck
46
46
  severity :suggestion # :error or :style
47
- doc "https://..." # Optional link to doc
48
47
 
49
48
  def on_document(node)
50
49
  # Called with the root node of all templates
@@ -122,7 +121,7 @@ module ThemeCheck
122
121
  end
123
122
  ```
124
123
 
125
- Add the new check to `config/default.yml` to enable it.
124
+ Add the new check to `config/default.yml` to enable it. If the check is configurable, the `initialize` argument name and default values should also be duplicated inside `config/default.yml`.
126
125
 
127
126
  ```yaml
128
127
  MyCheckName:
@@ -131,4 +130,8 @@ MyCheckName:
131
130
 
132
131
  Add a corresponding test file under `test/checks`.
133
132
 
133
+ Add a documentation file in `docs/checks/#{name_of_check}.md` based off of the [check documentation template][doctemplate].
134
+
134
135
  When done, run the tests with `dev test`.
136
+
137
+ [doctemplate]: /docs/checks/CHECK_DOCS_TEMPLATE.md
data/README.md CHANGED
@@ -32,7 +32,14 @@ Theme Check currently checks for the following:
32
32
  ✅ Deprecated filters
33
33
  ✅ Missing `theme-check-enable` comment
34
34
 
35
- And many more to come! Suggestions welcome ([create an issue](https://github.com/Shopify/theme-check/issues)).
35
+ As well as checks that prevent easy to spot performance problems:
36
+
37
+ ✅ Use of [parser-blocking](/docs/checks/parser_blocking_javascript.md) JavaScript
38
+ ✅ [Too much JavaScript](/docs/checks/asset_size_javascript.md)
39
+
40
+ For detailed descriptions and configuration options, [take a look at the complete list.](/docs/checks/)
41
+
42
+ With more to come! Suggestions welcome ([create an issue](https://github.com/Shopify/theme-check/issues)).
36
43
 
37
44
  ## Requirements
38
45
 
@@ -87,7 +94,7 @@ TemplateLength:
87
94
  enabled: false
88
95
  # Or configure options
89
96
  max_length: 300
90
-
97
+
91
98
  # Enable a custom check
92
99
  MyCustomCheck
93
100
  enabled: true
data/RELEASING.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
4
 
5
- 2. Create a PR to update the version in `lib/theme_check/version.rb`
5
+ 2. Create a PR to update the version in `lib/theme_check/version.rb` and replace the `THEME_CHECK_VERSION` placeholder in the documentation for new rules.
6
6
 
7
7
  3. Merge your PR to master
8
8
 
data/config/default.yml CHANGED
@@ -10,12 +10,14 @@ ConvertIncludeToRender:
10
10
 
11
11
  LiquidTag:
12
12
  enabled: true
13
+ min_consecutive_statements: 4
13
14
 
14
15
  MissingTemplate:
15
16
  enabled: true
16
17
 
17
18
  NestedSnippet:
18
19
  enabled: true
20
+ max_nesting_level: 2
19
21
 
20
22
  RequiredLayoutThemeObject:
21
23
  enabled: true
@@ -80,3 +82,7 @@ MissingEnableComment:
80
82
 
81
83
  ParserBlockingJavaScript:
82
84
  enabled: true
85
+
86
+ AssetSizeJavaScript:
87
+ enabled: false
88
+ threshold_in_bytes: 10000
@@ -15,6 +15,7 @@
15
15
  - increment
16
16
  - javascript
17
17
  - layout
18
+ - liquid
18
19
  - paginate
19
20
  - raw
20
21
  - render
@@ -0,0 +1,47 @@
1
+ # Check Title (`CheckClassName`)
2
+
3
+ A brief paragraph explaining why the check exists.
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at eliminating ...
8
+
9
+ :-1: Examples of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+ ```
13
+
14
+ :+1: Examples of **correct** code for this check:
15
+
16
+ ```liquid
17
+ ```
18
+
19
+ ## Check Options
20
+
21
+ The default configuration for this check is the following:
22
+
23
+ ```yaml
24
+ CheckClassName:
25
+ enabled: true
26
+ some_option: 10
27
+ ```
28
+
29
+ ### `some_option`
30
+
31
+ The `some_option` option (Default: `10`) determines ...
32
+
33
+ ## When Not To Use It
34
+
35
+ If you don't want to ..., then it's safe to disable this rule.
36
+
37
+ ## Version
38
+
39
+ This check has been introduced in Theme Check X.X.X.
40
+
41
+ ## Resources
42
+
43
+ - [Rule Source][codesource]
44
+ - [Documentation Source][docsource]
45
+
46
+ [codesource]: /lib/theme_check/checks/check_class_name.rb
47
+ [docsource]: /docs/checks/check_class_name.md
@@ -0,0 +1,79 @@
1
+ # Prevent JavaScript Abuse on Server Rendered Themes (`AssetSizeJavaScript`)
2
+
3
+ For server rendered pages, it is an anti-pattern to execute large JavaScript bundles on every navigation.
4
+
5
+ This doesn't mean they don't have a reason to exist. For instance, chat widgets are mini applications embedded inside web pages. Designing such an app with server rendered updates would be absurd. However, if only 10% of the users interact with the chat widget, the other 90% should not have to execute the entire bundle on every page load.
6
+
7
+ The natural solution to this problem is to implement the chat widget using the [Import on Interaction Pattern][ioip].
8
+
9
+ ## Check Details
10
+
11
+ This rule disallows the use of theme JavaScript files and external scripts to have a compressed size greater than a configured `threshold_in_bytes`.
12
+
13
+ :-1: Examples of **incorrect** code for this check:
14
+ ```liquid
15
+ <!-- Here assets/chat-widget.js is more than 10KB gzipped. -->
16
+ <script src="{{ 'chat-widget.js' | asset_url }}" defer></script>
17
+
18
+ <!-- The use of jQuery is discouraged in themes -->
19
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js" defer></script>
20
+ ```
21
+
22
+ :+1: Example of **correct** code for this check:
23
+ ```liquid
24
+ <script>
25
+ const chatWidgetButton = document.getElementById('#chat-widget')
26
+
27
+ chatWidgetButton.addEventListener('click', e => {
28
+ e.preventDefault();
29
+ import("{{ 'chat-widget.js' | asset_url }}")
30
+ .then(module => module.default)
31
+ .then(ChatWidget => ChatWidget.init())
32
+ .catch(err => {
33
+ console.error(err);
34
+ });
35
+ });
36
+ </script>
37
+ ```
38
+
39
+ ## Check Options
40
+
41
+ The default configuration is the following.
42
+
43
+ ```yaml
44
+ AssetSizeJavaScript:
45
+ enabled: false
46
+ threshold_in_bytes: 10000
47
+ ```
48
+
49
+ ### `threshold_in_bytes`
50
+
51
+ The `threshold_in_bytes` option (default: `10000`) determines the maximum allowed compressed size in bytes that a single JavaScript file can take.
52
+
53
+ This includes theme and remote scripts.
54
+
55
+ ## When Not To Use It
56
+
57
+ When you can't do anything about it, it is preferable to disable this rule using the comment syntax:
58
+
59
+ ```
60
+ {% comment %}theme-check-disable AssetSizeJavaScript{% endcomment %}
61
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js" defer></script>
62
+ {% comment %}theme-check-enable AssetSizeJavaScript{% endcomment %}
63
+ ```
64
+
65
+ This makes disabling the rule an explicit affair and shows that the code is smelly.
66
+
67
+ ## Version
68
+
69
+ This check has been introduced in Theme Check 0.5.0.
70
+
71
+ ## Resources
72
+
73
+ - [The Import On Interaction Pattern][ioip]
74
+ - [Rule Source][codesource]
75
+ - [Documentation Source][docsource]
76
+
77
+ [ioip]: https://addyosmani.com/blog/import-on-interaction/
78
+ [codesource]: /lib/theme_check/checks/asset_size_javascript.rb
79
+ [docsource]: /docs/checks/asset_size_javascript.md
@@ -0,0 +1,48 @@
1
+ # Discourage the use of `include` (`ConvertIncludeToRender`)
2
+
3
+ The `include` tag is [deprecated][deprecated]. This tag exists to enforce the use of the `render` tag instead of `include`.
4
+
5
+ The `include` tag works similarly to the `render` tag, but it lets the code inside of the snippet to access and overwrite the variables within its parent template. The `include` tag has been deprecated because the way that it handles variables reduces performance and makes theme code harder to both read and maintain.
6
+
7
+ ## Check Details
8
+
9
+ This check is aimed at eliminating the use of `include` tags.
10
+
11
+ :-1: Examples of **incorrect** code for this check:
12
+
13
+ ```liquid
14
+ {% include 'snippet' %}
15
+ ```
16
+
17
+ :+1: Examples of **correct** code for this check:
18
+
19
+ ```liquid
20
+ {% render 'snippet' %}
21
+ ```
22
+
23
+ ## Check Options
24
+
25
+ The default configuration for this check is the following:
26
+
27
+ ```yaml
28
+ ConvertIncludeToRender:
29
+ enabled: true
30
+ ```
31
+
32
+ ## When Not To Use It
33
+
34
+ It is discouraged to disable this rule.
35
+
36
+ ## Version
37
+
38
+ This check has been introduced in Theme Check 0.1.0.
39
+
40
+ ## Resources
41
+
42
+ - [Deprecated Tags Reference][deprecated]
43
+ - [Rule Source][codesource]
44
+ - [Documentation Source][docsource]
45
+
46
+ [deprecated]: https://shopify.dev/docs/themes/liquid/reference/tags/deprecated-tags#include
47
+ [codesource]: /lib/theme_check/checks/convert_include_to_render.rb
48
+ [docsource]: /docs/checks/convert_include_to_render.md
@@ -0,0 +1,46 @@
1
+ # Ensure theme has a default locale (`DefaultLocale`)
2
+
3
+ This check makes sure the theme has a default translation file.
4
+
5
+ ## Check Details
6
+
7
+ This check makes sure a theme has a default locale.
8
+
9
+ :-1: Example of **incorrect** theme for this check:
10
+
11
+ ```
12
+ locales/
13
+ ├── en.json
14
+ ├── fr.json
15
+ └── zh-TW.json
16
+ ```
17
+
18
+ :+1: Example of **correct** theme for this check:
19
+
20
+ ```
21
+ locales/
22
+ ├── en.default.json # a default translation file is required
23
+ ├── fr.json
24
+ └── zh-TW.json
25
+ ```
26
+
27
+ ## Check Options
28
+
29
+ The default configuration for this check is the following:
30
+
31
+ ```yaml
32
+ DefaultLocale:
33
+ enabled: true
34
+ ```
35
+
36
+ ## Version
37
+
38
+ This check has been introduced in Theme Check 0.1.0.
39
+
40
+ ## Resources
41
+
42
+ - [Rule Source][codesource]
43
+ - [Documentation Source][docsource]
44
+
45
+ [codesource]: /lib/theme_check/checks/default_locale.rb
46
+ [docsource]: /docs/checks/default_locale.md
@@ -0,0 +1,46 @@
1
+ # Discourage use of deprecated filters (`DeprecatedFilter`)
2
+
3
+ This check discourages the use of [deprecated filters][deprecated].
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at eliminating deprecated filters.
8
+
9
+ :-1: Example of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+ .site-footer p {
13
+ color: {{ settings.color_name | hex_to_rgba: 0.5 }};
14
+ }
15
+ ```
16
+
17
+ :+1: Example of **correct** code for this check:
18
+
19
+ ```liquid
20
+ .site-footer p {
21
+ color: {{ settings.color_name | color_modify: 'alpha', 0.5 }};
22
+ }
23
+ ```
24
+
25
+ ## Check Options
26
+
27
+ The default configuration for this check is the following:
28
+
29
+ ```yaml
30
+ DeprecatedFilter:
31
+ enabled: true
32
+ ```
33
+
34
+ ## Version
35
+
36
+ This check has been introduced in Theme Check 0.2.0.
37
+
38
+ ## Resources
39
+
40
+ - [Deprecated Filters Reference][deprecated]
41
+ - [Rule Source][codesource]
42
+ - [Documentation Source][docsource]
43
+
44
+ [deprecated]: https://shopify.dev/docs/themes/liquid/reference/filters/deprecated-filters
45
+ [codesource]: /lib/theme_check/checks/deprecated_filter.rb
46
+ [docsource]: /docs/checks/deprecated_filter.md
@@ -0,0 +1,65 @@
1
+ # Encourage use of liquid tag for consecutive statements (LiquidTag)
2
+
3
+ Recommends using `{% liquid ... %}` if 4 or more consecutive liquid tags (`{% ... %}`) are found.
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at eliminating repetitive tag markers (`{%` and `%}`) in theme files.
8
+
9
+ :-1: Example of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+ {% if collection.image.size != 0 %}
13
+ {% assign collection_image = collection.image %}
14
+ {% elsif collection.products.first.size != 0 and collection.products.first.media != empty %}
15
+ {% assign collection_image = collection.products.first.featured_media.preview_image %}
16
+ {% else %}
17
+ {% assign collection_image = nil %}
18
+ {% endif %}
19
+ ```
20
+
21
+ :+1: Example of **correct** code for this check:
22
+
23
+ ```liquid
24
+ {%- liquid
25
+ if collection.image.size != 0
26
+ assign collection_image = collection.image
27
+ elsif collection.products.first.size != 0 and collection.products.first.media != empty
28
+ assign collection_image = collection.products.first.featured_media.preview_image
29
+ else
30
+ assign collection_image = nil
31
+ endif
32
+ -%}
33
+ ```
34
+
35
+ ## Check Options
36
+
37
+ The default configuration for this check is the following:
38
+
39
+ ```yaml
40
+ LiquidTag:
41
+ enabled: true
42
+ min_consecutive_statements: 4
43
+ ```
44
+
45
+ ### `min_consecutive_statements`
46
+
47
+ The `min_consecutive_statements` option (Default: `4`) determines the maximum (inclusive) number of consecutive statements before the check recommends a refactor.
48
+
49
+ ## When Not To Use It
50
+
51
+ It's safe to disable this rule.
52
+
53
+ ## Version
54
+
55
+ This check has been introduced in Theme Check 0.1.0.
56
+
57
+ ## Resources
58
+
59
+ - [`{% liquid %}` Tag Reference][liquid]
60
+ - [Rule Source][codesource]
61
+ - [Documentation Source][docsource]
62
+
63
+ [liquid]: https://shopify.dev/docs/themes/liquid/reference/tags/theme-tags#liquid
64
+ [codesource]: /lib/theme_check/checks/liquid_tag.rb
65
+ [docsource]: /docs/checks/liquid_tag.md