theme-check 0.7.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/theme-check.yml +4 -0
  3. data/.rubocop.yml +1 -1
  4. data/CHANGELOG.md +43 -0
  5. data/CONTRIBUTING.md +2 -1
  6. data/README.md +4 -1
  7. data/RELEASING.md +5 -3
  8. data/config/default.yml +38 -1
  9. data/data/shopify_liquid/tags.yml +3 -0
  10. data/data/shopify_translation_keys.yml +1 -0
  11. data/dev.yml +1 -1
  12. data/docs/checks/content_for_header_modification.md +42 -0
  13. data/docs/checks/nested_snippet.md +1 -1
  14. data/docs/checks/parser_blocking_script_tag.md +53 -0
  15. data/docs/checks/space_inside_braces.md +28 -0
  16. data/exe/theme-check-language-server +1 -2
  17. data/lib/theme_check.rb +13 -1
  18. data/lib/theme_check/analyzer.rb +79 -13
  19. data/lib/theme_check/bug.rb +20 -0
  20. data/lib/theme_check/check.rb +36 -7
  21. data/lib/theme_check/checks.rb +47 -8
  22. data/lib/theme_check/checks/content_for_header_modification.rb +41 -0
  23. data/lib/theme_check/checks/img_width_and_height.rb +18 -49
  24. data/lib/theme_check/checks/missing_enable_comment.rb +4 -4
  25. data/lib/theme_check/checks/missing_template.rb +1 -0
  26. data/lib/theme_check/checks/nested_snippet.rb +1 -1
  27. data/lib/theme_check/checks/parser_blocking_javascript.rb +6 -38
  28. data/lib/theme_check/checks/parser_blocking_script_tag.rb +20 -0
  29. data/lib/theme_check/checks/space_inside_braces.rb +8 -2
  30. data/lib/theme_check/checks/template_length.rb +3 -0
  31. data/lib/theme_check/checks/valid_html_translation.rb +1 -0
  32. data/lib/theme_check/cli.rb +1 -1
  33. data/lib/theme_check/config.rb +8 -2
  34. data/lib/theme_check/disabled_check.rb +41 -0
  35. data/lib/theme_check/disabled_checks.rb +33 -29
  36. data/lib/theme_check/exceptions.rb +32 -0
  37. data/lib/theme_check/html_check.rb +7 -0
  38. data/lib/theme_check/html_node.rb +52 -0
  39. data/lib/theme_check/html_visitor.rb +36 -0
  40. data/lib/theme_check/json_file.rb +13 -1
  41. data/lib/theme_check/language_server.rb +2 -1
  42. data/lib/theme_check/language_server/completion_engine.rb +1 -1
  43. data/lib/theme_check/language_server/completion_providers/filter_completion_provider.rb +1 -0
  44. data/lib/theme_check/language_server/completion_providers/object_completion_provider.rb +10 -8
  45. data/lib/theme_check/language_server/constants.rb +5 -1
  46. data/lib/theme_check/language_server/diagnostics_tracker.rb +64 -0
  47. data/lib/theme_check/language_server/document_link_engine.rb +2 -2
  48. data/lib/theme_check/language_server/handler.rb +63 -50
  49. data/lib/theme_check/language_server/server.rb +1 -1
  50. data/lib/theme_check/language_server/variable_lookup_finder.rb +295 -0
  51. data/lib/theme_check/liquid_check.rb +0 -4
  52. data/lib/theme_check/node.rb +12 -0
  53. data/lib/theme_check/offense.rb +30 -46
  54. data/lib/theme_check/parsing_helpers.rb +1 -1
  55. data/lib/theme_check/position.rb +77 -0
  56. data/lib/theme_check/position_helper.rb +37 -0
  57. data/lib/theme_check/remote_asset_file.rb +3 -0
  58. data/lib/theme_check/shopify_liquid/tag.rb +13 -0
  59. data/lib/theme_check/template.rb +8 -0
  60. data/lib/theme_check/theme.rb +7 -2
  61. data/lib/theme_check/version.rb +1 -1
  62. data/lib/theme_check/visitor.rb +4 -14
  63. data/theme-check.gemspec +2 -0
  64. metadata +18 -5
  65. data/lib/theme_check/language_server/position_helper.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c3c0a379dbaa7c43b75d62954952d88a57af1ba6ba028cb30a73803a45fc274
