theme-check 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -0
  3. data/CONTRIBUTING.md +20 -91
  4. data/Rakefile +31 -0
  5. data/config/default.yml +31 -3
  6. data/data/shopify_liquid/objects.yml +2 -0
  7. data/docs/api/check.md +15 -0
  8. data/docs/api/html_check.md +46 -0
  9. data/docs/api/json_check.md +19 -0
  10. data/docs/api/liquid_check.md +99 -0
  11. data/docs/checks/{CHECK_DOCS_TEMPLATE.md → TEMPLATE.md.erb} +5 -5
  12. data/docs/checks/asset_size_css_stylesheet_tag.md +50 -0
  13. data/docs/checks/asset_url_filters.md +56 -0
  14. data/docs/checks/deprecate_bgsizes.md +66 -0
  15. data/docs/checks/deprecate_lazysizes.md +61 -0
  16. data/docs/checks/html_parsing_error.md +50 -0
  17. data/docs/checks/img_lazy_loading.md +61 -0
  18. data/docs/checks/liquid_tag.md +2 -2
  19. data/docs/checks/template_length.md +12 -2
  20. data/lib/theme_check/check.rb +1 -1
  21. data/lib/theme_check/checks/TEMPLATE.rb.erb +11 -0
  22. data/lib/theme_check/checks/asset_size_css.rb +11 -74
  23. data/lib/theme_check/checks/asset_size_css_stylesheet_tag.rb +24 -0
  24. data/lib/theme_check/checks/asset_size_javascript.rb +10 -36
  25. data/lib/theme_check/checks/asset_url_filters.rb +46 -0
  26. data/lib/theme_check/checks/deprecate_bgsizes.rb +14 -0
  27. data/lib/theme_check/checks/deprecate_lazysizes.rb +16 -0
  28. data/lib/theme_check/checks/html_parsing_error.rb +12 -0
  29. data/lib/theme_check/checks/img_lazy_loading.rb +20 -0
  30. data/lib/theme_check/checks/liquid_tag.rb +2 -2
  31. data/lib/theme_check/checks/remote_asset.rb +23 -79
  32. data/lib/theme_check/checks/template_length.rb +18 -4
  33. data/lib/theme_check/html_check.rb +2 -0
  34. data/lib/theme_check/html_node.rb +4 -0
  35. data/lib/theme_check/html_visitor.rb +5 -1
  36. data/lib/theme_check/json_file.rb +5 -0
  37. data/lib/theme_check/language_server/diagnostics_tracker.rb +2 -0
  38. data/lib/theme_check/liquid_check.rb +0 -11
  39. data/lib/theme_check/offense.rb +5 -5
  40. data/lib/theme_check/parsing_helpers.rb +3 -1
  41. data/lib/theme_check/regex_helpers.rb +17 -0
  42. data/lib/theme_check/tags.rb +37 -0
  43. data/lib/theme_check/template.rb +1 -0
  44. data/lib/theme_check/version.rb +1 -1
  45. metadata +21 -4
@@ -1,4 +1,4 @@
1
- # Check Title (`CheckClassName`)
1
+ # Check Title (`<%= class_name %>`)
2
2
 
3
3
  A brief paragraph explaining why the check exists.
4
4
 
@@ -21,7 +21,7 @@ This check is aimed at eliminating ...
21
21
  The default configuration for this check is the following:
22
22
 
23
23
  ```yaml
24
- CheckClassName:
24
+ <%= class_name %>:
25
25
  enabled: true
26
26
  some_option: 10
27
27
  ```
@@ -36,12 +36,12 @@ If you don't want to ..., then it's safe to disable this rule.
36
36
 
37
37
  ## Version
38
38
 
39
- This check has been introduced in Theme Check X.X.X.
39
+ This check has been introduced in Theme Check THEME_CHECK_VERSION.
40
40
 
41
41
  ## Resources
42
42
 
43
43
  - [Rule Source][codesource]
44
44
  - [Documentation Source][docsource]
45
45
 
