theme-check 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a114e025e51ad2a09395b4ae0dca33e9417942a76ed781fdd639e7d7d1b35928
4
- data.tar.gz: ff3c7f9b43f5ccae262cd22c8547d308a71e214cdd7f924208c25122624a48dc
3
+ metadata.gz: 2b606fffc2525680e6d47cf1d45b3fbdd514c79cf426dfd28baaec20e1cc083f
4
+ data.tar.gz: f0b9e3b0da8f41ae48e11d91ff1ccd780e0ed6cc5b8ba80694c3cd70a33e04a0
5
5
  SHA512:
6
- metadata.gz: 3e4ead0f1d63cc68dfbaff6dd5462f08b9008c04dd87fae9499875cf967e501c68327adec0ac3c1f253bbdbf1343d14ddeb63fe58b4c9f4cb24f494315898d70
7
- data.tar.gz: 62baa63bcf203d2bd0a7894787011f23d363cb6192920ac67c2ce0dfbe89f382c461a3d5a989c23234e5e1a9db7bfd9d10c4801bca121c1993a082b58887705d
6
+ metadata.gz: 23ce6e8b332e57cf523db93cf14ca9c948e569703633d5b82f106e95e66dd613ab30fa448226cf4f624b24da2675179220e7fc9fe206bfa9521f722c74356ba2
7
+ data.tar.gz: 22e2469eba1fc8aca4e881cfc5d0ad5ea7c16a057cdba6327310906099497b72d18dbef2d4f69d328528d6801f0abb91fac78a692f68387f7378d2c8fd3986dd
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ v0.10.0 / 2021-06-08
3
+ ==================
4
+
5
+ * Add ImgLazyLoading check for recommending loading="lazy" attribute
6
+
2
7
  v0.9.1 / 2021-06-04
3
8
  ==================
4
9
 
data/config/default.yml CHANGED
@@ -137,3 +137,7 @@ AssetUrlFilters:
137
137
  ContentForHeaderModification:
138
138
  enabled: true
139
139
  ignore: []
140
+
141
+ ImgLazyLoading:
142
+ enabled: true
143
+ ignore: []
@@ -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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module ThemeCheck
3
+ class ImgLazyLoading < HtmlCheck
4
+ severity :suggestion
5
+ categories :html, :performance
6
+ doc docs_url(__FILE__)
7
+
8
+ ACCEPTED_LOADING_VALUES = %w[lazy eager]
9
+
10
+ def on_img(node)
11
+ loading = node.attributes["loading"]&.value&.downcase
12
+ return if ACCEPTED_LOADING_VALUES.include?(loading)
13
+
14
+ class_list = node.attributes["class"]&.value&.split(" ")
15
+
16
+ if class_list&.include?("lazyload")
17
+ add_offense("Use the native loading=\"lazy\" attribute instead of lazysizes", node: node)
18
+ elsif loading == "auto"
19
+ add_offense("Prefer loading=\"lazy\" to defer loading of images", node: node)
20
+ else
21
+ add_offense("Add a loading=\"lazy\" attribute to defer loading of images", node: node)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ThemeCheck
3
- VERSION = "0.9.1"
3
+ VERSION = "0.10.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theme-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Cournoyer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-04 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -77,6 +77,7 @@ files:
77
77
  - docs/checks/convert_include_to_render.md
78
78
  - docs/checks/default_locale.md
79
79
  - docs/checks/deprecated_filter.md
80
+ - docs/checks/img_lazy_loading.md
80
81
  - docs/checks/img_width_and_height.md
81
82
  - docs/checks/liquid_tag.md
82
83
  - docs/checks/matching_schema_translations.md
@@ -117,6 +118,7 @@ files:
117
118
  - lib/theme_check/checks/convert_include_to_render.rb
118
119
  - lib/theme_check/checks/default_locale.rb
119
120
  - lib/theme_check/checks/deprecated_filter.rb
121
+ - lib/theme_check/checks/img_lazy_loading.rb
120
122
  - lib/theme_check/checks/img_width_and_height.rb
121
123
  - lib/theme_check/checks/liquid_tag.rb
122
124
  - lib/theme_check/checks/matching_schema_translations.rb