haml_lint 0.49.0 → 0.49.1

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: 0411721c82b95f3662c12b9bb3eeff8013a81dbef095d1b5756baf529f121fd9
4
- data.tar.gz: 2ab1affd25ac7b27278a35bc56a883aeb8626573e082b3ac4a2e725bdff1a90f
3
+ metadata.gz: ccc4d7e3d573b44a76eb95a860b47023cacc016d84a423fab45ed5521ec4c859
4
+ data.tar.gz: 30df2f2e85a8b5629fc3e7be4d236f899e4a7350520d3fa6ff1ad544e298db81
5
5
  SHA512:
6
- metadata.gz: 431cc4b6f6dec7e6d910e7406a76fa58a9224fd689446636e02a7cb895137c33090a3fd845ffbeda941650549da069b8ce056eb979494d6442b348939da32ba5
7
- data.tar.gz: 9c491a34546d7b437ee53ba5ec4059f8019bcd45dae564c90d230d8faaf69c7e4ec5f07585afc61bd5e0f903b1678567b727d9d82b3a30723e0aa1c8767923a6
6
+ metadata.gz: 31ee68b52d129a92e1ce5b0b08c5c1770cc79cb5fc334ead102b3512b3e01e899b9d4b48f14cfb75d047708c8274d76ef9f76c1c9ea96ce9418fbcc7d90a3d07
7
+ data.tar.gz: f5723c505efeb8b98c278d9ff6e18c6f04396542f5f45543b3fdde2c622f5431378592a03340cd3040a4ed357ab8e7f216f98c35bf0e65f17c3925e5fab14590
@@ -102,7 +102,8 @@ module HamlLint::RubyExtraction
102
102
  # that contains interpolation.
103
103
  indent = raw_first_line.index(/\S/)
104
104
  @ruby_chunks << PlaceholderMarkerChunk.new(node, 'interpolation', indent: indent)
105
- add_interpolation_chunks(node, raw_first_line, node.line - 1, indent: indent)
105
+ lines = extract_piped_plain_multilines(node.line - 1)
106
+ add_interpolation_chunks(node, lines.join("\n"), node.line - 1, indent: indent)
106
107
  return
107
108
  end
108
109
 
@@ -327,9 +328,16 @@ module HamlLint::RubyExtraction
327
328
  # ex: %tag hello #{world}
328
329
  # Sadly, the text with interpolation is escaped from the original, but this code
329
330
  # needs the original.
330
- interpolation_original = @document.unescape_interpolation_to_original_cache[node.script]
331
331
 
332
+ interpolation_original = @document.unescape_interpolation_to_original_cache[node.script]
332
333
  line_start_index = @original_haml_lines[node.line - 1].rindex(interpolation_original)
334
+ if line_start_index.nil?
335
+ raw_lines = extract_piped_plain_multilines(node.line - 1)
336
+ equivalent_haml_code = "#{raw_lines.first} #{raw_lines[1..].map(&:lstrip).join(' ')}"
337
+ line_start_index = equivalent_haml_code.rindex(interpolation_original)
338
+
339
+ interpolation_original = raw_lines.join("\n")
340
+ end
333
341
  add_interpolation_chunks(node, interpolation_original, node.line - 1,
334
342
  line_start_index: line_start_index, indent: indent)
335
343
  else
@@ -404,11 +412,14 @@ module HamlLint::RubyExtraction
404
412
  # because Haml::Util.balance does a strip...
405
413
  interpolated_code = code[char_index...scanner.charpos - 1]
406
414
 
407
- interpolated_code = "#{' ' * indent}#{script_output_prefix}#{interpolated_code}"
408
-
409
415
  if interpolated_code.include?("\n")
410
416
  # We can't correct multiline interpolation.
411
417
  # Finding meaningful code to generate and then transfer back is pretty complex
418
+
419
+ # Since we can't fix it, strip around the code to reduce RuboCop lints that we won't be able to fix.
420
+ interpolated_code = interpolated_code.strip
421
+ interpolated_code = "#{' ' * indent}#{script_output_prefix}#{interpolated_code}"
422
+
412
423
  placeholder_code = interpolated_code.gsub(/\s*\n\s*/, ' ').rstrip
413
424
  unless parse_ruby(placeholder_code)
414
425
  placeholder_code = interpolated_code.gsub(/\s*\n\s*/, '; ').rstrip
@@ -416,6 +427,7 @@ module HamlLint::RubyExtraction
416
427
  @ruby_chunks << AdHocChunk.new(node, [placeholder_code],
417
428
  haml_line_index: haml_line_index + line_index)
418
429
  else
430
+ interpolated_code = "#{' ' * indent}#{script_output_prefix}#{interpolated_code}"
419
431
  @ruby_chunks << InterpolationChunk.new(node, [interpolated_code],
420
432
  haml_line_index: haml_line_index + line_index,
421
433
  start_char_index: start_char_index,
@@ -433,6 +445,15 @@ module HamlLint::RubyExtraction
433
445
  end
434
446
  end
435
447
 
448
+ def process_plain_multiline!(line)
449
+ if line&.end_with?(' |')
450
+ line[-2..] = ''
451
+ true
452
+ else
453
+ false
454
+ end
455
+ end
456
+
436
457
  # Returns the raw lines from the haml for the given index.
437
458
  # Multiple lines are returned when a line ends with a comma as that is the only
438
459
  # time HAMLs allows Ruby lines to be split.
@@ -517,6 +538,25 @@ module HamlLint::RubyExtraction
517
538
  [first_line_offset, ruby_lines]
518
539
  end
519
540
 
541
+ def extract_piped_plain_multilines(first_line_index)
542
+ lines = []
543
+
544
+ cur_line = @original_haml_lines[first_line_index].rstrip
545
+ cur_line_index = first_line_index
546
+
547
+ # The pipes must also be on the last line of the multi-line section
548
+ while cur_line && process_plain_multiline!(cur_line)
549
+ lines << cur_line
550
+ cur_line_index += 1
551
+ cur_line = @original_haml_lines[cur_line_index].rstrip
552
+ end
553
+
554
+ if lines.empty?
555
+ lines << cur_line
556
+ end
557
+ lines
558
+ end
559
+
520
560
  # Tag attributes actually handle multiline differently than scripts.
521
561
  # The basic system basically keeps considering more lines until it meets the closing braces, but still
522
562
  # processes pipes too (same as extract_raw_ruby_lines).
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.49.0'
5
+ VERSION = '0.49.1'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.49.0
4
+ version: 0.49.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-15 00:00:00.000000000 Z
11
+ date: 2023-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml