theme-check 1.2.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/theme-check.yml +3 -3
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +47 -0
  5. data/CONTRIBUTING.md +59 -1
  6. data/Gemfile +3 -0
  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/docs/flamegraph.svg +18488 -0
  21. data/lib/theme_check/analyzer.rb +1 -0
  22. data/lib/theme_check/check.rb +2 -2
  23. data/lib/theme_check/checks/app_block_valid_tags.rb +36 -0
  24. data/lib/theme_check/checks/asset_size_css.rb +3 -3
  25. data/lib/theme_check/checks/asset_size_javascript.rb +2 -2
  26. data/lib/theme_check/checks/convert_include_to_render.rb +3 -1
  27. data/lib/theme_check/checks/default_locale.rb +3 -1
  28. data/lib/theme_check/checks/deprecate_bgsizes.rb +1 -1
  29. data/lib/theme_check/checks/deprecate_lazysizes.rb +7 -4
  30. data/lib/theme_check/checks/deprecated_global_app_block_type.rb +57 -0
  31. data/lib/theme_check/checks/img_lazy_loading.rb +1 -1
  32. data/lib/theme_check/checks/img_width_and_height.rb +3 -3
  33. data/lib/theme_check/checks/missing_template.rb +21 -5
  34. data/lib/theme_check/checks/pagination_size.rb +84 -0
  35. data/lib/theme_check/checks/parser_blocking_javascript.rb +1 -1
  36. data/lib/theme_check/checks/remote_asset.rb +3 -3
  37. data/lib/theme_check/checks/space_inside_braces.rb +26 -6
  38. data/lib/theme_check/checks/template_length.rb +1 -1
  39. data/lib/theme_check/checks/undefined_object.rb +1 -1
  40. data/lib/theme_check/checks/valid_html_translation.rb +1 -1
  41. data/lib/theme_check/checks.rb +11 -1
  42. data/lib/theme_check/cli.rb +42 -3
  43. data/lib/theme_check/corrector.rb +9 -0
  44. data/lib/theme_check/file_system_storage.rb +12 -0
  45. data/lib/theme_check/html_check.rb +0 -1
  46. data/lib/theme_check/html_node.rb +37 -16
  47. data/lib/theme_check/html_visitor.rb +17 -3
  48. data/lib/theme_check/json_check.rb +2 -2
  49. data/lib/theme_check/json_file.rb +11 -0
  50. data/lib/theme_check/json_printer.rb +31 -0
  51. data/lib/theme_check/language_server/constants.rb +18 -11
  52. data/lib/theme_check/language_server/document_link_engine.rb +3 -67
  53. data/lib/theme_check/language_server/document_link_provider.rb +71 -0
  54. data/lib/theme_check/language_server/document_link_providers/asset_document_link_provider.rb +11 -0
  55. data/lib/theme_check/language_server/document_link_providers/include_document_link_provider.rb +11 -0
  56. data/lib/theme_check/language_server/document_link_providers/render_document_link_provider.rb +11 -0
  57. data/lib/theme_check/language_server/document_link_providers/section_document_link_provider.rb +11 -0
  58. data/lib/theme_check/language_server/handler.rb +17 -9
  59. data/lib/theme_check/language_server/server.rb +11 -13
  60. data/lib/theme_check/language_server/uri_helper.rb +37 -0
  61. data/lib/theme_check/language_server.rb +6 -0
  62. data/lib/theme_check/node.rb +6 -4
  63. data/lib/theme_check/offense.rb +56 -3
  64. data/lib/theme_check/parsing_helpers.rb +4 -3
  65. data/lib/theme_check/position.rb +98 -14
  66. data/lib/theme_check/printer.rb +9 -5
  67. data/lib/theme_check/regex_helpers.rb +5 -2
  68. data/lib/theme_check/theme.rb +3 -0
  69. data/lib/theme_check/version.rb +1 -1
  70. data/lib/theme_check.rb +1 -0
  71. data/theme-check.gemspec +1 -1
  72. metadata +21 -10
  73. data/bin/liquid-server +0 -4
  74. data/exe/theme-check-language-server.bat +0 -3
  75. data/exe/theme-check.bat +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28cb25e47867151bea85360a9f07667f46ea30ad90285f16cc74e85370ad39d9
