platformos-check 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +2 -0
  3. data/.gitignore +22 -0
  4. data/.rubocop.yml +555 -0
  5. data/CHANGELOG.md +5 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/CONTRIBUTING.md +209 -0
  8. data/Gemfile +33 -0
  9. data/Guardfile +7 -0
  10. data/LICENSE.md +10 -0
  11. data/Makefile +18 -0
  12. data/README.md +189 -0
  13. data/RELEASING.md +35 -0
  14. data/Rakefile +83 -0
  15. data/TROUBLESHOOTING.md +35 -0
  16. data/bin/platformos-check +29 -0
  17. data/bin/platformos-check-language-server +29 -0
  18. data/config/default.yml +98 -0
  19. data/config/nothing.yml +11 -0
  20. data/data/platformos_liquid/built_in_liquid_objects.json +66 -0
  21. data/data/platformos_liquid/deprecated_filters.json +22 -0
  22. data/data/platformos_liquid/documentation/filters.json +6 -0
  23. data/data/platformos_liquid/documentation/latest.json +2 -0
  24. data/data/platformos_liquid/documentation/objects.json +6 -0
  25. data/data/platformos_liquid/documentation/tags.json +6 -0
  26. data/docker/check.Dockerfile +3 -0
  27. data/docker/lsp.Dockerfile +21 -0
  28. data/docs/api/check.md +15 -0
  29. data/docs/api/html_check.md +46 -0
  30. data/docs/api/liquid_check.md +115 -0
  31. data/docs/api/yaml_check.md +19 -0
  32. data/docs/checks/TEMPLATE.md.erb +52 -0
  33. data/docs/checks/convert_include_to_render.md +48 -0
  34. data/docs/checks/deprecated_filter.md +30 -0
  35. data/docs/checks/html_parsing_error.md +50 -0
  36. data/docs/checks/img_lazy_loading.md +63 -0
  37. data/docs/checks/img_width_and_height.md +79 -0
  38. data/docs/checks/invalid_args.md +56 -0
  39. data/docs/checks/liquid_tag.md +65 -0
  40. data/docs/checks/missing_enable_comment.md +50 -0
  41. data/docs/checks/missing_template.md +65 -0
  42. data/docs/checks/parse_json_format.md +76 -0
  43. data/docs/checks/parser_blocking_javascript.md +97 -0
  44. data/docs/checks/required_layout_object.md +28 -0
  45. data/docs/checks/space_inside_braces.md +89 -0
  46. data/docs/checks/syntax_error.md +49 -0
  47. data/docs/checks/template_length.md +45 -0
  48. data/docs/checks/undefined_object.md +71 -0
  49. data/docs/checks/unknown_filter.md +46 -0
  50. data/docs/checks/unused_assign.md +63 -0
  51. data/docs/checks/unused_partial.md +32 -0
  52. data/docs/checks/valid_yaml.md +48 -0
  53. data/docs/flamegraph.svg +18488 -0
  54. data/docs/language_server/code-action-command-palette.png +0 -0
  55. data/docs/language_server/code-action-flow.png +0 -0
  56. data/docs/language_server/code-action-keyboard.png +0 -0
  57. data/docs/language_server/code-action-light-bulb.png +0 -0
  58. data/docs/language_server/code-action-problem.png +0 -0
  59. data/docs/language_server/code-action-quickfix.png +0 -0
  60. data/docs/language_server/how_to_correct_code_with_code_actions_and_execute_command.md +197 -0
  61. data/docs/preview.png +0 -0
  62. data/exe/platformos-check +6 -0
  63. data/exe/platformos-check-language-server +7 -0
  64. data/lib/platformos_check/analyzer.rb +178 -0
  65. data/lib/platformos_check/api_call_file.rb +9 -0
  66. data/lib/platformos_check/app.rb +138 -0
  67. data/lib/platformos_check/app_file.rb +89 -0
  68. data/lib/platformos_check/app_file_rewriter.rb +79 -0
  69. data/lib/platformos_check/asset_file.rb +34 -0
  70. data/lib/platformos_check/bug.rb +23 -0
  71. data/lib/platformos_check/check.rb +163 -0
  72. data/lib/platformos_check/checks/TEMPLATE.rb.erb +11 -0
  73. data/lib/platformos_check/checks/convert_include_to_render.rb +17 -0
  74. data/lib/platformos_check/checks/deprecated_filter.rb +123 -0
  75. data/lib/platformos_check/checks/html_parsing_error.rb +13 -0
  76. data/lib/platformos_check/checks/img_lazy_loading.rb +18 -0
  77. data/lib/platformos_check/checks/img_width_and_height.rb +46 -0
  78. data/lib/platformos_check/checks/invalid_args.rb +81 -0
  79. data/lib/platformos_check/checks/liquid_tag.rb +47 -0
  80. data/lib/platformos_check/checks/missing_enable_comment.rb +37 -0
  81. data/lib/platformos_check/checks/missing_template.rb +107 -0
  82. data/lib/platformos_check/checks/parse_json_format.rb +31 -0
  83. data/lib/platformos_check/checks/parser_blocking_javascript.rb +17 -0
  84. data/lib/platformos_check/checks/required_layout_object.rb +41 -0
  85. data/lib/platformos_check/checks/space_inside_braces.rb +150 -0
  86. data/lib/platformos_check/checks/syntax_error.rb +31 -0
  87. data/lib/platformos_check/checks/template_length.rb +20 -0
  88. data/lib/platformos_check/checks/undefined_object.rb +206 -0
  89. data/lib/platformos_check/checks/unknown_filter.rb +27 -0
  90. data/lib/platformos_check/checks/unused_assign.rb +101 -0
  91. data/lib/platformos_check/checks/unused_partial.rb +93 -0
  92. data/lib/platformos_check/checks/valid_yaml.rb +16 -0
  93. data/lib/platformos_check/checks.rb +73 -0
  94. data/lib/platformos_check/checks_tracking.rb +9 -0
  95. data/lib/platformos_check/cli.rb +239 -0
  96. data/lib/platformos_check/config.rb +219 -0
  97. data/lib/platformos_check/config_file.rb +6 -0
  98. data/lib/platformos_check/corrector.rb +68 -0
  99. data/lib/platformos_check/disabled_check.rb +44 -0
  100. data/lib/platformos_check/disabled_checks.rb +96 -0
  101. data/lib/platformos_check/email_file.rb +9 -0
  102. data/lib/platformos_check/exceptions.rb +36 -0
  103. data/lib/platformos_check/file_system_storage.rb +93 -0
  104. data/lib/platformos_check/graphql_file.rb +68 -0
  105. data/lib/platformos_check/html_check.rb +8 -0
  106. data/lib/platformos_check/html_node.rb +210 -0
  107. data/lib/platformos_check/html_visitor.rb +36 -0
  108. data/lib/platformos_check/in_memory_storage.rb +68 -0
  109. data/lib/platformos_check/json_file.rb +57 -0
  110. data/lib/platformos_check/json_helper.rb +73 -0
  111. data/lib/platformos_check/json_helpers.rb +24 -0
  112. data/lib/platformos_check/json_printer.rb +32 -0
  113. data/lib/platformos_check/language_server/bridge.rb +167 -0
  114. data/lib/platformos_check/language_server/channel.rb +69 -0
  115. data/lib/platformos_check/language_server/client_capabilities.rb +27 -0
  116. data/lib/platformos_check/language_server/code_action_engine.rb +32 -0
  117. data/lib/platformos_check/language_server/code_action_provider.rb +41 -0
  118. data/lib/platformos_check/language_server/code_action_providers/quickfix_code_action_provider.rb +85 -0
  119. data/lib/platformos_check/language_server/code_action_providers/source_fix_all_code_action_provider.rb +41 -0
  120. data/lib/platformos_check/language_server/completion_context.rb +52 -0
  121. data/lib/platformos_check/language_server/completion_engine.rb +32 -0
  122. data/lib/platformos_check/language_server/completion_helper.rb +26 -0
  123. data/lib/platformos_check/language_server/completion_provider.rb +53 -0
  124. data/lib/platformos_check/language_server/completion_providers/assignments_completion_provider.rb +40 -0
  125. data/lib/platformos_check/language_server/completion_providers/filter_completion_provider.rb +102 -0
  126. data/lib/platformos_check/language_server/completion_providers/object_attribute_completion_provider.rb +48 -0
  127. data/lib/platformos_check/language_server/completion_providers/object_completion_provider.rb +38 -0
  128. data/lib/platformos_check/language_server/completion_providers/render_snippet_completion_provider.rb +50 -0
  129. data/lib/platformos_check/language_server/completion_providers/tag_completion_provider.rb +41 -0
  130. data/lib/platformos_check/language_server/configuration.rb +89 -0
  131. data/lib/platformos_check/language_server/constants.rb +29 -0
  132. data/lib/platformos_check/language_server/diagnostic.rb +129 -0
  133. data/lib/platformos_check/language_server/diagnostics_engine.rb +131 -0
  134. data/lib/platformos_check/language_server/diagnostics_manager.rb +184 -0
  135. data/lib/platformos_check/language_server/document_change_corrector.rb +271 -0
  136. data/lib/platformos_check/language_server/document_link_engine.rb +21 -0
  137. data/lib/platformos_check/language_server/document_link_provider.rb +71 -0
  138. data/lib/platformos_check/language_server/document_link_providers/asset_document_link_provider.rb +11 -0
  139. data/lib/platformos_check/language_server/document_link_providers/include_document_link_provider.rb +11 -0
  140. data/lib/platformos_check/language_server/document_link_providers/render_document_link_provider.rb +11 -0
  141. data/lib/platformos_check/language_server/document_link_providers/section_document_link_provider.rb +11 -0
  142. data/lib/platformos_check/language_server/execute_command_engine.rb +19 -0
  143. data/lib/platformos_check/language_server/execute_command_provider.rb +30 -0
  144. data/lib/platformos_check/language_server/execute_command_providers/correction_execute_command_provider.rb +48 -0
  145. data/lib/platformos_check/language_server/execute_command_providers/run_checks_execute_command_provider.rb +28 -0
  146. data/lib/platformos_check/language_server/handler.rb +310 -0
  147. data/lib/platformos_check/language_server/hover_engine.rb +32 -0
  148. data/lib/platformos_check/language_server/hover_provider.rb +53 -0
  149. data/lib/platformos_check/language_server/hover_providers/filter_hover_provider.rb +113 -0
  150. data/lib/platformos_check/language_server/io_messenger.rb +109 -0
  151. data/lib/platformos_check/language_server/messenger.rb +27 -0
  152. data/lib/platformos_check/language_server/protocol.rb +55 -0
  153. data/lib/platformos_check/language_server/server.rb +188 -0
  154. data/lib/platformos_check/language_server/tokens.rb +55 -0
  155. data/lib/platformos_check/language_server/type_helper.rb +22 -0
  156. data/lib/platformos_check/language_server/uri_helper.rb +39 -0
  157. data/lib/platformos_check/language_server/variable_lookup_finder/assignments_finder/node_handler.rb +87 -0
  158. data/lib/platformos_check/language_server/variable_lookup_finder/assignments_finder/scope.rb +60 -0
  159. data/lib/platformos_check/language_server/variable_lookup_finder/assignments_finder/scope_visitor.rb +44 -0
  160. data/lib/platformos_check/language_server/variable_lookup_finder/assignments_finder.rb +76 -0
  161. data/lib/platformos_check/language_server/variable_lookup_finder/constants.rb +44 -0
  162. data/lib/platformos_check/language_server/variable_lookup_finder/liquid_fixer.rb +103 -0
  163. data/lib/platformos_check/language_server/variable_lookup_finder/potential_lookup.rb +10 -0
  164. data/lib/platformos_check/language_server/variable_lookup_finder/tolerant_parser.rb +94 -0
  165. data/lib/platformos_check/language_server/variable_lookup_finder.rb +262 -0
  166. data/lib/platformos_check/language_server/variable_lookup_traverser.rb +70 -0
  167. data/lib/platformos_check/language_server/versioned_in_memory_storage.rb +84 -0
  168. data/lib/platformos_check/language_server.rb +71 -0
  169. data/lib/platformos_check/layout_file.rb +15 -0
  170. data/lib/platformos_check/liquid_check.rb +10 -0
  171. data/lib/platformos_check/liquid_file.rb +102 -0
  172. data/lib/platformos_check/liquid_node.rb +570 -0
  173. data/lib/platformos_check/liquid_visitor.rb +39 -0
  174. data/lib/platformos_check/migration_file.rb +9 -0
  175. data/lib/platformos_check/node.rb +53 -0
  176. data/lib/platformos_check/offense.rb +228 -0
  177. data/lib/platformos_check/page_file.rb +9 -0
  178. data/lib/platformos_check/parsing_helpers.rb +21 -0
  179. data/lib/platformos_check/partial_file.rb +15 -0
  180. data/lib/platformos_check/platformos_liquid/deprecated_filter.rb +31 -0
  181. data/lib/platformos_check/platformos_liquid/documentation/markdown_template.rb +51 -0
  182. data/lib/platformos_check/platformos_liquid/documentation.rb +45 -0
  183. data/lib/platformos_check/platformos_liquid/filter.rb +19 -0
  184. data/lib/platformos_check/platformos_liquid/object.rb +15 -0
  185. data/lib/platformos_check/platformos_liquid/source_index/base_entry.rb +66 -0
  186. data/lib/platformos_check/platformos_liquid/source_index/base_state.rb +23 -0
  187. data/lib/platformos_check/platformos_liquid/source_index/filter_entry.rb +26 -0
  188. data/lib/platformos_check/platformos_liquid/source_index/filter_state.rb +11 -0
  189. data/lib/platformos_check/platformos_liquid/source_index/object_entry.rb +20 -0
  190. data/lib/platformos_check/platformos_liquid/source_index/object_state.rb +11 -0
  191. data/lib/platformos_check/platformos_liquid/source_index/parameter_entry.rb +25 -0
  192. data/lib/platformos_check/platformos_liquid/source_index/property_entry.rb +21 -0
  193. data/lib/platformos_check/platformos_liquid/source_index/return_type_entry.rb +41 -0
  194. data/lib/platformos_check/platformos_liquid/source_index/tag_entry.rb +24 -0
  195. data/lib/platformos_check/platformos_liquid/source_index/tag_state.rb +11 -0
  196. data/lib/platformos_check/platformos_liquid/source_index.rb +79 -0
  197. data/lib/platformos_check/platformos_liquid/source_manager.rb +116 -0
  198. data/lib/platformos_check/platformos_liquid/tag.rb +59 -0
  199. data/lib/platformos_check/platformos_liquid.rb +21 -0
  200. data/lib/platformos_check/position.rb +180 -0
  201. data/lib/platformos_check/position_helper.rb +57 -0
  202. data/lib/platformos_check/printer.rb +87 -0
  203. data/lib/platformos_check/regex_helpers.rb +21 -0
  204. data/lib/platformos_check/releaser.rb +43 -0
  205. data/lib/platformos_check/schema_file.rb +6 -0
  206. data/lib/platformos_check/sms_file.rb +9 -0
  207. data/lib/platformos_check/storage.rb +29 -0
  208. data/lib/platformos_check/string_helpers.rb +48 -0
  209. data/lib/platformos_check/tags/background.rb +67 -0
  210. data/lib/platformos_check/tags/base.rb +14 -0
  211. data/lib/platformos_check/tags/base_block.rb +14 -0
  212. data/lib/platformos_check/tags/base_tag_methods.rb +59 -0
  213. data/lib/platformos_check/tags/cache.rb +13 -0
  214. data/lib/platformos_check/tags/export.rb +30 -0
  215. data/lib/platformos_check/tags/form.rb +19 -0
  216. data/lib/platformos_check/tags/function.rb +58 -0
  217. data/lib/platformos_check/tags/graphql.rb +70 -0
  218. data/lib/platformos_check/tags/hash_assign.rb +75 -0
  219. data/lib/platformos_check/tags/log.rb +15 -0
  220. data/lib/platformos_check/tags/parse_json.rb +24 -0
  221. data/lib/platformos_check/tags/print.rb +20 -0
  222. data/lib/platformos_check/tags/redirect_to.rb +15 -0
  223. data/lib/platformos_check/tags/render.rb +60 -0
  224. data/lib/platformos_check/tags/response_headers.rb +20 -0
  225. data/lib/platformos_check/tags/response_status.rb +20 -0
  226. data/lib/platformos_check/tags/return.rb +20 -0
  227. data/lib/platformos_check/tags/session.rb +27 -0
  228. data/lib/platformos_check/tags/sign_in.rb +27 -0
  229. data/lib/platformos_check/tags/spam_protection.rb +15 -0
  230. data/lib/platformos_check/tags/theme_render.rb +58 -0
  231. data/lib/platformos_check/tags/try.rb +59 -0
  232. data/lib/platformos_check/tags.rb +65 -0
  233. data/lib/platformos_check/translation_file.rb +6 -0
  234. data/lib/platformos_check/user_schema_file.rb +6 -0
  235. data/lib/platformos_check/version.rb +5 -0
  236. data/lib/platformos_check/yaml_check.rb +11 -0
  237. data/lib/platformos_check/yaml_file.rb +57 -0
  238. data/lib/platformos_check.rb +106 -0
  239. data/platformos-check.gemspec +34 -0
  240. metadata +329 -0