4
- data.tar.gz: eef366fdb4f66ec0bf33c1d405e405ea757159295a11bac02ea6c8086e9d5342
3
+ metadata.gz: e5970832846bda5a0e7cb27c99ebef32382050c911350d1d208211849bef7d55
4
+ data.tar.gz: 89d3bb2d5a261c817dddfbf50ad9ac31a589f88fe4f2a2df23b8c5aaad51c4db
5
5
  SHA512:
6
- metadata.gz: ae494f6e081c0ed351d5511c2990503933b50d2b5749fd33f948770d3ffbb46fb7274b91c164731953e2d3566201b38ed09b352c02ec81091081a70c9697b4b3
7
- data.tar.gz: 4ecd1ecbc3f035a60c837deb46c8174043a35cc11118fc28f70c30369c8d99d555b4432da1cd3faa662d49773457eb8f3dfad97439a5d2fcce58d45922189ec4
6
+ metadata.gz: 2ee4f610dc461c6e70e870723f801ddb0f1e5381eebfc6622030af68486c2c6650c11e530be38456cf0df8666ecc5e78b26d16cf60428142e04f0ebde45edf9f
7
+ data.tar.gz: 36053d9337a817da4334a5341be1877f04d86b3f4d88606a2acccb2028c0a3a07227086183de5aa06bd44e9beeebd0a4650d08b746fdfbced854e945469d61a3
@@ -15,6 +15,7 @@ jobs:
15
15
  version:
16
16
  - 3.0.0
17
17
  - 2.7.1
18
+ - 2.6.6
18
19
 
19
20
  name: Ruby ${{ matrix.version }}
20
21
 
@@ -33,3 +34,6 @@ jobs:
33
34
  run: bundle install --jobs=3 --retry=3 --path=vendor/bundle
34
35
  - name: Run tests
35
36
  run: bundle exec rake
37
+ - name: Test runtime
38
+ # Testing that runtime can execute, not testing the results themselves
39
+ run: bundle exec theme-check ./test/theme | grep -q "files inspected"
data/.rubocop.yml CHANGED
@@ -7,7 +7,7 @@ require:
7
7
  - rubocop-rake
8
8
 
9
9
  AllCops:
10
- TargetRubyVersion: 2.7
10
+ TargetRubyVersion: 2.6
11
11
  Exclude:
12
12
  - 'vendor/bundle/**/*'
13
13
  - 'packaging/builds/**/*'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,47 @@
1
1
 
2
+ v0.9.0 / 2021-05-28
3
+ ==================
4
+
5
+ * Introduce HtmlCheck, and convert ParserBlockingJavaScript & ImgWidthAndHeight to it
6
+ * Move `script-tag` validation from ParserBlockingJavaScript to ParserBlockingScriptTag
7
+ * Add ability to ignore individual checks using file patterns
8
+ * Introduce single file and whole theme checks to optimize LSP diagnostics
9
+ * Fix TemplateLength counter not being reseted on each document
10
+ * Add missing category to ValidHTMLTranslation
11
+ * Set Ruby default encodings to UTF-8 to fix encoding issues
12
+ * Add ContentForHeaderModification check to prevent relying on the content of ``content_for_header`
13
+ * Fix `Content-Length` in LSP responses
14
+ * Fix disabling checks that emit offences in `on_end`
15
+ * Fix completion bug in `filter_completion_provider`
16
+
17
+ v0.8.3 / 2021-05-17
18
+ ==================
19
+
20
+ * Making sure VERSION is set before referencing it
21
+
22
+ v0.8.2 / 2021-05-14
23
+ ===================
24
+
25
+ * Bump NestedSnippet max_nesting_level to 3
26
+ * Add a message to help debug errors, and timeout checks after 5 sec
27
+ * Object Completions Everywhere!
28
+ * Include operators to space inside braces check
29
+
30
+ 0.8.1 / 2021-04-22
31
+ ==================
32
+
33
+ * Add consistent spacing around the pipe character (`|`) in variable expressions to the `SpaceInsideBrace` check ([#73](https://github.com/shopify/theme-check/issues/73))
34
+ * Add ReCaptcha system translation ([#265](https://github.com/shopify/theme-check/issues/265))
35
+ * Fix document links in `{% liquid %}` tags ([#263](https://github.com/shopify/theme-check/issues/263))
36
+ * Fix theme-check-disable for checks based on regular expressions ([#242](https://github.com/shopify/theme-check/issues/242))
37
+ * Fix VS Code crash on new window ([#264](https://github.com/shopify/theme-check/issues/264))
38
+ * Rescue errors thrown by remote_asset_file
39
+
40
+ 0.8.0 / 2021-04-13
41
+ ==================
42
+
43
+ * Set minimal Ruby version to 2.6
44
+
2
45
  0.7.3 / 2021-04-13
3
46
  ==================
4
47
 
data/CONTRIBUTING.md CHANGED
@@ -41,7 +41,8 @@ Under `lib/theme_check/checks`, create new Ruby file with a unique name describi
41
41
  ```ruby
42
42
  module ThemeCheck
43
43
  # Does one thing, and does it well!
44
- # NOTE: inherit from JsonCheck to implement a JSON based check.
44
+ # NOTE: inherit from `JsonCheck` to implement a JSON-based check, and from `HtmlCheck`
45
+ # to implement an HTML-based one. See other checks in `lib/theme_check/checks` for examples.
45
46
  class MyCheckName < LiquidCheck
46
47
  severity :suggestion # :error or :style
47
48
 
data/README.md CHANGED
@@ -92,11 +92,14 @@ root: dist
92
92
  require:
93
93
  - ./path/to/my_custom_check.rb
94
94
 
95
- # Disable some checks
96
95
  TemplateLength:
96
+ # Disable some checks
97
97
  enabled: false
98
98
  # Or configure options
99
99
  max_length: 300
100
+ # Or ignore certain paths
101
+ ignore:
102
+ - snippets/icon-*
100
103
 
101
104
  # Enable a custom check
102
105
  MyCustomCheck
data/RELEASING.md CHANGED
@@ -9,11 +9,13 @@
9
9
  rake prerelease[$VERSION]
10
10
  ```
11
11
 
12
- 3. Commit your changes and make a PR.
12
+ 3. Run [`git changelog`](https://github.com/tj/git-extras) to update `CHANGELOG.md`.
13
13
 
14
- 4. Merge your PR to master.
14
+ 4. Commit your changes and make a PR.
15
15
 
16
- 5. On [Shipit](https://shipit.shopify.io/shopify/theme-check/rubygems), deploy your commit.
16
+ 5. Merge your PR to master.
17
+
18
+ 6. On [Shipit](https://shipit.shopify.io/shopify/theme-check/rubygems), deploy your commit.
17
19
 
18
20
  ## Homebrew Release Process
19
21
 
data/config/default.yml CHANGED
@@ -7,92 +7,129 @@ ignore:
7
7
 
8
8
  ConvertIncludeToRender:
9
9
  enabled: true
10
+ ignore: []
10
11
 
11
12
  LiquidTag:
12
13
  enabled: true
14
+ ignore: []
13
15
  min_consecutive_statements: 4
14
16
 
15
17
  MissingTemplate:
16
18
  enabled: true
19
+ ignore: []
17
20
 
18
21
  NestedSnippet:
19
22
  enabled: true
20
- max_nesting_level: 2
23
+ ignore: []
24
+ max_nesting_level: 3
21
25
 
22
26
  RequiredLayoutThemeObject:
23
27
  enabled: true
28
+ ignore: []
24
29
 
25
30
  SpaceInsideBraces:
26
31
  enabled: true
32
+ ignore: []
27
33
 
28
34
  SyntaxError:
29
35
  enabled: true
36
+ ignore: []
30
37
 
31
38
  TemplateLength:
32
39
  enabled: true
40
+ ignore: []
33
41
  max_length: 200
34
42
  # Exclude content of {% schema %} in line count
35
43
  exclude_schema: true
36
44
 
37
45
  UnknownFilter:
38
46
  enabled: true
47
+ ignore: []
39
48
 
40
49
  UnusedAssign:
41
50
  enabled: true
51
+ ignore: []
42
52
 
43
53
  UnusedSnippet:
44
54
  enabled: true
55
+ ignore: []
45
56
 
46
57
  MatchingSchemaTranslations:
47
58
  enabled: true
59
+ ignore: []
48
60
 
49
61
  MatchingTranslations:
50
62
  enabled: true
63
+ ignore: []
51
64
 
52
65
  DefaultLocale:
53
66
  enabled: true
67
+ ignore: []
54
68
 
55
69
  TranslationKeyExists:
56
70
  enabled: true
71
+ ignore: []
57
72
 
58
73
  ValidHTMLTranslation:
59
74
  enabled: true
75
+ ignore: []
60
76
 
61
77
  ValidJson:
62
78
  enabled: true
79
+ ignore: []
63
80
 
64
81
  ValidSchema:
65
82
  enabled: true
83
+ ignore: []
66
84
 
67
85
  MissingRequiredTemplateFiles:
68
86
  enabled: true
87
+ ignore: []
69
88
 
70
89
  UndefinedObject:
71
90
  enabled: true
91
+ ignore: []
72
92
  exclude_snippets: true
73
93
 
74
94
  RequiredDirectories:
75
95
  enabled: true
96
+ ignore: []
76
97
 
77
98
  DeprecatedFilter:
78
99
  enabled: true
100
+ ignore: []
79
101
 
80
102
  MissingEnableComment:
81
103
  enabled: true
104
+ ignore: []
82
105
 
83
106
  ParserBlockingJavaScript:
84
107
  enabled: true
108
+ ignore: []
109
+
110
+ ParserBlockingScriptTag:
111
+ enabled: true
85
112
 
86
113
  AssetSizeJavaScript:
87
114
  enabled: false
115
+ ignore: []
88
116
  threshold_in_bytes: 10_000
117
+ ignore: []
89
118
 
90
119
  AssetSizeCSS:
91
120
  enabled: false
121
+ ignore: []
92
122
  threshold_in_bytes: 100_000
123
+ ignore: []
93
124
 
94
125
  ImgWidthAndHeight:
95
126
  enabled: true
127
+ ignore: []
96
128
 
97
129
  RemoteAsset:
98
130
  enabled: true
131
+ ignore: []
132
+
133
+ ContentForHeaderModification:
134
+ enabled: true
135
+ ignore: []
@@ -8,6 +8,8 @@
8
8
  - cycle
9
9
  - decrement
10
10
  - echo
11
+ - else
12
+ - elsif
11
13
  - for
12
14
  - form
13
15
  - if
@@ -25,3 +27,4 @@
25
27
  - stylesheet
26
28
  - tablerow
27
29
  - unless
30
+ - when
@@ -848,3 +848,4 @@
848
848
  - shopify.store_availability.pick_up_time.two_to_four_hours
849
849
  - shopify.store_availability.pick_up_time.immediately
850
850
  - shopify.store_availability.pick_up_time.next_day
851
+ - shopify.online_store.spam_detection.disclaimer_html
data/dev.yml CHANGED
@@ -3,7 +3,7 @@ name: theme-check
3
3
  type: ruby
4
4
 
5
5
  up:
6
- - ruby: 2.7.1
6
+ - ruby: 2.6.6
7
7
  - bundler
8
8
 
9
9
  commands:
@@ -0,0 +1,42 @@
1
+ # Do not depend on the content of `content_for_header` (`ContentForHeaderModification`)
2
+
3
+ Do not rely on the content of `content_for_header` as it might change in the future, which could cause your Liquid code behavior to change.
4
+
5
+ ## Check Details
6
+
7
+ :-1: Examples of **incorrect** code for this check:
8
+
9
+ ```liquid
10
+ {% assign parts = content_for_header | split: ',' %}
11
+ ```
12
+
13
+ :+1: Examples of **correct** code for this check:
14
+
15
+ The only acceptable usage of `content_for_header` is:
16
+
17
+ ```liquid
18
+ {{ content_for_header }}
19
+ ```
20
+
21
+ ## Check Options
22
+
23
+ The default configuration for this check is the following:
24
+
25
+ ```yaml
26
+ ContentForHeaderModification:
27
+ enabled: true
28
+ ```
29
+
30
+ ## Version
31
+
32
+ This check has been introduced in Theme Check 0.9.0.
33
+
34
+ ## Resources
35
+
36
+ - [Rule Source][codesource]
37
+ - [Documentation Source][docsource]
38
+ - [`theme.liquid` template considerations][considerations]
39
+
40
+ [codesource]: /lib/theme_check/checks/check_class_name.rb
41
+ [docsource]: /docs/checks/check_class_name.md
42
+ [considerations]: https://shopify.dev/docs/themes/theme-templates/theme-liquid#template-considerations
@@ -45,7 +45,7 @@ The default configuration for this check is the following:
45
45
  ```yaml