4
- data.tar.gz: 2023811dad002a72f00e2c26562ff3e6b5f2f49c748d44968fd94d1f9e72300f
3
+ metadata.gz: 60f0635001a9f808d12b55e0328536911bde9ea36160bcf34a63f10114401d18
4
+ data.tar.gz: 78365fe98014904e058191934663b75d24701db8a2a2585edac2557192cec5d5
5
5
  SHA512:
6
- metadata.gz: f3a5339873aea7a325cbc3f3715e9166b1f7734226e3d9ac7b400f048629a514f3eec5d559c77eaf70febacda35416b8332d8d1a6ebefa1d9a34f29474a4e41d
7
- data.tar.gz: 19eec11d1eb86188fe170bce61f884072340d848e800b2bb2b344cddf3561d60594e4f066199b7f9157b54da81ce8afebc5e6db0f3dbfbc5fac208c95d2b5ed8
6
+ metadata.gz: 0520e083dac843ed6273ba17e0cb44ee0e9e2c412f85a81b176da8b0912a583ab262c0c25b0b580df9c53cabefca305dce468559efa6df786ff37b7583e7ecc4
7
+ data.tar.gz: 58b7483ad5935de781eddf850a73c88f04aadbae394416f901fa38e173b44b4af3717947fc72cc009c899866ce1d27cc3f6597d5de7dd7ea1ef6984393d71ff4
@@ -4,16 +4,16 @@ on: [push]
4
4
 
5
5
  jobs:
6
6
  test:
7
- runs-on: macos-latest
7
+ runs-on: ${{ matrix.platform }}
8
8
 
9
9
  strategy:
10
10
  matrix:
11
+ platform: [ubuntu-latest, windows-latest]
11
12
  version:
12
13
  - 3.0.0
13
- - 2.7.1
14
14
  - 2.6.6
15
15
 
16
- name: Ruby ${{ matrix.version }}
16
+ name: Ruby ${{ matrix.platform }} ${{ matrix.version }}
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v2
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,51 @@
1
1
 
