theme-check 1.0.0 → 1.4.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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/theme-check.yml +2 -6
  3. data/CHANGELOG.md +50 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/README.md +39 -0
  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 +28 -1
  10. data/config/nothing.yml +11 -0
  11. data/config/theme_app_extension.yml +168 -0
  12. data/data/shopify_liquid/objects.yml +1 -0
  13. data/docs/checks/app_block_valid_tags.md +40 -0
  14. data/docs/checks/asset_size_app_block_css.md +52 -0
  15. data/docs/checks/asset_size_app_block_javascript.md +57 -0
  16. data/docs/checks/deprecate_lazysizes.md +0 -3
  17. data/docs/checks/missing_template.md +25 -0
  18. data/docs/checks/pagination_size.md +44 -0
  19. data/docs/checks/template_length.md +1 -1
  20. data/docs/checks/undefined_object.md +5 -0
  21. data/lib/theme_check/analyzer.rb +26 -21
  22. data/lib/theme_check/asset_file.rb +3 -15
  23. data/lib/theme_check/bug.rb +3 -1
  24. data/lib/theme_check/check.rb +26 -4
  25. data/lib/theme_check/checks/app_block_valid_tags.rb +36 -0
  26. data/lib/theme_check/checks/asset_size_app_block_css.rb +44 -0
  27. data/lib/theme_check/checks/asset_size_app_block_javascript.rb +44 -0
  28. data/lib/theme_check/checks/asset_size_css.rb +3 -3
  29. data/lib/theme_check/checks/asset_size_javascript.rb +2 -2
  30. data/lib/theme_check/checks/convert_include_to_render.rb +3 -1
  31. data/lib/theme_check/checks/default_locale.rb +3 -1
  32. data/lib/theme_check/checks/deprecate_bgsizes.rb +1 -1
  33. data/lib/theme_check/checks/deprecate_lazysizes.rb +7 -4
  34. data/lib/theme_check/checks/img_lazy_loading.rb +1 -1
  35. data/lib/theme_check/checks/img_width_and_height.rb +3 -3
  36. data/lib/theme_check/checks/missing_template.rb +21 -5
  37. data/lib/theme_check/checks/pagination_size.rb +65 -0
  38. data/lib/theme_check/checks/parser_blocking_javascript.rb +1 -1
  39. data/lib/theme_check/checks/remote_asset.rb +3 -3
  40. data/lib/theme_check/checks/space_inside_braces.rb +27 -7
  41. data/lib/theme_check/checks/template_length.rb +1 -1
  42. data/lib/theme_check/checks/undefined_object.rb +1 -1
  43. data/lib/theme_check/checks/valid_html_translation.rb +1 -1
  44. data/lib/theme_check/checks.rb +11 -1
  45. data/lib/theme_check/cli.rb +52 -15
  46. data/lib/theme_check/config.rb +56 -10
  47. data/lib/theme_check/corrector.rb +9 -0
  48. data/lib/theme_check/exceptions.rb +29 -27
  49. data/lib/theme_check/file_system_storage.rb +12 -0
  50. data/lib/theme_check/html_check.rb +0 -1
  51. data/lib/theme_check/html_node.rb +37 -16
  52. data/lib/theme_check/html_visitor.rb +17 -3
  53. data/lib/theme_check/json_check.rb +2 -2
  54. data/lib/theme_check/json_file.rb +11 -27
  55. data/lib/theme_check/json_printer.rb +26 -0
  56. data/lib/theme_check/language_server/constants.rb +21 -6
  57. data/lib/theme_check/language_server/document_link_engine.rb +3 -31
  58. data/lib/theme_check/language_server/document_link_provider.rb +70 -0
  59. data/lib/theme_check/language_server/document_link_providers/asset_document_link_provider.rb +11 -0
  60. data/lib/theme_check/language_server/document_link_providers/include_document_link_provider.rb +11 -0
  61. data/lib/theme_check/language_server/document_link_providers/render_document_link_provider.rb +11 -0
  62. data/lib/theme_check/language_server/document_link_providers/section_document_link_provider.rb +11 -0
  63. data/lib/theme_check/language_server/handler.rb +7 -4
  64. data/lib/theme_check/language_server/server.rb +13 -2
  65. data/lib/theme_check/language_server.rb +5 -0
  66. data/lib/theme_check/node.rb +6 -4
  67. data/lib/theme_check/offense.rb +56 -3
  68. data/lib/theme_check/parsing_helpers.rb +4 -3
  69. data/lib/theme_check/position.rb +98 -14
  70. data/lib/theme_check/regex_helpers.rb +5 -2
  71. data/lib/theme_check/tags.rb +26 -9
  72. data/lib/theme_check/template.rb +3 -32
  73. data/lib/theme_check/theme.rb +3 -0
  74. data/lib/theme_check/theme_file.rb +40 -0
  75. data/lib/theme_check/version.rb +1 -1
  76. data/lib/theme_check.rb +16 -0
  77. data/theme-check.gemspec +1 -1
  78. metadata +24 -6
  79. data/bin/liquid-server +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94b918e53777cfb70c65dacd9d9bfbdb6f4463597c8f9c81969e1baef89df7a1