@@ -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 theme file. 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 PlatformOS Check 0.0.1.
39
+
40
+ ## Resources
41
+
42
+ - [Deprecated Tags Reference][deprecated]
43
+ - [Rule Source][codesource]
44
+ - [Documentation Source][docsource]
45
+
46
+ [deprecated]: https://documentation.platformos.com/api-reference/liquid/include
47
+ [codesource]: /lib/platformos_check/checks/convert_include_to_render.rb
48
+ [docsource]: /docs/checks/convert_include_to_render.md
@@ -0,0 +1,30 @@
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
+ ## Check Options
10
+
11
+ The default configuration for this check is the following:
12
+
13
+ ```yaml
14
+ DeprecatedFilter:
15
+ enabled: true
16
+ ```
17
+
18
+ ## Version
19
+
20
+ This check has been introduced in PlatformOS Check 0.1.0.
21
+
22
+ ## Resources
23
+
24
+ - [Deprecated Filters Reference][deprecated]
25
+ - [Rule Source][codesource]
26
+ - [Documentation Source][docsource]
27
+
28
+ [deprecated]: https://documentation.platformos.com/api-reference/liquid/platformos-filters
29
+ [codesource]: /lib/platformos_check/checks/deprecated_filter.rb
30
+ [docsource]: /docs/checks/deprecated_filter.md
@@ -0,0 +1,50 @@
1
+ # Report HTML parsing errors (`HtmlParsingError`)
2
+
3
+ Report errors preventing the HTML from being parsed and analyzed by PlatformOS Check.
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at reporting HTML errors that prevent a file from being analyzed.
8
+
9
+ The HTML parser limits the number of attributes per element to 400, and the maximum depth of the DOM tree to 400 levels. If any one of those limits is reached, parsing stops, and all HTML offenses on this file are ignored.
10
+
11
+ :-1: Examples of **incorrect** code for this check:
12
+
13
+ ```liquid
14
+ <img src="muffin.jpeg"
15
+ data-attrbute-1=""
16
+ data-attrbute-2=""
17
+ ... up to
18
+ data-attrbute-400="">
19
+ ```
20
+
21
+ :+1: Examples of **correct** code for this check:
22
+
23
+ ```liquid
24
+ <img src="muffin.jpeg">
25
+ ```
26
+
27
+ ## Check Options
28
+
29
+ The default configuration for this check is the following:
30
+
31
+ ```yaml
32
+ HtmlParsingError:
33
+ enabled: true
34
+ ```
35
+
36
+ ## When Not To Use It
37
+
38
+ If you don't care about HTML offenses.
39
+
40
+ ## Version
41
+
42
+ This check has been introduced in PlatformOS Check 0.0.1.
43
+
44
+ ## Resources
45
+
46
+ - [Rule Source][codesource]
47
+ - [Documentation Source][docsource]
48
+
49
+ [codesource]: /lib/platformos_check/checks/html_parsing_error.rb
50
+ [docsource]: /docs/checks/html_parsing_error.md
@@ -0,0 +1,63 @@
1
+ # Lazy loading image tags (`ImgLazyLoading`)
2
+
3
+ Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the length of the critical rendering path, which translates into reduced page load times.
4
+
5
+ Lazy loading can occur on different moments in the application, but it typically happens on some user interactions such as scrolling and navigation.
6
+
7
+ Very often, webpages contain many images that contribute to data-usage and how fast a page can load. Most of those images are off-screen (non-critical), requiring user interaction (an example being scroll) in order to view them.
8
+
9
+ _Quoted from [MDN - Lazy loading][mdn]_
10
+
11
+ As a general rule you should apply `loading="lazy"` to elements that are **not initially visible** when the page loads. Only images that require user interaction (scrolling, hovering, clicking etc.) to be seen can be safely lazy loaded without negatively impacting the rendering performance.
12
+
13
+ ## Check Details
14
+
15
+ This check is aimed at deferring loading non-critical images.
16
+
17
+ :-1: Examples of **incorrect** code for this check:
18
+
19
+ ```liquid
20
+ <img src="a.jpg">
21
+
22
+ <!-- Replaces lazysizes.js -->
23
+ <img data-src="a.jpg" class="lazyload">
24
+
25
+ <!-- `auto` is deprecated -->
26
+ <img src="a.jpg" loading="auto">
27
+ ```
28
+
29
+ :+1: Examples of **correct** code for this check:
30
+
31
+ ```liquid
32
+ <img src="a.jpg" loading="lazy">
33
+
34
+ <!-- `eager` is also accepted -->
35
+ <img src="a.jpg" loading="eager">
36
+ ```
37
+
38
+ ## Check Options
39
+
40
+ The default configuration for this check is the following:
41
+
42
+ ```yaml
43
+ ImgLazyLoading:
44
+ enabled: true
45
+ ```
46
+
47
+ ## When Not To Use It
48
+
49
+ There should be no cases where disabling this rule is needed. When it comes to rendering performance, it is generally better to specify `loading="eager"` as a default. You may want to do that for sections that are often placed in different parts of the page (top, middle, bottom), which makes it hard to reason about which value should be used.
50
+
51
+ ## Version
52
+
53
+ This check has been introduced in PlatformOS Check 0.10.0.
54
+
55
+ ## Resources
56
+
57
+ - [Rule Source][codesource]
58
+ - [Documentation Source][docsource]
59
+ - [MDN - Lazy loading][mdn]
60
+
61
+ [codesource]: /lib/platformos_check/checks/img_lazy_loading.rb
62
+ [docsource]: /docs/checks/img_lazy_loading.md
63
+ [mdn]: https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading
@@ -0,0 +1,79 @@
1
+ # Width and height attributes on image tags (`ImgWidthAndHeight`)
2
+
3
+ This check exists to prevent [cumulative layout shift][cls] (CLS) in themes.
4
+
5
+ The absence of `width` and `height` attributes on an `img` tag prevents the browser from knowing the aspect ratio of the image before it is downloaded. Unless another technique is used to allocate space, the browser will consider the image to be of height 0 until it is loaded.
6
+
7
+ This has numerous nefarious implications:
8
+
9
+ 1. [This causes layout shift as images start appearing one after the other.][codepenshift] Text starts flying down the page as the image pushes it down.
10
+ 2. [This breaks lazy loading.][codepenlazy] When all images have a height of 0px, every image is inside the viewport. And when everything is in the viewport, everything gets loaded. There's nothing lazy about it!
11
+
12
+ The fix is easy. Make sure the `width` and `height` attribute are set on the `img` tag and that the CSS width of the image is set.
13
+
14
+ Note: The width and height attributes of an image do not have units.
15
+
16
+ ## Check Details
17
+
18
+ This check is aimed at eliminating content layout shift in themes by enforcing the use of the `width` and `height` attributes on `img` tags.
19
+
20
+ :-1: Examples of **incorrect** code for this check:
21
+
22
+ ```liquid
23
+ <img alt="cat" src="cat.jpg">
24
+ <img alt="cat" src="cat.jpg" width="100px" height="100px">
25
+ <img alt="{{ image.alt }}" src="{{ image.src }}">
26
+ ```
27
+
28
+ :+1: Examples of **correct** code for this check:
29
+
30
+ ```liquid
31
+ <img alt="cat" src="cat.jpg" width="100" height="200">
32
+ <img
33
+ alt="{{ image.alt }}"
34
+ src="{{ image.src }}"
35
+ width="{{ image.width }}"
36
+ height="{{ image.height }}"
37
+ >
38
+ ```
39
+
40
+ **NOTE:** The CSS `width` of the `img` should _also_ be set for the image to be responsive.
41
+
42
+ ## Check Options
43
+
44
+ The default configuration for this check is the following:
45
+
46
+ ```yaml
47
+ ImgWidthAndHeight:
48
+ enabled: true
49
+ ```
50
+
51
+ ## When Not To Use It
52
+
53
+ There are some cases where you can avoid content-layout shift without needing the width and height attributes:
54
+
55
+ - When the aspect-ratio of the displayed image should be independent of the uploaded image. In those cases, the solution is still the padding-top hack with an `overflow: hidden container`.
56
+ - When you are happy with the padding-top hack.
57
+
58
+ In those cases, it is fine to disable this check with the comment.
59
+
60
+ It is otherwise unwise to disable this check, since it would negatively impact the mobile search ranking of the merchants using your theme.
61
+
62
+ ## Version
63
+
64
+ This check has been introduced in PlatformOS Check 0.6.0.
65
+
66
+ ## Resources
67
+
68
+ - [Cumulative Layout Shift Reference][cls]
69
+ - [Codepen illustrating the impact of width and height on layout shift][codepenshift]
70
+ - [Codepen illustrating the impact of width and height on lazy loading][codepenlazy]
71
+ - [Rule Source][codesource]
72
+ - [Documentation Source][docsource]
73
+
74
+ [cls]: https://web.dev/cls/
75
+ [codepenshift]: https://codepen.io/charlespwd/pen/YzpxPEp?editors=1100
76
+ [codepenlazy]: https://codepen.io/charlespwd/pen/abZmqXJ?editors=0111
77
+ [aspect-ratio]: https://caniuse.com/mdn-css_properties_aspect-ratio
78
+ [codesource]: /lib/platformos_check/checks/img_aspect_ratio.rb
79
+ [docsource]: /docs/checks/img_aspect_ratio.md
@@ -0,0 +1,56 @@
1
+ # Prevent providing invalid arguments in function, render and graphql tags Liquid (`InvalidArgs`)
2
+
3
+ This check exists to prevent providing invalid arguments via `function`, `render` and `graphql` tags.
4
+
5
+ ## Examples
6
+
7
+ The following examples contain code snippets that either fail or pass this check.
8
+
9
+ ### &#x2717; Fail
10
+
11
+ ```liquid
12
+ {% comment %}app/graphql/my-query does not define invalid_argument{% endcomment %}
13
+ {% graphql res = 'my-query', invalid_argument: 10 %}
14
+ ```
15
+
16
+ ```liquid
17
+ {% function res = 'my-function', arg: 1, arg: 2 %}
18
+ ```
19
+
20
+ ```liquid
21
+ {% render res = 'my-partial', context: context %}
22
+ ```
23
+
24
+ ### &#x2713; Pass
25
+
26
+ ```liquid
27
+ {% comment %}app/graphql/my-query defines defined_argument{% endcomment %}
28
+ {% graphql res = 'my-query', defined_argument: 10 %}
29
+ ```
30
+
31
+ ## Options
32
+
33
+ The following example contains the default configuration for this check:
34
+
35
+ ```yaml
36
+ InvalidArgs:
37
+ enabled: true
38
+ ```
39
+
40
+ | Parameter | Description |
41
+ | --- | --- |
42
+ | enabled | Whether the check is enabled. |
43
+ | severity | The [severity](https://documentation.platformos.com/developer-guide/platformos-check/platformos-check#check-severity) of the check. |
44
+
45
+ ## When Not To Use It
46
+
47
+ It is not safe to disable this rule.
48
+
49
+ ## Resources
50
+
51
+ - [platformOS GraphQL Reference](https://documentation.platformos.com/api-reference/graphql/glossary)
52
+ - [Rule source][codesource]
53
+ - [Documentation source][docsource]
54
+
55
+ [codesource]: /lib/platformos_check/checks/graphql_args.rb
56
+ [docsource]: /docs/checks/graphql_args.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: 5
43
+ ```
44
+
45
+ ### `min_consecutive_statements`
46
+
47
+ The `min_consecutive_statements` option (Default: `5`) 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 PlatformOS Check 0.0.1.
56
+
57
+ ## Resources
58
+
59
+ - [`{% liquid %}` Tag Reference][liquid]
60
+ - [Rule Source][codesource]
61
+ - [Documentation Source][docsource]
62
+
63
+ [liquid]: https://documentation.platformos.com/api-reference/liquid/platformos-tags
64
+ [codesource]: /lib/platformos_check/checks/liquid_tag.rb
65
+ [docsource]: /docs/checks/liquid_tag.md
@@ -0,0 +1,50 @@
1
+ # Prevent missing platformos-check-enable comments (`MissingEnableComment`)
2
+
3
+ When `platformos-check-disable` is used in the middle of a theme file, the corresponding `platformos-check-enable` comment should also be included.
4
+
5
+ ## Check Details
6
+
7
+ This check aims at eliminating missing `platformos-check-enable` comments.
8
+
9
+ :-1: Example of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+ <!doctype html>
13
+ <html>
14
+ <head>
15
+ {% # platformos-check-disable ParserBlockingJavaScript %}
16
+ <script src="https://cdnjs.com/jquery.min.js"></script>
17
+ </head>
18
+ <body>
19
+ <!-- ... -->
20
+ </body>
21
+ </html>
22
+ ```
23
+
24
+ :+1: Example of **correct** code for this check:
25
+
26
+ ```liquid
27
+ <!doctype html>
28
+ <html>
29
+ <head>
30
+ {% # platformos-check-disable ParserBlockingJavaScript %}
31
+ <script src="https://cdnjs.com/jquery.min.js"></script>
32
+ {% # platformos-check-enable ParserBlockingJavaScript %}
33
+ </head>
34
+ <body>
35
+ <!-- ... -->
36
+ </body>
37
+ </html>
38
+ ```
39
+
40
+ ## Version
41
+
42
+ This check has been introduced in PlatformOS Check 0.3.0.
43
+
44
+ ## Resources
45
+
46
+ - [Rule Source][codesource]
47
+ - [Documentation Source][docsource]
48
+
49
+ [codesource]: /lib/platformos_check/checks/missing_enable_comment.rb
50
+ [docsource]: /docs/checks/missing_enable_comment.md
@@ -0,0 +1,65 @@
1
+ # Prevent missing templates (`MissingTemplate`)
2
+
3
+ This check exists to prevent rendering resources with the `render` tag, `function` tag (and the deprecated `include` tag) that do not exist.
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at preventing liquid rendering errors.
8
+
9
+ :-1: Example of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+ {% render 'partial-that-does-not-exist' %}
13
+ ```
14
+
15
+ :+1: Example of **correct** code for this check:
16
+
17
+ ```liquid
18
+ {% render 'partial-that-exists' %}
19
+ ```
20
+
21
+ ## Check Options
22
+
23
+ The default configuration for this check is the following:
24
+
25
+ ```yaml
26
+ MissingTemplate:
27
+ enabled: true
28
+ ignore_missing: []
29
+ ```
30
+
31
+ ### `ignore_missing`
32
+
33
+ Specify a list of patterns of missing template files to ignore.
34
+
35
+ While the `ignore` option will ignore all occurrences of `MissingTemplate` according to the file in which they appear, `ignore_missing` allows ignoring all occurrences of `MissingTemplate` based on the target template, the template being rendered.
36
+
37
+ For example:
38
+
39
+ ```yaml
40
+ MissingTemplate:
41
+ ignore_missing:
42
+ - icon-*
43
+ ```
44
+
45
+ Would ignore offenses on `{% render 'icon-missing' %}` across app files.
46
+
47
+ ```yaml
48
+ MissingTemplate:
49
+ ignore:
50
+ - modules/private-module/index.liquid
51
+ ```
52
+
53
+ Would ignore all `MissingTemplate` in `modules/private-module/index.liquid`, no mater the file being rendered.
54
+
55
+ ## Version
56
+
57
+ This check has been introduced in PlatformOS Check 0.0.1.
58
+
59
+ ## Resources
60
+
61
+ - [Rule Source][codesource]
62
+ - [Documentation Source][docsource]
63
+
64
+ [codesource]: /lib/platformos_check/checks/missing_template.rb
65
+ [docsource]: /docs/checks/missing_template.md
@@ -0,0 +1,76 @@
1
+ # Prevent unformatted parse_json tags (`ParseJsonFormat`)
2
+
3
+ _Version 1.9.0+_
4
+
5
+ This check exists to ensure the JSON in your parses is pretty.
6
+
7
+ It exists as a facilitator for its auto-correction. This way you can right-click fix the problem.
8
+
9
+ ## Examples
10
+
11
+ The following examples contain code snippets that either fail or pass this check.
12
+
13
+ ### &#x2717; Fail
14
+
15
+ ```liquid
16
+ {% parse_json my_json %}
17
+ {
18
+ "locales": {
19
+ "en": {
20
+ "title": "Welcome", "product": "Product"
21
+ },
22
+ "fr": { "title": "Bienvenue", "product": "Produit" }
23
+ }
24
+ }
25
+ {% endparse_json %}
26
+ ```
27
+
28
+ ### &#x2713; Pass
29
+
30
+ ```liquid
31
+ {% parse_json my_json %}
32
+ {
33
+ "locales": {
34
+ "en": {
35
+ "title": "Welcome",
36
+ "product": "Product"
37
+ },
38
+ "fr": {
39
+ "title": "Bienvenue",
40
+ "product": "Produit"
41
+ }
42
+ }
43
+ }
44
+ {% endparse_json %}
45
+ ```
46
+
47
+ ## Options
48
+
49
+ The following example contains the default configuration for this check:
50
+
51
+ ```yaml
52
+ ParseJsonFormat:
53
+ enabled: true
54
+ severity: style
55
+ start_level: 0
56
+ indent: ' '
57
+ ```
58
+
59
+ | Parameter | Description |
60
+ | --- | --- |
61
+ | enabled | Whether the check is enabled. |
62
+ | severity | The [severity](https://documentation.platformos.com/developer-guide/platformos-check/platformos-check#check-severity) of the check. |
63
+ | start_level | The indentation level. If you prefer an indented parse_json, set this to 1. |
64
+ | indent | The character(s) used for indentation levels. |
65
+
66
+ ## Disabling this check
67
+
68
+ This check is safe to disable. You might want to disable this check if you do not care about the visual appearance of your parse_json tags.
69
+
70
+ ## Resources
71
+
72
+ - [Rule source][codesource]
73
+ - [Documentation source][docsource]
74
+
75
+ [codesource]: /lib/platformos_check/checks/parse_json_format.rb
76
+ [docsource]: /docs/checks/parse_json_format.md
@@ -0,0 +1,97 @@
1
+ # Discourage use of parser-blocking JavaScript (`ParserBlockingJavaScript`)
2
+
3
+ The `defer` or `async` attributes are extremely important on script tags. When neither of those attributes are used, a script tag will block the construction and rendering of the DOM until the script is _loaded_, _parsed_ and _executed_. It also creates congestion on the Network, messes with the resource priorities and significantly delays the rendering of the page.
4
+
5
+ Considering that JavaScript on platformOS apps should always be used to progressively _enhance_ the experience of the site, app should never make use of parser-blocking script tags.
6
+
7
+ As a general rule, use `defer` if the order of execution matters, `async` otherwise. When in doubt, choose either one and get 80/20 of the benefits.
8
+
9
+ ## Check Details
10
+
11
+ This check is aimed at eliminating parser-blocking JavaScript on app.
12
+
13
+ :-1: Examples of **incorrect** code for this check:
14
+
15
+ ```liquid
16
+ <!-- The script_tag filter outputs a parser-blocking script -->
17
+ {{ 'app-code.js' | asset_url | script_tag }}
18
+
19
+ <!-- jQuery is typically loaded synchronously because inline scripts depend on $, don't do that. -->
20
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
21
+ ...
22
+ <button id="thing">Click me!</button>
23
+ <script>
24
+ $('#thing').click(() => {
25
+ alert('Oh. Hi Mark!');
26
+ });
27
+ </script>
28
+ ```
29
+
30
+ :+1: Examples of **correct** code for this check:
31
+
32
+ ```liquid
33
+ <!-- Good. Using the asset_url filter + defer -->
34
+ <script src="{{ 'theme.js' | asset_url }}" defer></script>
35
+
36
+ <!-- Also good. Using the asset_url filter + async -->
37
+ <script src="{{ 'theme.js' | asset_url }}" async></script>
38
+
39
+ <!-- Better than synchronous jQuery -->
40
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js" defer></script>
41
+ ...
42
+ <button id="thing">Click me!</button>
43
+ <script>
44
+ // Because we're using `defer`, jQuery is guaranteed to
45
+ // be loaded when DOMContentLoaded fires. This technique
46
+ // could be used as a first step to refactor an old theme
47
+ // that inline depends on jQuery.
48
+ document.addEventListener('DOMContentLoaded', () => {
49
+ $('#thing').click(() => {
50
+ alert('Oh. Hi Mark!');
51
+ });
52
+ });
53
+ </script>
54
+
55
+ <!-- Even better. Web Native (no jQuery). -->
56
+ <button id="thing">Click Me</button>
57
+ <script>
58
+ const button = document.getElementById('thing');
59
+ button.addEventListener('click', () => {
60
+ alert('Oh. Hi Mark!');
61
+ });
62
+ </script>
63
+
64
+ <!-- Best -->
65
+ <script src="{{ 'theme.js' | asset_url }}" defer></script>
66
+ ...
67
+ <button id="thing">Click Me</button>
68
+ ```
69
+
70
+ ## Check Options
71
+
72
+ The default configuration for this check is the following:
73
+
74
+ ```yaml
75
+ ParserBlockingJavaScript:
76
+ enabled: true
77
+ ```
78
+
79
+ ## When Not To Use It
80
+
81
+ This should only be turned off with the `platformos-check-disable` comment when there's no better way to accomplish what you're doing than with a parser-blocking script.
82
+
83
+ It is discouraged to turn this rule off.
84
+
85
+ ## Version
86
+
87
+ This check has been introduced in PlatformOS Check 0.0.1.
88
+
89
+ ## Resources
90
+
91
+ - [Lighthouse Render-Blocking Resources Audit][render-blocking]
92
+ - [Rule Source][codesource]
93
+ - [Documentation Source][docsource]
94
+
95
+ [render-blocking]: https://web.dev/render-blocking-resources/
96
+ [codesource]: /lib/platformos_check/checks/parser_blocking_javascript.rb
97
+ [docsource]: /docs/checks/parser_blocking_javascript.md