theme-check 0.8.0 → 0.9.1

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/theme-check.yml +3 -0
  3. data/CHANGELOG.md +44 -0
  4. data/CONTRIBUTING.md +2 -1
  5. data/README.md +4 -1
  6. data/RELEASING.md +5 -3
  7. data/config/default.yml +42 -1
  8. data/data/shopify_liquid/tags.yml +3 -0
  9. data/data/shopify_translation_keys.yml +1 -0
  10. data/docs/checks/asset_url_filters.md +56 -0
  11. data/docs/checks/content_for_header_modification.md +42 -0
  12. data/docs/checks/nested_snippet.md +1 -1
  13. data/docs/checks/parser_blocking_script_tag.md +53 -0
  14. data/docs/checks/space_inside_braces.md +28 -0
  15. data/exe/theme-check-language-server +1 -2
  16. data/lib/theme_check.rb +13 -1
  17. data/lib/theme_check/analyzer.rb +79 -13
  18. data/lib/theme_check/bug.rb +20 -0
  19. data/lib/theme_check/check.rb +36 -7
  20. data/lib/theme_check/checks.rb +47 -8
  21. data/lib/theme_check/checks/asset_url_filters.rb +46 -0
  22. data/lib/theme_check/checks/content_for_header_modification.rb +41 -0
  23. data/lib/theme_check/checks/img_width_and_height.rb +18 -49
  24. data/lib/theme_check/checks/missing_enable_comment.rb +4 -4
  25. data/lib/theme_check/checks/missing_template.rb +1 -0
  26. data/lib/theme_check/checks/nested_snippet.rb +1 -1
  27. data/lib/theme_check/checks/parser_blocking_javascript.rb +6 -38
  28. data/lib/theme_check/checks/parser_blocking_script_tag.rb +20 -0
  29. data/lib/theme_check/checks/remote_asset.rb +21 -79
  30. data/lib/theme_check/checks/space_inside_braces.rb +8 -2
  31. data/lib/theme_check/checks/template_length.rb +3 -0
  32. data/lib/theme_check/checks/valid_html_translation.rb +1 -0
  33. data/lib/theme_check/config.rb +2 -0
  34. data/lib/theme_check/disabled_check.rb +41 -0
  35. data/lib/theme_check/disabled_checks.rb +33 -29
  36. data/lib/theme_check/exceptions.rb +32 -0
  37. data/lib/theme_check/html_check.rb +7 -0
  38. data/lib/theme_check/html_node.rb +56 -0
  39. data/lib/theme_check/html_visitor.rb +38 -0
  40. data/lib/theme_check/json_file.rb +13 -1
  41. data/lib/theme_check/language_server.rb +2 -1
  42. data/lib/theme_check/language_server/completion_engine.rb +1 -1
  43. data/lib/theme_check/language_server/completion_providers/filter_completion_provider.rb +1 -0
  44. data/lib/theme_check/language_server/completion_providers/object_completion_provider.rb +10 -8
  45. data/lib/theme_check/language_server/constants.rb +5 -1
  46. data/lib/theme_check/language_server/diagnostics_tracker.rb +64 -0
  47. data/lib/theme_check/language_server/document_link_engine.rb +2 -2
  48. data/lib/theme_check/language_server/handler.rb +63 -50
  49. data/lib/theme_check/language_server/server.rb +1 -1
  50. data/lib/theme_check/language_server/variable_lookup_finder.rb +295 -0
  51. data/lib/theme_check/liquid_check.rb +1 -4
  52. data/lib/theme_check/node.rb +12 -0
  53. data/lib/theme_check/offense.rb +30 -46
  54. data/lib/theme_check/position.rb +77 -0
  55. data/lib/theme_check/position_helper.rb +37 -0
  56. data/lib/theme_check/remote_asset_file.rb +3 -0
  57. data/lib/theme_check/shopify_liquid/tag.rb +13 -0
  58. data/lib/theme_check/template.rb +8 -0
  59. data/lib/theme_check/theme.rb +7 -2
  60. data/lib/theme_check/version.rb +1 -1
  61. data/lib/theme_check/visitor.rb +4 -14
  62. metadata +19 -4
  63. data/lib/theme_check/language_server/position_helper.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 299afef3e63667dca21495d3a3e6246d378b4be98c6b26a7a5f46405e6db80b8