4
- data.tar.gz: 7e45af9a3dfeab1eafdff5533df68a9e0d67007d94661a2c974c0c2fece61095
3
+ metadata.gz: e154c11ed7f84b968edac05c97afb2611e816933d790347cdbdca63071d46e88
4
+ data.tar.gz: dd8fc72c420412ab3adfad64f3d11197f562904bd0171289debe8e440ca34c86
5
5
  SHA512:
6
- metadata.gz: ea1b75ca11a66aefe5eef421f577d53716cb180799863185d36fad21a9033b5cf52579df3e593e41867513da410adc7d16de723f35b3a5435e50098b7af2a348
7
- data.tar.gz: ceab091f6bf7317d899cb5459601b7dfb5294e6e4be962a421b33bad33c74fd730001dea90687f81f754d57e5cdedc5b39d0efb5d95d6c016ed965f7e4e86a9f
6
+ metadata.gz: 0315a3eb75f5cda96fe2be02d7533e07aa364fc7b3e08bdb2682edf50f30d13bc2c03099d015c73db2e1c6e7d06c90707068d596db044176ddcdaea4bfe3a65c
7
+ data.tar.gz: a7050df945829d05a0440464d0ac309d3cc55d9fdd9909259b95f2405beae746e799aad8beeb564508b0a543568dcd718edb9638c1307bb345051784818ea165
@@ -1,10 +1,6 @@
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:
@@ -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/CHANGELOG.md CHANGED
@@ -1,4 +1,54 @@
1
1
 
