herb 0.8.4-x86-linux-musl → 0.8.5-x86-linux-musl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e81cc9549293698d196da56a12f587e7bc39f45bd38ebd982f99879b9656203e
4
- data.tar.gz: 8e4840ebc3be008c1ed2dc296a7f8628a70566cff3a80c8b6067d1300f9d21ca
3
+ metadata.gz: 9b2e36c455f391dd9d3fb27e5ed6fb271a32f3d439a244dcb541b5bc3ff16d55
4
+ data.tar.gz: 0b1ef871b453c91a0afc6f3a413753e2dde36aaf48dd997b517cfae3b5eff75a
5
5
  SHA512:
6
- metadata.gz: df0a528c96e2d630a0c76909c6f76d9973a7f14523030cc98da5087b07649d680f7d394b6c6602acf3593a714f9315070efca87cd09652b1f6bc48ff4883b983
7
- data.tar.gz: 7efd8bf46bd3c9d8afbb02524053af57a5bc8894b12d8a583a5f8c5da120dce2c847de6a382ba53439c97844c141fa179d868907b70268f91fd025198823899e
6
+ metadata.gz: 772670f1ffb014eb8c52bfd631e01ea051013d8ced2507d2d93f1f44065afc7067b1eac6fefe4ad08906cd3a0f5641186ec471cb79a720961c2f8f8d21e44ca7
7
+ data.tar.gz: 4064f106fd4d231fcb8cbdff4b2e848721bb30a957b16c9d06b10a151e3fd487e3f970ea255eec8ec4d2463fe2edd2b6e9a8ab2a17ba421396ed0d61a3a75db3
data/config.yml CHANGED
@@ -171,6 +171,13 @@ errors:
171
171
  - name: keyword
172
172
  type: string
173
173
 
174
+ - name: ERBMultipleBlocksInTagError
175
+ message:
176
+ template: "Multiple unclosed control flow blocks in a single ERB tag. Split each block into its own ERB tag, or close all blocks within the same tag."
177
+ arguments: []
178
+
179
+ fields: []
180
+
174
181
  warnings:
175
182
  fields: []
176
183
  types: []
@@ -317,6 +317,30 @@ static VALUE rb_missingerb_end_tag_error_from_c_struct(MISSINGERB_END_TAG_ERROR_
317
317
  return rb_class_new_instance(4, args, MissingERBEndTagError);
318
318
  };
319
319
 
320
+ static VALUE rb_erb_multiple_blocks_in_tag_error_from_c_struct(ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error) {
321
+ if (erb_multiple_blocks_in_tag_error == NULL) { return Qnil; }
322
+
323
+ ERROR_T* error = &erb_multiple_blocks_in_tag_error->base;
324
+
325
+ VALUE Herb = rb_define_module("Herb");
326
+ VALUE Errors = rb_define_module_under(Herb, "Errors");
327
+ VALUE Error = rb_define_class_under(Errors, "Error", rb_cObject);
328
+ VALUE ERBMultipleBlocksInTagError = rb_define_class_under(Errors, "ERBMultipleBlocksInTagError", Error);
329
+
330
+ VALUE type = rb_utf8_str_new_cstr(error_type_to_string(error));
331
+ VALUE location = rb_location_from_c_struct(error->location);
332
+ VALUE message = rb_utf8_str_new_cstr(error->message);
333
+
334
+
335
+ VALUE args[3] = {
336
+ type,
337
+ location,
338
+ message
339
+ };
340
+
341
+ return rb_class_new_instance(3, args, ERBMultipleBlocksInTagError);
342
+ };
343
+
320
344
 
