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
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,209 @@
1
+ # Contributing to platformOS Check
2
+
3
+ ## Standards
4
+
5
+ * Checks should do one thing, and do it well.
6
+ * PR should explain what the feature does, and why the change exists.
7
+ * PR should include any carrier specific documentation explaining how it works.
8
+ * Code _must_ be tested.
9
+ * Be consistent. Write clean code that follows [Ruby community standards](https://github.com/bbatsov/ruby-style-guide).
10
+ * Code should be generic and reusable.
11
+
12
+ ## How to contribute
13
+
14
+ 1. Fork it ( https://github.com/Platform-OS/platformos-lsp )
15
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
16
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
17
+ 4. Push to the branch (`git push origin my-new-feature`)
18
+ 5. Create a new Pull Request
19
+
20
+ ## Run Language Server
21
+
22
+ If you're making changes to the language server and you want to debug, you can run the repo's version of `platformos-check-language-server`.
23
+
24
+ ### Setup
25
+
26
+ Before configuring your IDE, run the following commands in a terminal:
27
+
28
+ * Make sure you have a `$HOME/bin`
29
+ ```bash
30
+ mkdir -p $HOME/bin
31
+ ```
32
+ * Paste this script to create an executable wrapper in `$HOME/bin/platformos-check-language-server` for language server
33
+ ```bash
34
+ cat <<-'EOF' > $HOME/bin/platformos-check-language-server
35
+ #!/usr/bin/env bash
36
+ cd "$HOME/src/github.com/Platform-OS/platformos-lsp" &> /dev/null
37
+ export PLATFORMOS_CHECK_DEBUG=true
38
+ export PLATFORMOS_CHECK_DEBUG_LOG_FILE="/tmp/platformos-check-debug.log"
39
+ touch "$PLATFORMOS_CHECK_DEBUG_LOG_FILE"
40
+ gem env &>/dev/null
41
+ bundle install &>/dev/null
42
+ bin/platformos-check-language-server
43
+ EOF
44
+ ```
45
+ * Make the script executable
46
+ ```bash
47
+ chmod u+x $HOME/bin/platformos-check-language-server
48
+ ```
49
+
50
+ #### Configure VS Code
51
+
52
+ 1. Download provided .vsix file
53
+ 2. Install it manually via View -> Extensions -> ... -> Install from VSIX
54
+ 3. Configure settings.json
55
+
56
+ ```
57
+ "platformosCheck.checkOnChange": true,
58
+ "platformosCheck.onlySingleFileChecks": false,
59
+ "platformOSLiquid.languageServerPath": "/Users/<your user>/bin/platformos-check-language-server",
60
+ "platformosCheck.checkOnOpen": true,
61
+ "platformosCheck.checkOnSave": true
62
+ ```
63
+
64
+ #### Configure Vim
65
+
66
+ If you use `coc.nvim` as your completion engine, add this to your CocConfig:
67
+
68
+ ```json
69
+ {
70
+ "languageserver": {
71
+ "platformos-check": {
72
+ "command": "/Users/<YOUR_USERNAME>/bin/platformos-check-language-server",
73
+ "trace.server": "verbose",
74
+ "filetypes": ["liquid", "graphql", "yaml", "yml"],
75
+ "rootPatterns": [".platformos-check.yml", ".pos"],
76
+ "settings": {
77
+ "platformosCheck": {
78
+ "checkOnSave": true,
79
+ "checkEnter": true,
80
+ "onlySingleFileChecks": false,
81
+ "checkOnChange": true,
82
+ "checkOnOpen": true
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ ```
90
+
91
+ ### Confirm Setup
92
+
93
+ * In another terminal from the root of theme check run `tail -f /tmp/platformos-check-debug.log` to watch the server logs
94
+ * Restart your IDE, confirm the response for initialize in the logs is pointing to the language server in the `$HOME/bin` directory (the version will be different)
95
+
96
+ ```json
97
+ "serverInfo": {
98
+ "name": "/Users/johndoe/bin/platformos-check-language-server",
99
+ "version": "1.10.3"
100
+ }
101
+ ```
102
+
103
+
104
+ ## Running Tests
105
+
106
+ ```
107
+ bundle install
108
+ bundle exec rake
109
+ ```
110
+
111
+ ## Checking a pOS app
112
+
113
+ ```
114
+ bin/platformos-check /path/to/your/app
115
+ ```
116
+
117
+ ## Creating a new "Check"
118
+
119
+ Run `bundle exec rake "new_check[MyNewCheckName]"` to generate all the files required to create a new check.
120
+
121
+ Check the [Check API](/docs/api/check.md) for how to implement a check. Also take a look at other checks in [lib/platformos_check/checks](/lib/platformos_check/checks).
122
+
123
+ We done implementing your check, add it to `config/default.yml` to enable it:
124
+
125
+ ```yaml
126
+ MyNewCheckName:
127
+ enabled: true
128
+ ignore: []
129
+ ```
130
+
131
+ If the check is configurable, the `initialize` argument names and default values should also be duplicated inside `config/default.yml`. eg.:
132
+
133
+ ```ruby
134
+ class MyCheckName < LiquidCheck
135
+ def initialize(muffin_mode: true)
136
+ @muffin_mode = muffin_mode
137
+ end
138
+ # ...
139
+ end
140
+ ```
141
+
142
+ ```yaml
143
+ MyNewCheckName:
144
+ enabled: true
145
+ ignore: []
146
+ muffin_mode: true
147
+ ```
148
+
149
+ ## Debugging
150
+
151
+ A couple of things are turned on when the `PLATFORMOS_CHECK_DEBUG` environment variable is set.
152
+
153
+ 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`
154
+ 2. The `--profile` flag appears. You can now create Flamegraphs to inspect performance.
155
+
156
+ ```
157
+ export PLATFORMOS_CHECK_DEBUG=true
158
+
159
+ # The following will behave slightly differently
160
+ bin/platformos-check ../dawn
161
+ bundle exec rake tests:in_memory
162
+
163
+ # The following becomes available
164
+ bin/platformos-check --profile ../dawn
165
+
166
+ # The LanguageServer will log the JSONRPC calls to STDERR
167
+ bin/platformos-check-language-server
168
+ ```
169
+
170
+ ### Profiling
171
+
172
+ `ruby-prof` and `ruby-prof-flamegraph` are both included as development dependencies.
173
+
174
+ #### Flamegraph
175
+
176
+ With the `--profile` flag, you can run platformos-check on a theme and the `ruby-prof-flamegraph` printer will output profiling information in a format [Flamegraph](/brendangregg/FlameGraph) understands.
177
+
178
+
179
+ **Setup:**
180
+
181
+ ```bash
182
+ # clone the FlameGraph repo somewhere
183
+ git clone https://github.com/brendangregg/FlameGraph.git
184
+
185
+ # the flamegraph.pl perl script is in that repo
186
+ alias flamegraph=/path/to/FlameGraph/flamegraph.pl
187
+ ```
188
+
189
+ **Profiling:**
190
+
191
+ ```
192
+ # run platformos-check with --profile
193
+ # pass the output to flamegraph
194
+ # dump the output into an svg file
195
+ bin/platformos-check --profile ../dawn \
196
+ | flamegraph --countname=ms --width=1750 \
197
+ > /tmp/fg.svg
198
+
199
+ # open the svg file in Chrome to look at the flamegraph
200
+ chrome /tmp/fg.svg
201
+ ```
202
+
203
+ What you'll see is an interactive version of the following image:
204
+
205
+ ![flamegraph](docs/flamegraph.svg)
206
+
207
+ ## Troubleshooting
208
+
209
+ If you run into issues during development, see the [troubleshooting guide](/TROUBLESHOOTING.md)
data/Gemfile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in platformos-check.gemspec
8
+ gemspec
9
+
10
+ gem 'bundler'
11
+ gem 'graphql'
12
+ gem 'rake'
13
+
14
+ group :test do
15
+ gem 'debug'
16
+ gem 'minitest'
17
+ gem 'minitest-focus'
18
+ gem 'mocha'
19
+ gem 'pry-byebug'
20
+ end
21
+
22
+ group :development do
23
+ gem 'guard'
24
+ gem 'guard-minitest'
25
+ gem 'ruby-prof'
26
+ gem 'ruby-prof-flamegraph'
27
+ gem 'solargraph'
28
+ end
29
+
30
+ gem 'rubocop', require: false
31
+ gem 'rubocop-minitest', require: false
32
+ gem 'rubocop-performance', require: false
33
+ gem 'rubocop-rake', require: false
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :minitest do
4
+ watch(%r{^test/(.*)_test.rb$})
5
+ watch(%r{^lib/platformos_check/(.*)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
6
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
7
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+
2
+ Copyright 2023-present, platformOS.
3
+
4
+ Contains code from activesupport Copyright (c) 2005-2019 David Heinemeier Hansson
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,18 @@
1
+ IMAGE_NAMES := lsp check
2
+ BUILD_TARGETS := $(patsubst %,build-%,$(IMAGE_NAMES))
3
+ PUSH_TARGETS := $(patsubst %,push-%,$(IMAGE_NAMES))
4
+
5
+ VERSION=0.0.1
6
+
7
+ IMAGE_NAME=platformos/platformos
8
+
9
+ build: $(BUILD_TARGETS)
10
+ build-%:
11
+ docker build -t ${IMAGE_NAME}-$*:${VERSION} -f docker/$*.Dockerfile .
12
+ docker tag ${IMAGE_NAME}-$*:${VERSION} ${IMAGE_NAME}-$*:latest
13
+
14
+ push: $(PUSH_TARGETS)
15
+ push-%:
16
+ docker push ${IMAGE_NAME}-$*:${VERSION}
17
+ docker push ${IMAGE_NAME}-$*:latest
18
+
data/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # platformOS Check ✅ - A linter for platformOS
2
+
3
+ PlatformOS Check is a tool that helps you follow platformOS recommendations & best practices by analyzing the Liquid inside your app.
4
+
5
+ ![](docs/preview.png)
6
+
7
+ ## Supported Checks
8
+
9
+ PlatformOS Check currently checks for the following:
10
+
11
+ ✅ Liquid syntax errors
12
+ ✅ JSON syntax errors
13
+ ✅ Missing snippet & section templates
14
+ ✅ Unused `{% assign ... %}`
15
+ ✅ Unused snippet templates
16
+ ✅ Template length
17
+ ✅ Deprecated tags
18
+ ✅ Unknown tags
19
+ ✅ Unknown filters
20
+ ✅ Missing or extra spaces inside `{% ... %}` and `{{ ... }}`
21
+ ✅ Using several `{% ... %}` instead of `{% liquid ... %}`
22
+ ✅ Undefined objects
23
+ ✅ Deprecated filters
24
+ ✅ Missing `platformos-check-enable` comment
25
+
26
+ As well as checks that prevent easy to spot performance problems:
27
+
28
+ ✅ Use of [parser-blocking](/docs/checks/parser_blocking_javascript.md) JavaScript
29
+ ✅ [Use of non-platformOS domains for assets](/docs/checks/remote_asset.md)
30
+ ✅ [Missing width and height attributes on `img` tags](/docs/checks/img_width_and_height.md)
31
+ ✅ [Too much JavaScript](/docs/checks/asset_size_javascript.md)
32
+ ✅ [Too much CSS](/docs/checks/asset_size_css.md)
33
+
34
+ For detailed descriptions and configuration options, [take a look at the complete list.](/docs/checks/)
35
+
36
+ With more to come! Suggestions welcome ([create an issue](https://github.com/Platform-OS/platformos-lsp/issues)).
37
+
38
+ ## Installation
39
+
40
+ - download and install the extension [more]
41
+ - next steps
42
+ -> [using-local-ruby]
43
+ -> [docker]
44
+
45
+ ### Using locally installed ruby
46
+
47
+ #### Requirements
48
+
49
+ - Ruby 3.2+
50
+
51
+ TODO
52
+
53
+ ### Using Docker
54
+
55
+ #### PlatformOS Check Language Server
56
+
57
+ - Create an executable `platformos-check-language-server` file and place it within a directory listed in your $PATH variable.
58
+
59
+ ```bash
60
+ DIR=$(pwd)
61
+ IMAGE_NAME=platformos/platformos-lsp:latest
62
+
63
+ LOG_DIR=$DIR/logs
64
+ mkdir $LOG_DIR
65
+ LOG_FILE=$LOG_DIR/platformos-lsp.log
66
+
67
+ exec docker run -i \
68
+ -v $DIR:$DIR \
69
+ -w $DIR \
70
+ -e PLATFORMOS_CHECK_DEBUG=true \
71
+ -e PLATFORMOS_CHECK_DEBUG_LOG_FILE=$LOG_FILE \
72
+ $IMAGE_NAME
73
+ ```
74
+ This script will automatically download the latest Docker image and initiate a language server. Visual Studio Code (VSC) manages this process automatically. However, you can run the script for verification if needed."
75
+
76
+ #### Troubleshooting
77
+
78
+ - In the event of `onlySingleFileChecks: true` not functioning as expected, please examine your Visual Studio Code (VSC) workspace. Ensure that the workspace contains only a single project.
79
+
80
+ #### PlatformOS Check
81
+
82
+ PlatformOS Check can be used also as a standalone function. Prepare the following executable script:
83
+
84
+ ```bash
85
+ DIR=$(pwd)
86
+ IMAGE_NAME=platformos/platformos-check:latest
87
+
88
+ LOG_DIR=$DIR/logs
89
+ mkdir $LOG_DIR
90
+ LOG_FILE=$LOG_DIR/platformos-check.log
91
+
92
+ exec docker run -i \
93
+ -v $DIR:$DIR \
94
+ -w $DIR \
95
+ -e PLATFORMOS_CHECK_DEBUG=true \
96
+ -e PLATFORMOS_CHECK_DEBUG_LOG_FILE=$LOG_FILE \
97
+ $IMAGE_NAME
98
+ ```
99
+
100
+ ## Configuration
101
+
102
+ Add a `.platformos-check.yml` file at the root of your app.
103
+
104
+ See [config/default.yml](config/default.yml) for available options & defaults.
105
+
106
+ ## Disable checks with comments
107
+
108
+ Use Liquid comments to disable and re-enable all checks for a section of your file:
109
+
110
+ ```liquid
111
+ {% # platformos-check-disable %}
112
+ {% assign x = 1 %}
113
+ {% # platformos-check-enable %}
114
+ ```
115
+
116
+ Disable a specific check by including it in the comment:
117
+
118
+ ```liquid
119
+ {% # platformos-check-disable UnusedAssign %}
120
+ {% assign x = 1 %}
121
+ {% # platformos-check-enable UnusedAssign %}
122
+ ```
123
+
124
+ Disable multiple checks by including them as a comma-separated list:
125
+
126
+ ```liquid
127
+ {% # platformos-check-disable UnusedAssign,SpaceInsideBraces %}
128
+ {%assign x = 1%}
129
+ {% # platformos-check-enable UnusedAssign,SpaceInsideBraces %}
130
+ ```
131
+
132
+ Disable checks for the _entire document_ by placing the comment on the first line:
133
+
134
+ ```liquid
135
+ {% # platformos-check-disable SpaceInsideBraces %}
136
+ {%assign x = 1%}
137
+ ```
138
+
139
+ ## Exit Code and `--fail-level`
140
+
141
+ Use the `--fail-level` (default: `error`) flag to configure the exit code of platformos-check. Useful in CI scenarios.
142
+
143
+ Example:
144
+
145
+ ```
146
+ # Make CI fail on styles warnings, suggestions, and errors
147
+ platformos-check --fail-level style path_to_app
148
+
149
+ # Make CI fail on suggestions, and errors
150
+ platformos-check --fail-level suggestion path_to_app
151
+
152
+ # Make CI fail on errors
153
+ platformos-check path_to_app
154
+ ```
155
+
156
+ There are three fail levels:
157
+
158
+ - `error`
159
+ - `suggestion`
160
+ - `style`
161
+
162
+ Exit code meanings:
163
+
164
+ - 0: Success!
165
+ - 1: Your code doesn't pass the checks
166
+ - 2: There's a bug in platformos-check
167
+
168
+ If you would like to change the severity of a check, you can do so with the `severity` attribute. Example:
169
+
170
+ ```yaml
171
+ DeprecateLazysizes:
172
+ enabled: true
173
+ severity: error
174
+ ```
175
+
176
+ ## Language Server Configurations
177
+
178
+ - `platformosCheck.checkOnOpen` (default: `true`) makes it so theme check runs on file open.
179
+ - `platformosCheck.checkOnChange` (default: `true`) makes it so theme check runs on file change.
180
+ - `platformosCheck.checkOnSave` (default: `true`) makes it so theme check runs on file save.
181
+ - `platformosCheck.onlySingleFileChecks` (default: `false`) makes it so we only check the opened files and disable "whole theme" checks (e.g. UnusedPartial, TranslationKeyExists)
182
+
183
+ ⚠️ **Note:** Quickfixes only work on a freshly checked file. If any of those configurations are turned off, you will need to rerun platformos-check in order to apply quickfixes.
184
+
185
+ In VS Code, these can be set directly in your `settings.json`.
186
+
187
+ ## Contributing
188
+
189
+ For guidance on contributing, refer to this [doc](/CONTRIBUTING.md)
data/RELEASING.md ADDED
@@ -0,0 +1,35 @@
1
+ ## Releasing platformOS Check
2
+
3
+ 1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
+
5
+ 2. Run the following command to update the version in `lib/platformos_check/version.rb` and replace the `PLATFORMOS_CHECK_VERSION` placeholder in the documentation for new rules:
6
+
7
+ ```bash
8
+ VERSION="X.X.X"
9
+ rake prerelease[$VERSION]
10
+ ```
11
+
12
+ 3. Run [`git changelog`](https://github.com/tj/git-extras) to update `CHANGELOG.md`.
13
+
14
+ 4. Commit your changes and make a PR.
15
+
16
+ ```bash
17
+ git checkout -b "bump/platformos-check-$VERSION"
18
+ git add docs/checks CHANGELOG.md lib/platformos_check/version.rb
19
+ git commit -m "Bump platformos-check version to $VERSION"
20
+ hub compare "main:bump/platformos-check-$VERSION"
21
+ ```
22
+
23
+ 5. Merge your PR to main.
24
+
25
+ 6. [Create a GitHub release](https://github.com/Platform-OS/platformos-lsp/releases/new) for the change.
26
+
27
+ ```
28
+ VERSION=v1.X.Y
29
+ git fetch origin
30
+ git fetch origin --tags
31
+ git reset origin $VERSION
32
+ gh release create -t $VERSION
33
+ ```
34
+
35
+ (It's a good idea to copy parts of the CHANGELOG in there)
data/Rakefile ADDED
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/testtask"
4
+ require "rubocop/rake_task"
5
+ require "bundler/gem_tasks"
6
+
7
+ namespace :tests do
8
+ task all: %i[in_memory file_system]
9
+
10
+ Rake::TestTask.new(:suite) do |t|
11
+ t.libs << "test"
12
+ t.libs << "lib"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
+ end
15
+
16
+ desc("Runs the tests with InMemoryStorage")
17
+ task :in_memory do
18
+ ENV["THEME_STORAGE"] = 'InMemoryStorage'
19
+ puts "Running tests with #{ENV.fetch('THEME_STORAGE', nil)}"
20
+ Rake::Task['tests:suite'].execute
21
+ end
22
+
23
+ desc("Runs the tests with FileSystemStorage")
24
+ task :file_system do
25
+ ENV["THEME_STORAGE"] = 'FileSystemStorage'
26
+ puts "Running tests with #{ENV.fetch('THEME_STORAGE', nil)}"
27
+ Rake::Task['tests:suite'].execute
28
+ end
29
+ end
30
+
31
+ desc("Runs all tests")
32
+ task(test: 'tests:all')
33
+
34
+ RuboCop::RakeTask.new
35
+
36
+ task default: %i[test rubocop]
37
+
38
+ desc("Builds all distribution packages of the CLI")
39
+ task(package: 'package:all')
40
+
41
+ desc("Update files in the repo to match new version")
42
+ task :prerelease, [:version] do |_t, args|
43
+ require 'platformos_check/releaser'
44
+ PlatformosCheck::Releaser.new.release(args.version)
45
+ end
46
+
47
+ desc("Download theme-liquid-docs")
48
+ task :download_theme_liquid_docs do
49
+ require 'platformos_check/platformos_liquid/source_manager'
50
+
51
+ PlatformosCheck::PlatformosLiquid::SourceManager.download
52
+ end
53
+
54
+ desc "Create a new check"
55
+ task :new_check, [:name] do |_t, args|
56
+ require "platformos_check/string_helpers"
57
+ class_name = args.name
58
+ base_name = PlatformosCheck::StringHelpers.underscore(class_name)
59
+ code_source = "lib/platformos_check/checks/#{base_name}.rb"
60
+ doc_source = "docs/checks/#{base_name}.md"
61
+ test_source = "test/checks/#{base_name}_test.rb"
62
+ erb(
63
+ "lib/platformos_check/checks/TEMPLATE.rb.erb", code_source,
64
+ class_name:
65
+ )
66
+ erb(
67
+ "test/checks/TEMPLATE.rb.erb", test_source,
68
+ class_name:
69
+ )
70
+ erb(
71
+ "docs/checks/TEMPLATE.md.erb", doc_source,
72
+ class_name:,
73
+ code_source:,
74
+ doc_source:
75
+ )
76
+ sh "bundle exec ruby -Itest #{test_source}"
77
+ end
78
+
79
+ def erb(file, to, **args)
80
+ require "erb"
81
+ File.write(to, ERB.new(File.read(file)).result_with_hash(args))
82
+ puts "Generated #{to}"
83
+ end
@@ -0,0 +1,35 @@
1
+ # Troubleshooting
2
+
3
+ ## Issues with Language Server
4
+
5
+ ### Language server erroring out on startup
6
+
7
+ The following error can cause language server to crash:
8
+ ```bash
9
+ Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
10
+ /Users/johndoe/.gem/ruby/3.1.2/gems/bundler-2.2.22/lib/bundler/spec_set.rb:91:in `block in materialize': Could not find ruby-prof-0.18.0 in any of the sources (Bundler::GemNotFound)
11
+ ```
12
+
13
+ Confirm the version of platformos-check matches the version in the wrapper in `~/bin/platformos-check-language-server`. If it doesn't match the ruby version, run the following from the platformos-check directory:
14
+
15
+ ```bash
16
+ chruby 3.1.2 #your `~/bin/platformos-check-language-server` ruby version
17
+ bundle install
18
+ ```
19
+
20
+ ### Language server sends an `initialize()` request to the client and stops
21
+
22
+ To debug, confirm these steps are included in your local language server startup script:
23
+
24
+ ```bash
25
+ export PLATFORMOS_CHECK_DEBUG=true
26
+ export PLATFORMOS_CHECK_DEBUG_LOG_FILE="/tmp/platformos-check-debug.log"
27
+ touch "$PLATFORMOS_CHECK_DEBUG_LOG_FILE"
28
+ ```
29
+
30
+ An example script can be found [here](/CONTRIBUTING.md#run-language-server).
31
+
32
+ Open `/tmp/platformos-check-debug.log` in your IDE. Check if there are any exceptions being raised by language server.
33
+
34
+ If there are no exceptions, check if there are any logs that aren't in jsonrpc. The language server and client use stdin and stdout to communicate using jsonrpc. Debugging statements that aren't in a jsonrpc format might trigger unexpected behavior (this includes any logs from language server or echo statements in your language server script).
35
+
@@ -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 'platformos-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', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300).include?('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("platformos-check", "platformos-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 'platformos-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', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300).include?('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("platformos-check", "platformos-check-language-server")