theme-check 1.1.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/theme-check.yml +5 -9
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +50 -0
  5. data/CONTRIBUTING.md +1 -1
  6. data/RELEASING.md +34 -2
  7. data/bin/theme-check +29 -0
  8. data/bin/theme-check-language-server +29 -0
  9. data/config/default.yml +15 -1
  10. data/config/theme_app_extension.yml +15 -0
  11. data/data/shopify_liquid/objects.yml +1 -0
  12. data/docs/checks/app_block_valid_tags.md +40 -0
  13. data/docs/checks/asset_size_app_block_css.md +1 -1
  14. data/docs/checks/deprecate_lazysizes.md +0 -3
  15. data/docs/checks/deprecated_global_app_block_type.md +65 -0
  16. data/docs/checks/missing_template.md +25 -0
  17. data/docs/checks/pagination_size.md +44 -0
  18. data/docs/checks/template_length.md +1 -1
  19. data/docs/checks/undefined_object.md +5 -0
  20. data/lib/theme_check/analyzer.rb +1 -0
  21. data/lib/theme_check/check.rb +3 -3
  22. data/lib/theme_check/checks/app_block_valid_tags.rb +36 -0
  23. data/lib/theme_check/checks/asset_size_css.rb +3 -3
  24. data/lib/theme_check/checks/asset_size_javascript.rb +2 -2
  25. data/lib/theme_check/checks/convert_include_to_render.rb +3 -1
  26. data/lib/theme_check/checks/default_locale.rb +3 -1
  27. data/lib/theme_check/checks/deprecate_bgsizes.rb +1 -1
  28. data/lib/theme_check/checks/deprecate_lazysizes.rb +7 -4
  29. data/lib/theme_check/checks/deprecated_global_app_block_type.rb +57 -0
  30. data/lib/theme_check/checks/img_lazy_loading.rb +1 -1
  31. data/lib/theme_check/checks/img_width_and_height.rb +3 -3
  32. data/lib/theme_check/checks/missing_template.rb +21 -5
  33. data/lib/theme_check/checks/pagination_size.rb +64 -0
  34. data/lib/theme_check/checks/parser_blocking_javascript.rb +1 -1
  35. data/lib/theme_check/checks/remote_asset.rb +3 -3
  36. data/lib/theme_check/checks/space_inside_braces.rb +27 -7
  37. data/lib/theme_check/checks/template_length.rb +1 -1
  38. data/lib/theme_check/checks/undefined_object.rb +1 -1
  39. data/lib/theme_check/checks/valid_html_translation.rb +1 -1
  40. data/lib/theme_check/checks.rb +11 -1
  41. data/lib/theme_check/cli.rb +18 -2
  42. data/lib/theme_check/corrector.rb +9 -0
  43. data/lib/theme_check/file_system_storage.rb +12 -0
  44. data/lib/theme_check/html_check.rb +0 -1
  45. data/lib/theme_check/html_node.rb +37 -16
  46. data/lib/theme_check/html_visitor.rb +17 -3
  47. data/lib/theme_check/json_check.rb +2 -2
  48. data/lib/theme_check/json_file.rb +11 -0
  49. data/lib/theme_check/json_printer.rb +27 -0
  50. data/lib/theme_check/language_server/constants.rb +18 -11
  51. data/lib/theme_check/language_server/document_link_engine.rb +3 -67
  52. data/lib/theme_check/language_server/document_link_provider.rb +71 -0
  53. data/lib/theme_check/language_server/document_link_providers/asset_document_link_provider.rb +11 -0
  54. data/lib/theme_check/language_server/document_link_providers/include_document_link_provider.rb +11 -0
  55. data/lib/theme_check/language_server/document_link_providers/render_document_link_provider.rb +11 -0
  56. data/lib/theme_check/language_server/document_link_providers/section_document_link_provider.rb +11 -0
  57. data/lib/theme_check/language_server/handler.rb +17 -9
  58. data/lib/theme_check/language_server/server.rb +9 -0
  59. data/lib/theme_check/language_server/uri_helper.rb +37 -0
  60. data/lib/theme_check/language_server.rb +6 -0
  61. data/lib/theme_check/node.rb +6 -4
  62. data/lib/theme_check/offense.rb +56 -3
  63. data/lib/theme_check/parsing_helpers.rb +4 -3
  64. data/lib/theme_check/position.rb +98 -14
  65. data/lib/theme_check/regex_helpers.rb +5 -2
  66. data/lib/theme_check/theme.rb +3 -0
  67. data/lib/theme_check/version.rb +1 -1
  68. data/lib/theme_check.rb +1 -0
  69. data/theme-check.gemspec +1 -1
  70. metadata +20 -6
  71. data/bin/liquid-server +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc4aaf3260408a9b52d9afaa59662308f173a5d5dcd0f3663cbcc68da1d7f39
4
- data.tar.gz: 50cd7e0d42fda99ad3816a846c25868c38b92ea521e0be759c515548dd82f70b
3
+ metadata.gz: 9bfe8af624c0fe355dedcf6036609fc1366196011af2207b8365c0bb3389f3f5
4
+ data.tar.gz: 526353e93c6d8bc3bb902b24d81084c581cecdbd0bd98e29d9c1fd95ff00aff3
5
5
  SHA512:
6
- metadata.gz: 7ffad3310e441edd678143de233584a09167ffff1e09b96109cef417d360d797821dc9ef3491af4564608cd3b35aa59be41ebea6bb76030e1544d53bc9db8d02
7
- data.tar.gz: 30b6d8f3b58b95c833a78bc30ceea6cfcfa35d563e3d184b6aee51817965be87b352c2dbad5ff67a74f2a64479fe1945c11db738c1bfb6e64f610ae15b862cb3
6
+ metadata.gz: 49b583b1bbfa5fb7a59370ec6d09e6b1099ecf3ffa22a6fc55cf099fe26ab682637bf3c943c54786b0a36b80b20501491bb9623255af3323901d33f7cdbb8897
7
+ data.tar.gz: 02ed21413f0d437a77a8859cd7a4df76d296e4bf51f88c4470c8b9f74c89fefe32431cbb2658159fecc48bc79bdf4762f1db00bf21f2ff78fa81c239b29d765e
@@ -1,23 +1,19 @@
1
1
  name: ThemeCheck
2
2
 
3
- on:
4
- push:
5
- branches: [ master ]
6
- pull_request:
7
- branches: [ master ]
3
+ on: [push]
8
4
 
9
5
  jobs:
10
6
  test:
11
- runs-on: macos-latest
7
+ runs-on: ${{ matrix.platform }}
12
8
 
13
9
  strategy:
14
10
  matrix:
11
+ platform: [ubuntu-latest, windows-latest]
15
12
  version:
16
13
  - 3.0.0
17
- - 2.7.1
18
14
  - 2.6.6
19
15
 
20
- name: Ruby ${{ matrix.version }}
16
+ name: Ruby ${{ matrix.platform }} ${{ matrix.version }}
21
17
 
22
18
  steps:
23
19
  - uses: actions/checkout@v2
@@ -36,4 +32,4 @@ jobs:
36
32
  run: bundle exec rake
37
33
  - name: Test runtime
38
34
  # Testing that runtime can execute, not testing the results themselves
39
- run: bundle exec theme-check ./test/theme | grep -q "files inspected"
35
+ run: bundle exec theme-check ./test/theme | grep -q "files inspected"
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ Gemfile.lock
12
12
 
13
13
  .rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml
14
14
  packaging/builds