321
345
  VALUE rb_error_from_c_struct(ERROR_T* error) {
322
346
  if (!error) { return Qnil; }
@@ -333,6 +357,7 @@ VALUE rb_error_from_c_struct(ERROR_T* error) {
333
357
  case RUBY_PARSE_ERROR: return rb_ruby_parse_error_from_c_struct((RUBY_PARSE_ERROR_T*) error); break;
334
358
  case ERB_CONTROL_FLOW_SCOPE_ERROR: return rb_erb_control_flow_scope_error_from_c_struct((ERB_CONTROL_FLOW_SCOPE_ERROR_T*) error); break;
335
359
  case MISSINGERB_END_TAG_ERROR: return rb_missingerb_end_tag_error_from_c_struct((MISSINGERB_END_TAG_ERROR_T*) error); break;
360
+ case ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR: return rb_erb_multiple_blocks_in_tag_error_from_c_struct((ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T*) error); break;
336
361
  }
337
362
 
338
363
  return Qnil;
data/ext/herb/nodes.c CHANGED
@@ -464,7 +464,7 @@ static VALUE rb_erb_content_node_from_c_struct(AST_ERB_CONTENT_NODE_T* erb_conte
464
464
  VALUE erb_content_node_tag_opening = rb_token_from_c_struct(erb_content_node->tag_opening);
465
465
  VALUE erb_content_node_content = rb_token_from_c_struct(erb_content_node->content);
466
466
  VALUE erb_content_node_tag_closing = rb_token_from_c_struct(erb_content_node->tag_closing);
467
- /* #<Herb::Template::AnalyzedRubyField:0x00007f7e38cc7d98 @name="analyzed_ruby", @options={kind: nil}> */
467
+ /* #<Herb::Template::AnalyzedRubyField:0x00007fc18e49ea10 @name="analyzed_ruby", @options={kind: nil}> */
468
468
  VALUE erb_content_node_analyzed_ruby = Qnil;
469
469
  VALUE erb_content_node_parsed = (erb_content_node->parsed) ? Qtrue : Qfalse;
470
470
  VALUE erb_content_node_valid = (erb_content_node->valid) ? Qtrue : Qfalse;
data/lib/herb/3.0/herb.so CHANGED
Binary file
data/lib/herb/3.1/herb.so CHANGED
Binary file
data/lib/herb/3.2/herb.so CHANGED
Binary file
data/lib/herb/3.3/herb.so CHANGED
Binary file
data/lib/herb/3.4/herb.so CHANGED
Binary file
@@ -17,6 +17,11 @@ module Herb
17
17
  opening.start_with?("<%#")
18
18
  end
19
19
 
20
+ #: (String) -> bool
21
+ def erb_graphql?(opening)
22
+ opening.start_with?("<%graphql")
23
+ end
24
+
20
25
  #: (String) -> bool
21
26
  def erb_output?(opening)
22
27
  opening.include?("=")
@@ -319,6 +319,7 @@ module Herb
319
319
  opening = node.tag_opening.value
320
320
 
321
321
  return if !skip_comment_check && erb_comment?(opening)
322
+ return if erb_graphql?(opening)
322
323
 
323
324
  code = node.content.value.strip
324
325
 
data/lib/herb/errors.rb CHANGED
@@ -58,7 +58,6 @@ module Herb
58
58
  #: (String, Location, String, String, String, String) -> void
59
59
  def initialize(type, location, message, description, expected, found)
60
60
  super(type, location, message)
61
-
62
61
  @description = description
63
62
  @expected = expected
64
63
  @found = found
@@ -71,11 +70,11 @@ module Herb
71
70
 
72
71
  #: () -> serialized_unexpected_error
73
72
  def to_hash
74
- super.merge({
73
+ super.merge(
75
74
  description: description,
76
75
  expected: expected,
77
- found: found,
78
- }) #: Herb::serialized_unexpected_error
76
+ found: found
77
+ ) #: Herb::serialized_unexpected_error
79
78
  end
80
79
 
81
80
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -102,7 +101,6 @@ module Herb
102
101
  #: (String, Location, String, String, Herb::Token) -> void
103
102
  def initialize(type, location, message, expected_type, found)
104
103
  super(type, location, message)
105
-
106
104
  @expected_type = expected_type
107
105
  @found = found
108
106
  end
@@ -114,10 +112,10 @@ module Herb
114
112
 
115
113
  #: () -> serialized_unexpected_token_error
116
114
  def to_hash
117
- super.merge({
115
+ super.merge(
118
116
  expected_type: expected_type,
119
- found: found,
120
- }) #: Herb::serialized_unexpected_token_error
117
+ found: found
118
+ ) #: Herb::serialized_unexpected_token_error
121
119
  end
122
120
 
123
121
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -144,7 +142,6 @@ module Herb
144
142
  #: (String, Location, String, Herb::Token) -> void
145
143
  def initialize(type, location, message, closing_tag)
146
144
  super(type, location, message)
147
-
148
145
  @closing_tag = closing_tag
149
146
  end
150
147
 
@@ -155,9 +152,9 @@ module Herb
155
152
 
156
153
  #: () -> serialized_missing_opening_tag_error
157
154
  def to_hash
158
- super.merge({
159
- closing_tag: closing_tag,
160
- }) #: Herb::serialized_missing_opening_tag_error
155
+ super.merge(
156
+ closing_tag: closing_tag
157
+ ) #: Herb::serialized_missing_opening_tag_error
161
158
  end
162
159
 
163
160
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -183,7 +180,6 @@ module Herb
183
180
  #: (String, Location, String, Herb::Token) -> void
184
181
  def initialize(type, location, message, opening_tag)
185
182
  super(type, location, message)
186
-
187
183
  @opening_tag = opening_tag
188
184
  end
189
185
 
@@ -194,9 +190,9 @@ module Herb
194
190
 
195
191
  #: () -> serialized_missing_closing_tag_error
196
192
  def to_hash
197
- super.merge({
198
- opening_tag: opening_tag,
199
- }) #: Herb::serialized_missing_closing_tag_error
193
+ super.merge(
194
+ opening_tag: opening_tag
195
+ ) #: Herb::serialized_missing_closing_tag_error
200
196
  end
201
197
 
202
198
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -223,7 +219,6 @@ module Herb
223
219
  #: (String, Location, String, Herb::Token, Herb::Token) -> void
224
220
  def initialize(type, location, message, opening_tag, closing_tag)
225
221
  super(type, location, message)
226
-
227
222
  @opening_tag = opening_tag
228
223
  @closing_tag = closing_tag
229
224
  end
@@ -235,10 +230,10 @@ module Herb
235
230
 
236
231
  #: () -> serialized_tag_names_mismatch_error
237
232
  def to_hash
238
- super.merge({
233
+ super.merge(
239
234
  opening_tag: opening_tag,
240
- closing_tag: closing_tag,
241
- }) #: Herb::serialized_tag_names_mismatch_error
235
+ closing_tag: closing_tag
236
+ ) #: Herb::serialized_tag_names_mismatch_error
242
237
  end
243
238
 
244
239
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -268,7 +263,6 @@ module Herb
268
263
  #: (String, Location, String, Herb::Token, Herb::Token) -> void
269
264
  def initialize(type, location, message, opening_quote, closing_quote)
270
265
  super(type, location, message)
271
-
272
266
  @opening_quote = opening_quote
273
267
  @closing_quote = closing_quote
274
268
  end
@@ -280,10 +274,10 @@ module Herb
280
274
 
281
275
  #: () -> serialized_quotes_mismatch_error
282
276
  def to_hash
283
- super.merge({
277
+ super.merge(
284
278
  opening_quote: opening_quote,
285
- closing_quote: closing_quote,
286
- }) #: Herb::serialized_quotes_mismatch_error
279
+ closing_quote: closing_quote
280
+ ) #: Herb::serialized_quotes_mismatch_error
287
281
  end
288
282
 
289
283
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -314,7 +308,6 @@ module Herb
314
308
  #: (String, Location, String, Herb::Token, String, String) -> void
315
309
  def initialize(type, location, message, tag_name, expected, found)
316
310
  super(type, location, message)
317
-
318
311
  @tag_name = tag_name
319
312
  @expected = expected
320
313
  @found = found
@@ -327,11 +320,11 @@ module Herb
327
320
 
328
321
  #: () -> serialized_void_element_closing_tag_error
329
322
  def to_hash
330
- super.merge({
323
+ super.merge(
331
324
  tag_name: tag_name,
332
325
  expected: expected,
333
- found: found,
334
- }) #: Herb::serialized_void_element_closing_tag_error
326
+ found: found
327
+ ) #: Herb::serialized_void_element_closing_tag_error
335
328
  end
336
329
 
337
330
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -359,7 +352,6 @@ module Herb
359
352
  #: (String, Location, String, Herb::Token) -> void
360
353
  def initialize(type, location, message, opening_tag)
361
354
  super(type, location, message)
362
-
363
355
  @opening_tag = opening_tag
364
356
  end
365
357
 
@@ -370,9 +362,9 @@ module Herb
370
362
 
371
363
  #: () -> serialized_unclosed_element_error
372
364
  def to_hash
373
- super.merge({
374
- opening_tag: opening_tag,
375
- }) #: Herb::serialized_unclosed_element_error
365
+ super.merge(
366
+ opening_tag: opening_tag
367
+ ) #: Herb::serialized_unclosed_element_error
376
368
  end
377
369
 
378
370
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -400,7 +392,6 @@ module Herb
400
392
  #: (String, Location, String, String, String, String) -> void
401
393
  def initialize(type, location, message, error_message, diagnostic_id, level)
402
394
  super(type, location, message)
403
-
404
395
  @error_message = error_message
405
396
  @diagnostic_id = diagnostic_id
406
397
  @level = level
@@ -413,11 +404,11 @@ module Herb
413
404
 
414
405
  #: () -> serialized_ruby_parse_error
415
406
  def to_hash
416
- super.merge({
407
+ super.merge(
417
408
  error_message: error_message,
418
409
  diagnostic_id: diagnostic_id,
419
- level: level,
420
- }) #: Herb::serialized_ruby_parse_error
410
+ level: level
411
+ ) #: Herb::serialized_ruby_parse_error
421
412
  end
422
413
 
423
414
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -443,7 +434,6 @@ module Herb
443
434
  #: (String, Location, String, String) -> void
444
435
  def initialize(type, location, message, keyword)
445
436
  super(type, location, message)
446
-
447
437
  @keyword = keyword
448
438
  end
449
439
 
@@ -454,9 +444,9 @@ module Herb
454
444
 
455
445
  #: () -> serialized_erb_control_flow_scope_error
456
446
  def to_hash
457
- super.merge({
458
- keyword: keyword,
459
- }) #: Herb::serialized_erb_control_flow_scope_error
447
+ super.merge(
448
+ keyword: keyword
449
+ ) #: Herb::serialized_erb_control_flow_scope_error
460
450
  end
461
451
 
462
452
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -480,7 +470,6 @@ module Herb
480
470
  #: (String, Location, String, String) -> void
481
471
  def initialize(type, location, message, keyword)
482
472
  super(type, location, message)
483
-
484
473
  @keyword = keyword
485
474
  end
486
475
 
@@ -491,9 +480,9 @@ module Herb
491
480
 
492
481
  #: () -> serialized_missingerb_end_tag_error
493
482
  def to_hash
494
- super.merge({
495
- keyword: keyword,
496
- }) #: Herb::serialized_missingerb_end_tag_error
483
+ super.merge(
484
+ keyword: keyword
485
+ ) #: Herb::serialized_missingerb_end_tag_error
497
486
  end
498
487
 
499
488
  #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
@@ -509,5 +498,25 @@ module Herb
509
498
  end
510
499
  end
511
500
 
501
+ class ERBMultipleBlocksInTagError < Error
502
+ include Colors
503
+
504
+ #: () -> String
505
+ def inspect
506
+ tree_inspect.rstrip.gsub(/\s+$/, "")
507
+ end
508
+
509
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
510
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 25)
511
+ output = +""
512
+
513
+ output += white("@ #{bold(red(error_name))} #{dimmed("(location: #{location.tree_inspect})\n")}")
514
+ output += white("└── message: #{green(message.inspect)}\n")
515
+ output += %(\n)
516
+
517
+ output.gsub(/^/, " " * indent)
518
+ end
519
+ end
520
+
512
521
  end
513
522
  end
data/lib/herb/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # typed: true
3
3
 
4
4
  module Herb
5
- VERSION = "0.8.4"
5
+ VERSION = "0.8.5"
6
6
  end
@@ -9,6 +9,9 @@ module Herb
9
9
  # : (String) -> bool
10
10
  def erb_comment?: (String) -> bool
11
11
 
12
+ # : (String) -> bool
13
+ def erb_graphql?: (String) -> bool
14
+
12
15
  # : (String) -> bool
13
16
  def erb_output?: (String) -> bool
14
17
 
data/sig/herb/errors.rbs CHANGED
@@ -243,5 +243,15 @@ module Herb
243
243
  # : (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
244
244
  def tree_inspect: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
245
245
  end
246
+
247
+ class ERBMultipleBlocksInTagError < Error
248
+ include Colors
249
+
250
+ # : () -> String
251
+ def inspect: () -> String
252
+
253
+ # : (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
254
+ def tree_inspect: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
255
+ end
246
256
  end
247
257
  end
@@ -58,4 +58,7 @@ module Herb
58
58
  keyword: String,
59
59
  }
60
60
 
61
+ type serialized_erb_multiple_blocks_in_tag_error = serialized_error & {
62
+ }
63
+
61
64
  end
data/src/analyze.c CHANGED
@@ -45,6 +45,8 @@ static analyzed_ruby_T* herb_analyze_ruby(hb_string_T source) {
45
45
  search_yield_nodes(analyzed->root, analyzed);
46
46
  search_block_closing_nodes(analyzed);
47
47
 
48
+ if (!analyzed->valid) { pm_visit_node(analyzed->root, search_unclosed_control_flows, analyzed); }
49
+
48
50
  return analyzed;
49
51
  }
50
52
 
@@ -54,12 +56,21 @@ static bool analyze_erb_content(const AST_NODE_T* node, void* data) {
54
56
 
55
57
  const char* opening = erb_content_node->tag_opening->value;
56
58
 
57
- if (strcmp(opening, "<%%") != 0 && strcmp(opening, "<%%=") != 0 && strcmp(opening, "<%#") != 0) {
59
+ if (strcmp(opening, "<%%") != 0 && strcmp(opening, "<%%=") != 0 && strcmp(opening, "<%#") != 0
60
+ && strcmp(opening, "<%graphql") != 0) {
58
61
  analyzed_ruby_T* analyzed = herb_analyze_ruby(hb_string(erb_content_node->content->value));
59
62
 
60
63
  erb_content_node->parsed = true;
61
64
  erb_content_node->valid = analyzed->valid;
62
65
  erb_content_node->analyzed_ruby = analyzed;
66
+
67
+ if (!analyzed->valid && analyzed->unclosed_control_flow_count >= 2) {
68
+ append_erb_multiple_blocks_in_tag_error(
69
+ erb_content_node->base.location.start,
70
+ erb_content_node->base.location.end,
71
+ erb_content_node->base.errors
72
+ );
73
+ }
63
74
  } else {
64
75
  erb_content_node->parsed = false;
65
76
  erb_content_node->valid = true;