2
+ v1.5.1 / 2021-09-08
3
+ ===================
4
+
5
+ * Fix PaginationSize issue ([#429](https://github.com/shopify/theme-check/issues/429), [#428](https://github.com/shopify/theme-check/issues/428))
6
+
7
+ v1.5.0 / 2021-09-07
8
+ ==================
9
+
10
+ ### Features
11
+
12
+ * Add [DeprecatedGlobalAppBlockType](docs/checks/deprecated_global_app_block_type.md) ([#402](https://github.com/shopify/theme-check/issues/402))
13
+
14
+ ### Fixes
15
+
16
+ * Add Windows CI
17
+ * Fix multiple Windows bugs ([#413](https://github.com/shopify/theme-check/issues/413), [#415](https://github.com/shopify/theme-check/issues/415))
18
+ * 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))
19
+
20
+ v1.4.0 / 2021-08-30
21
+ ==================
22
+
23
+ * Add new object drop: `predictive_search`
24
+ * Bump `TemplateLength` `max_length` default
25
+ * Fix `RemoteAsset` incorrectly firing on structured data elements [#393](https://github.com/Shopify/theme-check/issues/393)
26
+ * Fix document links not working on open
27
+ * Fix `asset_url` document links
28
+ * Use better heuristics for `DeprecateLazysizes`
29
+ * Add support for `section` document links
30
+ * Add support for `include` document links
31
+ * Automatically creates the default translation file (`locales/en.default.json`) if it doesn't already exist.
32
+
33
+ v1.3.0 / 2021-08-26
34
+ ==================
35
+
36
+ * Add `--output json` option for the CLI ([#392](https://github.com/shopify/theme-check/issues/392))
37
+ * Add PaginationSize check ([#359](https://github.com/shopify/theme-check/issues/359))
38
+ * Add ConvertIncludeToRender auto corrector ([#341](https://github.com/shopify/theme-check/issues/341))
39
+ * Add MissingTemplate auto corrector ([#388](https://github.com/shopify/theme-check/issues/388))
40
+ * Add `MissingTemplate` `ignore_missing` option ([#394](https://github.com/shopify/theme-check/issues/394))
41
+ * Fix Windows duplicate .bat file problem ([#400](https://github.com/shopify/theme-check/issues/400))
42
+ * Fix substring highlighting inside nodes ([#386](https://github.com/shopify/theme-check/issues/386))
43
+ * Add check for forbidden tags in theme app extension blocks ([#383](https://github.com/shopify/theme-check/issues/383))
44
+ * Improve HTML parsing of liquid attributes ([#381](https://github.com/shopify/theme-check/issues/381))
45
+ * 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))
46
+ * Change asset size errors into suggestions ([#378](https://github.com/shopify/theme-check/issues/378))
47
+ * Switch to nokogiri 1.12, since it includes html5 support directly now ([#391](https://github.com/shopify/theme-check/issues/391))
48
+
2
49
  v1.2.0 / 2021-07-15
3
50
  ==================
4
51
 
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"
@@ -65,3 +65,61 @@ MyNewCheckName:
65
65
  ignore: []
66
66
  muffin_mode: true
67
67
  ```
68
+
69
+ ## Debugging
70
+
71
+ A couple of things are turned on when the `THEME_CHECK_DEBUG` environment variable is set.
72
+
73
+ 1. The check timeout is turned off. This means you can add `binding.pry` in tests and properly debug with `bundle exec rake tests:in_memory`
74
+ 2. The `--profile` flag appears. You can now create Flamegraphs to inspect performance.
75
+
76
+ ```
77
+ export THEME_CHECK_DEBUG=true
78
+
79
+ # The following will behave slightly differently
80
+ bin/theme-check ../dawn
81
+ bundle exec rake tests:in_memory
82
+
83
+ # The following becomes available
84
+ bin/theme-check --profile ../dawn
85
+
86
+ # The LanguageServer will log the JSONRPC calls to STDERR
87
+ bin/theme-check-language-server
88
+ ```
89
+
90
+ ### Profiling
91
+
92
+ `ruby-prof` and `ruby-prof-flamegraph` are both included as development dependencies.
93
+
94
+ #### Flamegraph
95
+
96
+ With the `--profile` flag, you can run theme-check on a theme and the `ruby-prof-flamegraph` printer will output profiling information in a format [Flamegraph](/brendangregg/FlameGraph) understands.
97
+
98
+
99
+ **Setup:**
100
+
101
+ ```bash
102
+ # clone the FlameGraph repo somewhere
103
+ git clone https://github.com/brendangregg/FlameGraph.git
104
+
105
+ # the flamegraph.pl perl script is in that repo
106
+ alias flamegraph=/path/to/FlameGraph/flamegraph.pl
107
+ ```
108
+
109
+ **Profiling:**
110
+
111
+ ```
112
+ # run theme-check with --profile
113
+ # pass the output to flamegraph
114
+ # dump the output into an svg file
115
+ bin/theme-check --profile ../dawn \
116
+ | flamegraph --countname=ms --width=1750 \
117
+ > /tmp/fg.svg
118
+
119
+ # open the svg file in Chrome to look at the flamegraph
120
+ chrome /tmp/fg.svg
121
+ ```
122
+
123
+ What you'll see is an interactive version of the following image:
124
+
125
+ ![flamegraph](docs/flamegraph.svg)
data/Gemfile CHANGED
@@ -19,6 +19,9 @@ end
19
19
  group :development do
20
20
  gem 'guard'
21
21
  gem 'guard-minitest'
22
+ gem 'ruby-prof'
23
+ gem 'ruby-prof-flamegraph'
24
+ gem 'solargraph'
22
25
  end
23
26
 
24
27
  gem 'rubocop', '~> 1.12.0', require: false
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