15
+ .vscode
data/CHANGELOG.md CHANGED
@@ -1,4 +1,54 @@
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
+
15
+ v1.4.0 / 2021-08-30
16
+ ==================
17
+
18
+ * Add new object drop: `predictive_search`
19
+ * Bump `TemplateLength` `max_length` default
20
+ * Fix `RemoteAsset` incorrectly firing on structured data elements [#393](https://github.com/Shopify/theme-check/issues/393)
21
+ * Fix document links not working on open
22
+ * Fix `asset_url` document links
23
+ * Use better heuristics for `DeprecateLazysizes`
24
+ * Add support for `section` document links
25
+ * Add support for `include` document links
26
+ * Automatically creates the default translation file (`locales/en.default.json`) if it doesn't already exist.
27
+
28
+ v1.3.0 / 2021-08-26
29
+ ==================
30
+
31
+ * Add `--output json` option for the CLI ([#392](https://github.com/shopify/theme-check/issues/392))
32
+ * Add PaginationSize check ([#359](https://github.com/shopify/theme-check/issues/359))
33
+ * Add ConvertIncludeToRender auto corrector ([#341](https://github.com/shopify/theme-check/issues/341))
34
+ * Add MissingTemplate auto corrector ([#388](https://github.com/shopify/theme-check/issues/388))
35
+ * Add `MissingTemplate` `ignore_missing` option ([#394](https://github.com/shopify/theme-check/issues/394))
36
+ * Fix Windows duplicate .bat file problem ([#400](https://github.com/shopify/theme-check/issues/400))
37
+ * Fix substring highlighting inside nodes ([#386](https://github.com/shopify/theme-check/issues/386))
38
+ * Add check for forbidden tags in theme app extension blocks ([#383](https://github.com/shopify/theme-check/issues/383))
39
+ * Improve HTML parsing of liquid attributes ([#381](https://github.com/shopify/theme-check/issues/381))
40
+ * Handle escaped file URIs in language server ([#360](https://github.com/shopify/theme-check/issues/360)) ([#382](https://github.com/shopify/theme-check/issues/382))
41
+ * Change asset size errors into suggestions ([#378](https://github.com/shopify/theme-check/issues/378))
42
+ * Switch to nokogiri 1.12, since it includes html5 support directly now ([#391](https://github.com/shopify/theme-check/issues/391))
43
+
44
+ v1.2.0 / 2021-07-15
45
+ ==================
46
+
47
+ * Add Windows Support ([#364](https://github.com/shopify/theme-check/issues/364))
48
+ * Ignore empty `{{}}` in SpaceInsideBraces ([#350](https://github.com/shopify/theme-check/issues/350))
49
+ * Switch to main branch
50
+ * Minor documentation fixes
51
+
2
52
  v1.1.0 / 2021-07-06
3
53
  ==================
4
54
 
data/CONTRIBUTING.md CHANGED
@@ -31,7 +31,7 @@ bundle exec rake
31
31
  ## Checking a theme
32
32
 
33
33
  ```
34
- bundle exec theme-check /path/to/your/theme
34
+ bin/theme-check /path/to/your/theme
35
35
  ```
36
36
 
37
37
  ## Creating a new "Check"
data/RELEASING.md CHANGED
@@ -13,7 +13,14 @@
13
13
 
14
14
  4. Commit your changes and make a PR.
15
15
 
16
- 5. Merge your PR to master.
16
+ ```bash
17
+ git checkout -b "bump/theme-check-$VERSION"
18
+ git add docs/checks CHANGELOG.md lib/theme_check/version.rb
19
+ git commit -m "Bump theme-check version to $VERSION"
20
+ hub compare "main:bump/theme-check-$VERSION"
21
+ ```
22
+
23
+ 5. Merge your PR to main.
17
24
 
18
25
  6. On [Shipit](https://shipit.shopify.io/shopify/theme-check/rubygems), deploy your commit.
19
26
 
@@ -46,5 +53,30 @@
46
53
 
47
54
  ```bash
48
55
  # shortcut if you have `hub` installed
49
- hub compare "master:bump/theme-check-$VERSION"
56
+ hub compare "main:bump/theme-check-$VERSION"
57
+ ```
58
+
59
+ ## Shopify CLI Release Process
60
+
61
+ 1. Release `theme-check` on RubyGems by following the steps in the previous section.
62
+
63
+ 2. Update the `theme-check` version in [`shopify-cli`](https://github.com/shopify/shopify-cli)'s `Gemfile.lock` and `shopify-cli.gemspec` files.
64
+
65
+ Such as in [this PR.](https://github.com/Shopify/shopify-cli/pull/1357/files)
66
+
67
+ 3. Create a branch + a commit on the [`shopify-cli`](https://github.com/Shopify/shopify-cli) repository.
68
+
69
+ ```bash
70
+ VERSION=X.X.X
71
+ git checkout -b "bump/theme-check-$VERSION"
72
+ git add Gemfile.lock
73
+ git add shopify-cli.gemspec
74
+ git commit -m "Bump theme-check version to $VERSION"
75
+ ```
76
+
77
+ 4. Create a pull-request for those changes on the [`shopify-cli`](https://github.com/Shopify/shopify-cli) repository.
78
+
79
+ ```bash
80
+ # shortcut if you have `hub` installed
81
+ hub compare "main:bump/theme-check-$VERSION"
50
82
  ```
data/bin/theme-check ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'theme-check' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("theme-check", "theme-check")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'theme-check-language-server' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("theme-check", "theme-check-language-server")
data/config/default.yml CHANGED
@@ -23,6 +23,7 @@ LiquidTag:
23
23
  MissingTemplate:
24
24
  enabled: true
25
25
  ignore: []
26
+ ignore_missing: []
26
27
 
27
28
  NestedSnippet:
28
29
  enabled: true
@@ -44,7 +45,7 @@ SyntaxError:
44
45
  TemplateLength:
45
46
  enabled: true
46
47
  ignore: []
47
- max_length: 500
48
+ max_length: 600
48
49
  # Exclude content of {% schema %} in line count
49
50
  exclude_schema: true
50
51
  # Exclude content of {% stylesheet %} in line count
@@ -177,3 +178,16 @@ AssetSizeAppBlockCSS:
177
178
  enabled: false
178
179
  ignore: []
179
180
  threshold_in_bytes: 100_000
181
+
182
+ AppBlockValidTags:
183
+ enabled: false
184
+ ignore: []
185
+
186
+ PaginationSize:
187
+ enabled: true
188
+ ignore: []
189
+ min_size: 1
190
+ max_size: 50
191
+
192
+ DeprecatedGlobalAppBlockType:
193
+ enabled: true
@@ -23,6 +23,7 @@ LiquidTag:
23
23
  MissingTemplate:
24
24
  enabled: true
25
25
  ignore: []
26
+ ignore_missing: []
26
27
 
27
28
  NestedSnippet:
28
29
  enabled: true
@@ -110,11 +111,13 @@ ParserBlockingScriptTag:
110
111
 
111
112
  AssetSizeJavaScript:
112
113
  enabled: true
114
+ severity: suggestion
113
115
  ignore: []
114
116
  threshold_in_bytes: 10_000
115
117
 
116
118
  AssetSizeCSS:
117
119
  enabled: true
120
+ severity: suggestion
118
121
  ignore: []
119
122
  threshold_in_bytes: 100_000
120
123
 
@@ -144,10 +147,22 @@ HtmlParsingError:
144
147
 
145
148
  AssetSizeAppBlockJavaScript:
146
149
  enabled: true
150
+ severity: suggestion
147
151
  ignore: []
148
152
  threshold_in_bytes: 10_000
149
153
 
150
154
  AssetSizeAppBlockCSS:
151
155
  enabled: true
156
+ severity: suggestion
152
157
  ignore: []
153
158
  threshold_in_bytes: 100_000
159
+
160
+ AppBlockValidTags:
161
+ enabled: true
162
+ ignore: []
163
+
164
+ PaginationSize:
165
+ enabled: true
166
+ ignore: []
167
+ min_size: 1
168
+ max_size: 50
@@ -54,6 +54,7 @@
54
54
  - part
55
55
  - policy
56
56
  - powered_by_link
57
+ - predictive_search
57
58
  - product
58
59
  - product_option
59
60
  - product_variant
@@ -0,0 +1,40 @@
1
+ # Reject Forbidden Tags from Theme App Extension Blocks (`AppBlockValidTags`)
2
+
3
+ This rule exists to prevent theme app extension blocks from containing forbidden tags in their liquid code.
4
+
5
+ ## Check Details
6
+
7
+ This rule verifies none of the below tags are used in theme app extension blocks.
8
+
9
+ - `{% javascript %}`
10
+ - `{% stylesheet %}`
11
+ - `{% include 'foo' %}`
12
+ - `{% layout 'foo' %}`
13
+ - `{% section 'foo' %}`
14
+
15
+ :-1: **Incorrect** code for this check occurs with the use of any of the above tags in the liquid code of theme app extension blocks.
16
+
17
+ ## Check Options
18
+
19
+ The default configuration for theme app extensions is the following:
20
+
21
+ ```yaml
22
+ AppBlockValidTags:
23
+ enabled: true
24
+ ```
25
+
26
+ ## When Not To Use It
27
+
28
+ This rule should not be disabled locally.
29
+
30
+ ## Version
31
+
32
+ This check has been introduced in 1.3.0
33
+
34
+ ## Resources
35
+
36
+ - [Rule Source][codesource]
37
+ - [Documentation Source][docsource]
38
+
39
+ [codesource]: /lib/theme_check/checks/app_block_valid_tags.rb
40
+ [docsource]: /docs/checks/app_block_valid_tags.md
@@ -23,7 +23,7 @@ The default configuration is the following:
23
23
 
24
24
  ```yaml
25
25
  AssetSizeAppBlockCSS:
26
- enabled: false
26
+ enabled: true
27
27
  threshold_in_bytes: 100_000
28
28
  ```
29
29
 
@@ -10,9 +10,6 @@ This check is aimed at discouraging the use of the lazysizes JavaScript library
10
10
 
11
11
  ```liquid
12
12
 
13
- <!-- Reports use of "lazyload" class -->
14
- <img src="a.jpg" class="lazyload">
15
-
16
13
  <!-- Reports use of "data-srcset" and "data-sizes" attribute. Reports data-sizes="auto" -->
17
14
  <img
18
15
  alt="House by the lake"
@@ -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