4
- data.tar.gz: b4d57dd51b0bd8960fcd42314fea731c1ae0aaac1ca29bbd2c591b3a6a9f4781
3
+ metadata.gz: a114e025e51ad2a09395b4ae0dca33e9417942a76ed781fdd639e7d7d1b35928
4
+ data.tar.gz: ff3c7f9b43f5ccae262cd22c8547d308a71e214cdd7f924208c25122624a48dc
5
5
  SHA512:
6
- metadata.gz: ea83f67457a564676ca6e32f7b6f601f54c2d6c259cc1a8af705d673640bb9a3e11881f54ca9cc571faf75cb36af93b51c5f03c96547d2cb24eb19ff69d59795
7
- data.tar.gz: 2694a73abcb292ebcc6d1f142a9255f9b5126d4748c64ece82c0081acb65d12c194acbd6232f24b50d0ddf982d076f49b342ef833883a09ab9a287712b631af5
6
+ metadata.gz: 3e4ead0f1d63cc68dfbaff6dd5462f08b9008c04dd87fae9499875cf967e501c68327adec0ac3c1f253bbdbf1343d14ddeb63fe58b4c9f4cb24f494315898d70
7
+ data.tar.gz: 62baa63bcf203d2bd0a7894787011f23d363cb6192920ac67c2ce0dfbe89f382c461a3d5a989c23234e5e1a9db7bfd9d10c4801bca121c1993a082b58887705d
@@ -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,48 @@
1
1
 
2
+ v0.9.1 / 2021-06-04
3
+ ==================
4
+
5
+ * Convert `RemoteAsset` into an `HtmlCheck`
6
+ * Move Liquid logic from `RemoteAsset` to a new `AssetUrlFilters` check
7
+
8
+ v0.9.0 / 2021-05-28
9
+ ==================
10
+
11
+ * Introduce HtmlCheck, and convert ParserBlockingJavaScript & ImgWidthAndHeight to it
12
+ * Move `script-tag` validation from ParserBlockingJavaScript to ParserBlockingScriptTag
13
+ * Add ability to ignore individual checks using file patterns
14
+ * Introduce single file and whole theme checks to optimize LSP diagnostics
15
+ * Fix TemplateLength counter not being reseted on each document
16
+ * Add missing category to ValidHTMLTranslation
17
+ * Set Ruby default encodings to UTF-8 to fix encoding issues
18
+ * Add ContentForHeaderModification check to prevent relying on the content of ``content_for_header`
19
+ * Fix `Content-Length` in LSP responses
20
+ * Fix disabling checks that emit offences in `on_end`
21
+ * Fix completion bug in `filter_completion_provider`
22
+
23
+ v0.8.3 / 2021-05-17
24
+ ==================
25
+
26
+ * Making sure VERSION is set before referencing it
27
+
28
+ v0.8.2 / 2021-05-14
29
+ ===================
30
+
31
+ * Bump NestedSnippet max_nesting_level to 3
32
+ * Add a message to help debug errors, and timeout checks after 5 sec
33
+ * Object Completions Everywhere!
34
+ * Include operators to space inside braces check
35
+
36
+ 0.8.1 / 2021-04-22
37
+ ==================
38
+
39
+ * Add consistent spacing around the pipe character (`|`) in variable expressions to the `SpaceInsideBrace` check ([#73](https://github.com/shopify/theme-check/issues/73))
40
+ * Add ReCaptcha system translation ([#265](https://github.com/shopify/theme-check/issues/265))
41
+ * Fix document links in `{% liquid %}` tags ([#263](https://github.com/shopify/theme-check/issues/263))
42
+ * Fix theme-check-disable for checks based on regular expressions ([#242](https://github.com/shopify/theme-check/issues/242))
43
+ * Fix VS Code crash on new window ([#264](https://github.com/shopify/theme-check/issues/264))
44
+ * Rescue errors thrown by remote_asset_file
45
+
2
46
  0.8.0 / 2021-04-13
3
47
  ==================
4
48
 
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 based check.
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. Commit your changes and make a PR.
12
+ 3. Run [`git changelog`](https://github.com/tj/git-extras) to update `CHANGELOG.md`.
13
13
 
14
- 4. Merge your PR to master.
14
+ 4. Commit your changes and make a PR.
15
15
 
16
- 5. On [Shipit](https://shipit.shopify.io/shopify/theme-check/rubygems), deploy your commit.
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,133 @@ 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
- max_nesting_level: 2
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: []
@@ -8,6 +8,8 @@
8
8
  - cycle
9
9
  - decrement
10
10
  - echo
11
+ - else
12
+ - elsif
11
13
  - for
12
14
  - form
13
15
  - if
@@ -25,3 +27,4 @@
25
27
  - stylesheet
26
28
  - tablerow
27
29
  - unless
30
+ - when
@@ -848,3 +848,4 @@
848
848
  - shopify.store_availability.pick_up_time.two_to_four_hours
849
849
  - shopify.store_availability.pick_up_time.immediately
850
850
  - shopify.store_availability.pick_up_time.next_day
851
+ - shopify.online_store.spam_detection.disclaimer_html
@@ -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
@@ -45,7 +45,7 @@ The default configuration for this check is the following:
45
45
  ```yaml