46
46
  NestedSnippet:
47
47
  enabled: true
48
- max_nesting_level: 2
48
+ max_nesting_level: 3
49
49
  ```
50
50
 
51
51
  ### `max_nesting_level`
@@ -0,0 +1,53 @@
1
+ # Discourage use of parser-blocking `script_tag` filter (`ParserBlockingScriptTag`)
2
+
3
+ The `script_tag` filter emits a parser-blocking script tag.
4
+
5
+ See the [ParserBlockingJavaScript check documentation][parser_blocking_javascript] for why this is generally discouraged.
6
+
7
+ ## Check Details
8
+
9
+ This check is aimed at eliminating parser-blocking JavaScript on themes.
10
+
11
+ :-1: Examples of **incorrect** code for this check:
12
+
13
+ ```liquid
14
+ <!-- The script_tag filter outputs a parser-blocking script -->
15
+ {{ 'app-code.js' | asset_url | script_tag }}
16
+ ```
17
+
18
+ :+1: Examples of **correct** code for this check:
19
+
20
+ ```liquid
21
+ <!-- Good. Using the asset_url filter + defer -->
22
+ <script src="{{ 'theme.js' | asset_url }}" defer></script>
23
+
24
+ <!-- Also good. Using the asset_url filter + async -->
25
+ <script src="{{ 'theme.js' | asset_url }}" async></script>
26
+ ```
27
+
28
+ ## Check Options
29
+
30
+ The default configuration for this check is the following:
31
+
32
+ ```yaml
33
+ ParserBlockingScriptTag:
34
+ enabled: true
35
+ ```
36
+
37
+ ## When Not To Use It
38
+
39
+ This should only be turned off with the `theme-check-disable` comment when there's no better way to accomplish what you're doing than with a parser-blocking script.
40
+
41
+ It is discouraged to turn this rule off.
42
+
43
+ ## Version
44
+
45
+ This check has been introduced in Theme Check 0.9.0.
46
+
47
+ ## Resources
48
+
49
+ - [ParserBlockingJavaScript check][parser_blocking_javascript]
50
+ - [Documentation Source][docsource]
51
+
52
+ [parser_blocking_javascript]: /docs/checks/parser_blocking_javascript.md
53
+ [docsource]: /docs/checks/parser_blocking_script_tag.md
@@ -17,6 +17,14 @@ This check is aimed at eliminating ugly Liquid:
17
17
  <!-- After commas and semicolons -->
18
18
  {% form 'type', object, key:value %}
19
19
  {% endform %}
20
+
21
+ <!-- Arround filter pipelines -->
22
+ {{ url | asset_url | img_tag }}
23
+ {% assign my_upcase_string = "Hello world"| upcase %}
24
+
25
+ <!-- Arround symbol operators -->
26
+ {%- if target == product and product.price_varies -%}
27
+ {%- if product.featured_media.width >=165 -%}
20
28
  ```
21
29
 
22
30
  :+1: Examples of **correct** code for this check:
@@ -33,6 +41,10 @@ This check is aimed at eliminating ugly Liquid:
33
41
  media_size: section.settings.product_recommendations_image_ratio,
34
42
  center_align_text: section.settings.center_align_text
35
43
  %}
44
+ {{ url | asset_url | img_tag }}
45
+ {% assign my_upcase_string = "Hello world" | upcase %}
46
+ {%- if target == product and product.price_varies -%}
47
+ {%- if product.featured_media.width >= 165 -%}
36
48
  ```
37
49
 
38
50
  ## Check Options
@@ -44,6 +56,22 @@ SpaceInsideBraces:
44
56
  enabled: true
45
57
  ```
46
58
 
59
+ ## Auto-correction
60
+
61
+ This check can automatically trim or add spaces around `{{ ... }}`.
62
+
63
+ ```liquid
64
+ {{ x}}
65
+ {{x}}
66
+ {{ x }}
67
+ ```
68
+
69
+ Can all be auto-corrected with the `--auto-correct` option to:
70
+
71
+ ```liquid
72
+ {{ x }}
73
+ ```
74
+
47
75
  ## When Not To Use It
48
76
 
49
77
  If you don't care about the look of your code.