46
- [codesource]: /lib/theme_check/checks/check_class_name.rb
47
- [docsource]: /docs/checks/check_class_name.md
46
+ [codesource]: /<%= code_source %>
47
+ [docsource]: /<%= doc_source %>
@@ -0,0 +1,50 @@
1
+ # Check Title (`AssetSizeCSSStylesheetTag`)
2
+
3
+ The `stylesheet_tag` filter generates a link tag that points to a given stylesheet. This rule exists to prevent large CSS bundles (for speed).
4
+
5
+ ## Check Details
6
+
7
+ This rule disallows the use of too much CSS in themes, as configured by `threshold_in_bytes`.
8
+
9
+ :-1: Examples of **incorrect** code for this check:
10
+ ```liquid
11
+ <!-- Here, assets/theme.css is **greater** than `threshold_in_bytes` compressed. -->
12
+ {{ 'theme.css' | asset_url | stylesheet_tag }}
13
+ ```
14
+
15
+ :+1: Example of **correct** code for this check:
16
+ ```liquid
17
+ <!-- Here, assets/theme.css is **less** than `threshold_in_bytes` compressed. -->
18
+ {{ 'theme.css' | asset_url | stylesheet_tag }}
19
+ ```
20
+
21
+ ## Check Options
22
+
23
+ The default configuration for this check is the following:
24
+
25
+ ```yaml
26
+ AssetSizeCSSStylesheetTag:
27
+ enabled: false
28
+ threshold_in_bytes: 100_000
29
+ ```
30
+
31
+ ### `threshold_in_bytes`
32
+
33
+ The `threshold_in_bytes` option (default: `100_000`) determines the maximum allowed compressed size in bytes that a single CSS file can take.
34
+
35
+ ## When Not To Use It
36
+
37
+ This rule is safe to disable.
38
+
39
+ ## Version
40
+
41
+ This check has been introduced in Theme Check 1.0.0
42
+
43
+ ## Resources
44
+
45
+ - [The Performance Inequality Gap](https://infrequently.org/2021/03/the-performance-inequality-gap/)
46
+ - [Rule Source][codesource]
47
+ - [Documentation Source][docsource]
48
+
49
+ [codesource]: /lib/theme_check/checks/asset_size_css_stylesheet_tag.rb
50
+ [docsource]: /docs/checks/asset_size_css_stylesheet_tag.md
@@ -0,0 +1,56 @@
1
+ # Ensure `asset_url` filters are used when serving assets (`AssetUrlFilters`)
2
+
3
+ See the [`RemoteAsset` check documentation][remote_asset] for a detailed explanation on why remote assets are discouraged.
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at eliminating unnecessary HTTP connections.
8
+
9
+ :-1: Examples of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+ <!-- Using multiple CDNs -->
13
+ {{ "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" | stylesheet_tag }}
14
+
15
+ <!-- Missing img_url filter -->
16
+ {{ url | img_tag }}
17
+ ```
18
+
19
+ :+1: Examples of **correct** code for this check:
20
+
21
+ ```liquid
22
+ {{ 'bootstrap.min.css' | asset_url | stylesheet_tag }}
23
+
24
+ <!-- Images -->
25
+ {{ url | img_url | img_tag }}
26
+ ```
27
+
28
+ Use the [`assets_url`](asset_url) or [`img_url`](img_url) filter to load the files in your theme's `assets/` folder from the Shopify CDN.
29
+
30
+ ## Check Options
31
+
32
+ The default configuration for this check is the following:
33
+
34
+ ```yaml
35
+ AssetUrlFilters:
36
+ enabled: true
37
+ ```
38
+
39
+ ## When Not To Use It
40
+
41
+ When the remote content is highly dynamic.
42
+
43
+ ## Version
44
+
45
+ This check has been introduced in Theme Check 0.9.1.
46
+
47
+ ## Resources
48
+
49
+ - [Rule Source][codesource]
50
+ - [Documentation Source][docsource]
51
+
52
+ [codesource]: /lib/theme_check/checks/remote_asset_filters.rb
53
+ [docsource]: /docs/checks/remote_asset_filters.md
54
+ [remote_asset]: /docs/checks/remote_asset.md
55
+ [asset_url]: https://shopify.dev/docs/themes/liquid/reference/filters/url-filters#assert_url
56
+ [img_url]: https://shopify.dev/docs/themes/liquid/reference/filters/url-filters#img_url
@@ -0,0 +1,66 @@
1
+ # Deprecate Bgsizes (`DeprecateBgsizes`)
2
+
3
+ The lazySizes bgset extension allows you to define multiple background images with a width descriptor. The extension will then load the best image size for the current viewport and device (https://github.com/aFarkas/lazysizes/tree/gh-pages/plugins/bgset)
4
+
5
+
6
+ ## Check Details
7
+
8
+ This check is aimed at discouraging the use of the lazySizes bgset plugin
9
+
10
+ :-1: Examples of **incorrect** code for this check:
11
+
12
+ ```liquid
13
+
14
+ <!-- Reports use of "lazyload" class and "data-bgset" attribute -->
15
+
16
+ <script src="ls.bgset.min.js"></script>
17
+ <script src="lazysizes.min.js"></script>
18
+ <div class="lazyload" data-bgset="image-200.jpg 200w, image-300.jpg 300w, image-400.jpg 400w" data-sizes="auto">
19
+ </div>
20
+
21
+ ```
22
+
23
+ :+1: Examples of **correct** code for this check:
24
+
25
+ ```liquid
26
+
27
+ <!-- Uses the CSS image-set() attribute instead of "data-bgset" -->
28
+ <!-- CSS Stylesheet -->
29
+ .box {
30
+ background-image: -webkit-image-set(
31
+ url("small-balloons.jpg") 1x,
32
+ url("large-balloons.jpg") 2x);
33
+ background-image: image-set(
34
+ url("small-balloons.jpg") 1x,
35
+ url("large-balloons.jpg") 2x);
36
+ }
37
+
38
+ <!-- HTML -->
39
+ <div class="box"></div>
40
+
41
+ ```
42
+
43
+ ## Check Options
44
+
45
+ The default configuration for this check is the following:
46
+
47
+ ```yaml
48
+ DeprecateBgsizes:
49
+ enabled: true
50
+ ```
51
+
52
+ ## When Not To Use It
53
+
54
+ You should disable this rule in older browsers that don't support the CSS image-set attribute.
55
+
56
+ ## Version
57
+
58
+ This check has been introduced in Theme Check 1.0.0.
59
+
60
+ ## Resources
61
+
62
+ - [Rule Source][codesource]
63
+ - [Documentation Source][docsource]
64
+
65
+ [codesource]: /lib/theme_check/checks/deprecate_bgsizes.rb
66
+ [docsource]: /docs/checks/deprecate_bgsizes.md
@@ -0,0 +1,61 @@
1
+ # Deprecate lazySizes (`DeprecateLazysizes`)
2
+
3
+ [lazysizes](https://github.com/aFarkas/lazysizes) is a common JavaScript library used to lazy load images, iframes and scripts.
4
+
5
+ ## Check Details
6
+
7
+ This check is aimed at discouraging the use of the lazysizes JavaScript library
8
+
9
+ :-1: Examples of **incorrect** code for this check:
10
+
11
+ ```liquid
12
+
13
+ <!-- Reports use of "lazyload" class -->
14
+ <img src="a.jpg" class="lazyload">
15
+
16
+ <!-- Reports use of "data-srcset" and "data-sizes" attribute. Reports data-sizes="auto" -->
17
+ <img
18
+ alt="House by the lake"
19
+ data-sizes="auto"
20
+ data-srcset="small.jpg 500w,
21
+ medium.jpg 640w,
22
+ big.jpg 1024w"
23
+ data-src="medium.jpg"
24
+ class="lazyload"
25
+ />
26
+
27
+ ```
28
+
29
+ :+1: Examples of **correct** code for this check:
30
+
31
+ ```liquid
32
+
33
+ <!-- Does not use lazySizes library. Instead uses native "loading" attribute -->
34
+ <img src="a.jpg" loading="lazy">
35
+
36
+ ```
37
+
38
+ ## Check Options
39
+
40
+ The default configuration for this check is the following:
41
+
42
+ ```yaml
43
+ DeprecateLazysizes:
44
+ enabled: true
45
+ ```
46
+
47
+ ## When Not To Use It
48
+
49
+ You should disable this rule if you want to support lazy loading of images in older browser that don't support the loading="lazy" attribute yet.
50
+
51
+ ## Version
52
+
53
+ This check has been introduced in Theme Check 1.0.0.
54
+
55
+ ## Resources
56
+
57
+ - [Rule Source][codesource]
58
+ - [Documentation Source][docsource]
59
+
60
+ [codesource]: /lib/theme_check/checks/deprecate_lazysizes.rb
61
+ [docsource]: /docs/checks/deprecate_lazysizes.md
@@ -0,0 +1,50 @@
1
+ # Report HTML parsing errors (`HtmlParsingError`)
2
+
3
+ Report errors preventing the HTML from being parsed and analyzed by Theme 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 Theme Check 0.10.2.
43
+
44
+ ## Resources
45
+
46
+ - [Rule Source][codesource]
47
+ - [Documentation Source][docsource]
48
+
49
+ [codesource]: /lib/theme_check/checks/html_parsing_error.rb
50
+ [docsource]: /docs/checks/html_parsing_error.md
@@ -0,0 +1,61 @@
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
+ ## Check Details
12
+
13
+ This check is aimed at defering loading non-critical images.
14
+
15
+ :-1: Examples of **incorrect** code for this check:
16
+
17
+ ```liquid
18
+ <img src="a.jpg">
19
+
20
+ <!-- Replaces lazysize.js -->
21
+ <img src="a.jpg" class="lazyload">
22
+
23
+ <!-- `auto` is deprecated -->
24
+ <img src="a.jpg" loading="auto">
25
+ ```
26
+
27
+ :+1: Examples of **correct** code for this check:
28
+
29
+ ```liquid
30
+ <img src="a.jpg" loading="lazy">
31
+
32
+ <!-- `eager` is also accepted, but prefer `lazy` -->
33
+ <img src="a.jpg" loading="eager">
34
+ ```
35
+
36
+ ## Check Options
37
+
38
+ The default configuration for this check is the following:
39
+
40
+ ```yaml
41
+ ImgLazyLoading:
42
+ enabled: true
43
+ ```
44
+
45
+ ## When Not To Use It
46
+
47
+ If you don't want to defer loading of images, then it's safe to disable this rule.
48
+
49
+ ## Version
50
+
51
+ This check has been introduced in Theme Check 0.10.0.
52
+
53
+ ## Resources
54
+
55
+ - [Rule Source][codesource]
56
+ - [Documentation Source][docsource]
57
+ - [MDN - Lazy loading][mdn]
58
+
59
+ [codesource]: /lib/theme_check/checks/img_lazy_loading.rb
60
+ [docsource]: /docs/checks/img_lazy_loading.md
61
+ [mdn]: https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading
@@ -39,12 +39,12 @@ The default configuration for this check is the following:
39
39
  ```yaml
40
40
  LiquidTag:
41
41
  enabled: true
42
- min_consecutive_statements: 4
42
+ min_consecutive_statements: 5
43
43
  ```
44
44
 
45
45
  ### `min_consecutive_statements`
46
46
 
47
- The `min_consecutive_statements` option (Default: `4`) determines the maximum (inclusive) number of consecutive statements before the check recommends a refactor.
47
+ The `min_consecutive_statements` option (Default: `5`) determines the maximum (inclusive) number of consecutive statements before the check recommends a refactor.
48
48
 
49
49
  ## When Not To Use It
50
50
 
@@ -21,8 +21,10 @@ The default configuration for this check is the following:
21
21
  ```yaml
22
22
  TemplateLength:
23
23
  enabled: true
24
- max_length: 200
24
+ max_length: 500
25
25
  exclude_schema: true
26
+ exclude_stylesheet: true
27
+ exclude_javascript: true
26
28
  ```
27
29
 
28
30
  ### `max_length`
@@ -31,7 +33,15 @@ The `max_length` (Default: `200`) option determines the maximum number of lines
31
33
 
32
34
  ### `exclude_schema`
33
35
 
34
- The `exclude_schema` (Default: `true`) option determines if the schema lines from a template should be excluded from the line count.
36
+ The `exclude_schema` (Default: `true`) option determines if the lines inside `{% schema %}` blocks from a template should be excluded from the line count.
37
+
38
+ ### `exclude_stylesheet`
39
+
40
+ The `exclude_stylesheet` (Default: `true`) option determines if the lines inside `{% stylesheet %}` blocks from a template should be excluded from the line count.
41
+
42
+ ### `exclude_javascript`
43
+
44
+ The `exclude_javascript` (Default: `true`) option determines if the lines inside `{% javascript %}` blocks from a template should be excluded from the line count.
35
45
 
36
46
  ## When Not To Use It
37
47
 
@@ -18,7 +18,6 @@ module ThemeCheck
18
18
  CATEGORIES = [
19
19
  :liquid,
20
20
  :translation,
21
- :performance,
22
21
  :html,
23
22
  :json,
24
23
  :performance,
@@ -124,6 +123,7 @@ module ThemeCheck
124
123
  def ==(other)
125
124
  other.is_a?(Check) && code_name == other.code_name
126
125
  end
126
+ alias_method :eql?, :==
127
127
 
128
128
  def to_s
129
129
  s = +"#{code_name}:\n"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module ThemeCheck
3
+ # TODO: inherit from HtmlCheck or JsonCheck if working on a non-Liquid check
4
+ class <%= class_name %> < LiquidCheck
5
+ severity :suggestion
6
+ category :liquid
7
+ doc docs_url(__FILE__)
8
+
9
+ # TODO: def on_<NODE_TYPE>
10
+ end
11
+ end