46
46
  NestedSnippet:
47
47
  enabled: true
48
- max_nesting_level: 2
48
+ max_nesting_level: 3
49
49
  ```
50
50
 
51
51
  ### `max_nesting_level`
@@ -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
@@ -17,6 +17,14 @@ This check is aimed at eliminating ugly Liquid:
17
17
  <!-- After commas and semicolons -->
18
18
  {% form 'type', object, key:value %}
19
19
  {% endform %}
20
+
21
+ <!-- Arround filter pipelines -->
22
+ {{ url | asset_url | img_tag }}
23
+ {% assign my_upcase_string = "Hello world"| upcase %}
24
+
25
+ <!-- Arround symbol operators -->
26
+ {%- if target == product and product.price_varies -%}
27
+ {%- if product.featured_media.width >=165 -%}
20
28
  ```
21
29
 
22
30
  :+1: Examples of **correct** code for this check:
@@ -33,6 +41,10 @@ This check is aimed at eliminating ugly Liquid:
33
41
  media_size: section.settings.product_recommendations_image_ratio,
34
42
  center_align_text: section.settings.center_align_text
35
43
  %}
44
+ {{ url | asset_url | img_tag }}
45
+ {% assign my_upcase_string = "Hello world" | upcase %}
46
+ {%- if target == product and product.price_varies -%}
47
+ {%- if product.featured_media.width >= 165 -%}
36
48
  ```
37
49
 
38
50
  ## Check Options
@@ -44,6 +56,22 @@ SpaceInsideBraces:
44
56
  enabled: true
45
57
  ```
46
58
 
59
+ ## Auto-correction
60
+
61
+ This check can automatically trim or add spaces around `{{ ... }}`.
62
+
63
+ ```liquid
64
+ {{ x}}
65
+ {{x}}
66
+ {{ x }}
67
+ ```
68
+
69
+ Can all be auto-corrected with the `--auto-correct` option to:
70
+
71
+ ```liquid
72
+ {{ x }}
73
+ ```
74
+
47
75
  ## When Not To Use It
48
76
 
49
77
  If you don't care about the look of your code.