2
+ v1.4.0 / 2021-08-30
3
+ ==================
4
+
5
+ * Add new object drop: `predictive_search`
6
+ * Bump `TemplateLength` `max_length` default
7
+ * Fix `RemoteAsset` incorrectly firing on structured data elements [#393](https://github.com/Shopify/theme-check/issues/393)
8
+ * Fix document links not working on open
9
+ * Fix `asset_url` document links
10
+ * Use better heuristics for `DeprecateLazysizes`
11
+ * Add support for `section` document links
12
+ * Add support for `include` document links
13
+ * Automatically creates the default translation file (`locales/en.default.json`) if it doesn't already exist.
14
+
15
+ v1.3.0 / 2021-08-26
16
+ ==================
17
+
18
+ * Add `--output json` option for the CLI ([#392](https://github.com/shopify/theme-check/issues/392))
19
+ * Add PaginationSize check ([#359](https://github.com/shopify/theme-check/issues/359))
20
+ * Add ConvertIncludeToRender auto corrector ([#341](https://github.com/shopify/theme-check/issues/341))
21
+ * Add MissingTemplate auto corrector ([#388](https://github.com/shopify/theme-check/issues/388))
22
+ * Add `MissingTemplate` `ignore_missing` option ([#394](https://github.com/shopify/theme-check/issues/394))
23
+ * Fix Windows duplicate .bat file problem ([#400](https://github.com/shopify/theme-check/issues/400))
24
+ * Fix substring highlighting inside nodes ([#386](https://github.com/shopify/theme-check/issues/386))
25
+ * Add check for forbidden tags in theme app extension blocks ([#383](https://github.com/shopify/theme-check/issues/383))
26
+ * Improve HTML parsing of liquid attributes ([#381](https://github.com/shopify/theme-check/issues/381))
27
+ * 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))
28
+ * Change asset size errors into suggestions ([#378](https://github.com/shopify/theme-check/issues/378))
29
+ * Switch to nokogiri 1.12, since it includes html5 support directly now ([#391](https://github.com/shopify/theme-check/issues/391))
30
+
31
+ v1.2.0 / 2021-07-15
32
+ ==================
33
+
34
+ * Add Windows Support ([#364](https://github.com/shopify/theme-check/issues/364))
35
+ * Ignore empty `{{}}` in SpaceInsideBraces ([#350](https://github.com/shopify/theme-check/issues/350))
36
+ * Switch to main branch
37
+ * Minor documentation fixes
38
+
39
+ v1.1.0 / 2021-07-06
40
+ ==================
41
+
42
+ * Add `--fail-level` CLI flag to configure exit code
43
+ * Refactor all theme file classes to inherit from `ThemeFile`
44
+ * Fix `undefined method liquid?` error when scanning from LSP
45
+ * Adding asset document links
46
+ * Allow initializing theme app extension configuration files
47
+ * Allow disabling registering mock Liquid tags w/ `ThemeCheck::Tags.register_tags = false`
48
+ * Support Theme App Extensions
49
+ * Add checks for theme app extension block JS/CSS
50
+ * Disable Liquid::C when parsing Liquid templates
51
+
2
52
  v1.0.0 / 2021-06-28
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/README.md CHANGED
@@ -100,6 +100,8 @@ TemplateLength:
100
100
  # Or ignore certain paths
101
101
  ignore:
102
102
  - snippets/icon-*
103
+ # Or change the severity (error|suggestion|style)
104
+ severity: suggestion
103
105
 
104
106
  # Enable a custom check
105
107
  MyCustomCheck
@@ -141,3 +143,40 @@ Disable checks for the _entire document_ by placing the comment on the first lin
141
143
 
142
144
  {%assign x = 1%}
143
145
  ```
146
+
147
+ ## Exit Code and `--fail-level`
148
+
149
+ Use the `--fail-level` (default: `error`) flag to configure the exit code of theme-check. Useful in CI scenarios.
150
+
151
+ Example:
152
+
153
+ ```
154
+ # Make CI fail on styles warnings, suggestions, and errors
155
+ theme-check --fail-level style path_to_theme
156
+
157
+ # Make CI fail on suggestions, and errors
158
+ theme-check --fail-level suggestion path_to_theme
159
+
160
+ # Make CI fail on errors
161
+ theme-check path_to_theme
162
+ ```
163
+
164
+ There are three fail levels:
165
+
166
+ - `error`
167
+ - `suggestion`
168
+ - `style`
169
+
170
+ Exit code meanings:
171
+
172
+ - 0: Success!
173
+ - 1: Your code doesn't pass the checks
174
+ - 2: There's a bug in theme-check
175
+
176
+ If you would like to change the severity of a check, you can do so with the `severity` attribute. Example:
177
+
178
+ ```yaml
179
+ DeprecateLazysizes:
180
+ enabled: true
181
+ severity: error
182
+ ```
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
@@ -1,7 +1,13 @@
1
1
  root: .
2
2
 
3
+ extends: :nothing
4
+
3
5
  require: []
4
6
 
7
+ include_categories: []
8
+
9
+ exclude_categories: []
10
+
5
11
  ignore:
6
12
  - node_modules/*
7
13
 
@@ -17,6 +23,7 @@ LiquidTag:
17
23
  MissingTemplate:
18
24
  enabled: true
19
25
  ignore: []
26
+ ignore_missing: []
20
27
 
21
28
  NestedSnippet:
22
29
  enabled: true
@@ -38,7 +45,7 @@ SyntaxError:
38
45
  TemplateLength:
39
46
  enabled: true
40
47
  ignore: []
41
- max_length: 500
48
+ max_length: 600
42
49
  # Exclude content of {% schema %} in line count
43
50
  exclude_schema: true
44
51
  # Exclude content of {% stylesheet %} in line count
@@ -161,3 +168,23 @@ ImgLazyLoading:
161
168
  HtmlParsingError:
162
169
  enabled: true
163
170
  ignore: []
171
+
172
+ AssetSizeAppBlockJavaScript:
173
+ enabled: false
174
+ ignore: []
175
+ threshold_in_bytes: 10_000
176
+
177
+ AssetSizeAppBlockCSS:
178
+ enabled: false
179
+ ignore: []
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
@@ -0,0 +1,11 @@
1
+ root: .
2
+
3
+ require: []
4
+
5
+ include_categories: []
6
+
7
+ exclude_categories: []
8
+
9
+ ignore:
10
+ - node_modules/*
11
+
@@ -0,0 +1,168 @@
1
+ root: .
2
+
3
+ extends: :nothing
4
+
5
+ require: []
6
+
7
+ include_categories: []
8
+
9
+ exclude_categories: []
10
+
11
+ ignore:
12
+ - node_modules/*
13
+
14
+ ConvertIncludeToRender:
15
+ enabled: true
16
+ ignore: []
17
+
18
+ LiquidTag:
19
+ enabled: true
20
+ ignore: []
21
+ min_consecutive_statements: 4
22
+
23
+ MissingTemplate:
24
+ enabled: true
25
+ ignore: []
26
+ ignore_missing: []
27
+
28
+ NestedSnippet:
29
+ enabled: true
30
+ ignore: []
31
+ max_nesting_level: 3
32
+
33
+ RequiredLayoutThemeObject:
34
+ enabled: true
35
+ ignore: []
36
+
37
+ SpaceInsideBraces:
38
+ enabled: true
39
+ ignore: []
40
+
41
+ SyntaxError:
42
+ enabled: true
43
+ ignore: []
44
+
45
+ TemplateLength:
46
+ enabled: true
47
+ ignore: []
48
+ max_length: 200
49
+ # Exclude content of {% schema %} in line count
50
+ exclude_schema: true
51
+
52
+ UnknownFilter:
53
+ enabled: true
54
+ ignore: []
55
+
56
+ UnusedAssign:
57
+ enabled: true
58
+ ignore: []
59
+
60
+ UnusedSnippet:
61
+ enabled: true
62
+ ignore: []
63
+
64
+ MatchingSchemaTranslations:
65
+ enabled: true
66
+ ignore: []
67
+
68
+ MatchingTranslations:
69
+ enabled: true
70
+ ignore: []
71
+
72
+ TranslationKeyExists:
73
+ enabled: true
74
+ ignore: []
75
+
76
+ ValidHTMLTranslation:
77
+ enabled: true
78
+ ignore: []
79
+
80
+ ValidJson:
81
+ enabled: true
82
+ ignore: []
83
+
84
+ ValidSchema:
85
+ enabled: true
86
+ ignore: []
87
+
88
+ UndefinedObject:
89
+ enabled: true
90
+ ignore: []
91
+ exclude_snippets: true
92
+
93
+ RequiredDirectories:
94
+ enabled: false
95
+ ignore: []
96
+
97
+ DeprecatedFilter:
98
+ enabled: true
99
+ ignore: []
100
+
101
+ MissingEnableComment:
102
+ enabled: true
103
+ ignore: []
104
+
105
+ ParserBlockingJavaScript:
106
+ enabled: true
107
+ ignore: []
108
+
109
+ ParserBlockingScriptTag:
110
+ enabled: true
111
+
112
+ AssetSizeJavaScript:
113
+ enabled: true
114
+ severity: suggestion
115
+ ignore: []
116
+ threshold_in_bytes: 10_000
117
+
118
+ AssetSizeCSS:
119
+ enabled: true
120
+ severity: suggestion
121
+ ignore: []
122
+ threshold_in_bytes: 100_000
123
+
124
+ ImgWidthAndHeight:
125
+ enabled: true
126
+ ignore: []
127
+
128
+ RemoteAsset:
129
+ enabled: true
130
+ ignore: []
131
+
132
+ AssetUrlFilters:
133
+ enabled: true
134
+ ignore: []
135
+
136
+ ContentForHeaderModification:
137
+ enabled: true
138
+ ignore: []
139
+
140
+ ImgLazyLoading:
141
+ enabled: true
142
+ ignore: []
143
+
144
+ HtmlParsingError:
145
+ enabled: true
146
+ ignore: []
147
+
148
+ AssetSizeAppBlockJavaScript:
149
+ enabled: true
150
+ severity: suggestion
151
+ ignore: []
152
+ threshold_in_bytes: 10_000
153
+
154
+ AssetSizeAppBlockCSS:
155
+ enabled: true
156
+ severity: suggestion
157
+ ignore: []
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