theme-check 0.10.1 → 0.10.2

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: 56b6a91e5ac4b1e2045b1e4fb2748e5ecb9600206f9ba07df401c1410bf494fc
4
- data.tar.gz: b6fb1b3957ae5aecd7b2efbaa76a2e3c07390ec442f94d416ea5b20ca2cbf966
3
+ metadata.gz: dc5f5b1f71dce3de919836a4b8cd55e2ae3994e12c8118a69050840fac21b0e6
4
+ data.tar.gz: bc190dcdae4c5ec62b8d3e9a6d0a3d1c9ea6fc9b052e843455faf1ed1fc0d92d
5
5
  SHA512:
6
- metadata.gz: e2ca68b31968949dc52240c8ee5ca607e10e063b500cda0a7b06306589849f2bc0098f1b0742f962a91a0ca282aa504acb9f7c0de6b785afff0b577b84fa6eba
7
- data.tar.gz: c7186299a1168c5ad1e3cd6544ee8c8248b96a492e1dc82481c26a69e75fb1f04172ceb58da61e310a393fd36c9b990464542e7528810c7bea556b5b8ce9b61d
6
+ metadata.gz: 24724968d6b6f792e522289b3a62e200d5a2dc568286f8b5044a4b72253bfeb54aafae140dff38d2bfa9e5cb871d1f65c5c575661bb5b5132f73c36919e1b4f1
7
+ data.tar.gz: aaf053c7dbe25615daadaef936f58435e84180664b03b9f77edf7eee247581ef6b3ddadcf04816922e738db047693e1ca75a6e5bcfec139d42d2d3c0595fe49c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ v0.10.2 / 2021-06-18
3
+ ==================
4
+
5
+ * Fix error when parsing a template with lots of HTML attributes.
6
+ * Add `HtmlParsingError` check for reporting errors during HTML parsing.
7
+
2
8
  v0.10.1 / 2021-06-11
3
9
  ==================
4
10
 
data/Rakefile CHANGED
@@ -75,7 +75,7 @@ task :new_check, [:name] do |_t, args|
75
75
  code_source: code_source,
76
76
  doc_source: doc_source,
77
77
  )
78
- sh "bundle exec ruby -Itest test/checks/my_new_check_test.rb"
78
+ sh "bundle exec ruby -Itest #{test_source}"
79
79
  end
80
80
 
81
81
  def erb(file, to, **args)
data/config/default.yml CHANGED
@@ -141,3 +141,7 @@ ContentForHeaderModification:
141
141
  ImgLazyLoading:
142
142
  enabled: true
143
143
  ignore: []
144
+
145
+ HtmlParsingError:
146
+ enabled: true
147
+ ignore: []
@@ -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,12 @@
1
+ # frozen_string_literal: true
2
+ module ThemeCheck
3
+ class HtmlParsingError < HtmlCheck
4
+ severity :error
5
+ category :html
6
+ doc docs_url(__FILE__)
7
+
8
+ def on_parse_error(exception, template)
9
+ add_offense("HTML in this template can not be parsed: #{exception.message}", template: template)
10
+ end
11
+ end
12
+ end
@@ -13,12 +13,14 @@ module ThemeCheck
13
13
  def visit_template(template)
14
14
  doc = parse(template)
15
15
  visit(HtmlNode.new(doc, template))
16
+ rescue ArgumentError => e
17
+ call_checks(:on_parse_error, e, template)
16
18
  end
17
19
 
18
20
  private
19
21
 
20
22
  def parse(template)
21
- Nokogiri::HTML5.fragment(template.source)
23
+ Nokogiri::HTML5.fragment(template.source, max_tree_depth: 400, max_attributes: 400)
22
24
  end
23
25
 
24
26
  def visit(node)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ThemeCheck
3
- VERSION = "0.10.1"
3
+ VERSION = "0.10.2"
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.10.1
4
+ version: 0.10.2
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-11 00:00:00.000000000 Z
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -81,6 +81,7 @@ files:
81
81
  - docs/checks/convert_include_to_render.md
82
82
  - docs/checks/default_locale.md
83
83
  - docs/checks/deprecated_filter.md
84
+ - docs/checks/html_parsing_error.md
84
85
  - docs/checks/img_lazy_loading.md
85
86
  - docs/checks/img_width_and_height.md
86
87
  - docs/checks/liquid_tag.md
@@ -123,6 +124,7 @@ files:
123
124
  - lib/theme_check/checks/convert_include_to_render.rb
124
125
  - lib/theme_check/checks/default_locale.rb
125
126
  - lib/theme_check/checks/deprecated_filter.rb
127
+ - lib/theme_check/checks/html_parsing_error.rb
126
128
  - lib/theme_check/checks/img_lazy_loading.rb
127
129
  - lib/theme_check/checks/img_width_and_height.rb
128
130
  - lib/theme_check/checks/liquid_tag.rb