haml_lint 0.49.0 → 0.49.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/haml_lint/ruby_extraction/chunk_extractor.rb +52 -10
- data/lib/haml_lint/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95c5137a04c59dbfc74fbc6648be0e502ae683e7bca5ff756bab9daf128243cb
|
4
|
+
data.tar.gz: 4b7429295c1a07d73dd3fae058cafba55fdcab05a7113623a5db4d8aed4d7d11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ab868d2be78c9a5fcebc8dd370687fa088deb4b537a64c3ff878e4a8bb4a057a9841c6b0f02914a9ebd791bf19a19e737d9f559e8b12f577c215695ff9b207d
|
7
|
+
data.tar.gz: dbd373708eba214749fc1aa20e42d330c494ac1e3161a71527c956f405e845fb724d312dfa4bfae1bc3c080fe2d972fb75cf9915e1a1c0a808ba4b1ca963be15
|
@@ -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
|
-
|
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
|
@@ -386,7 +394,7 @@ module HamlLint::RubyExtraction
|
|
386
394
|
|
387
395
|
# Adds chunks for the interpolation within the given code
|
388
396
|
def add_interpolation_chunks(node, code, haml_line_index, indent:, line_start_index: 0)
|
389
|
-
HamlLint::Utils.handle_interpolation_with_indexes(code) do |scanner, line_index,
|
397
|
+
HamlLint::Utils.handle_interpolation_with_indexes(code) do |scanner, line_index, line_char_index|
|
390
398
|
escapes = scanner[2].size
|
391
399
|
next if escapes.odd?
|
392
400
|
char = scanner[3] # '{', '@' or '$'
|
@@ -395,20 +403,25 @@ module HamlLint::RubyExtraction
|
|
395
403
|
next
|
396
404
|
end
|
397
405
|
|
398
|
-
|
399
|
-
|
406
|
+
line_start_char_index = line_char_index
|
407
|
+
line_start_char_index += line_start_index if line_index == 0
|
408
|
+
code_start_char_index = scanner.charpos
|
400
409
|
|
401
|
-
|
410
|
+
# This moves the scanner
|
411
|
+
Haml::Util.balance(scanner, '{', '}', 1)
|
402
412
|
|
403
413
|
# Need to manually get the code now that we have positions so that all whitespace is present,
|
404
414
|
# because Haml::Util.balance does a strip...
|
405
|
-
interpolated_code = code[
|
406
|
-
|
407
|
-
interpolated_code = "#{' ' * indent}#{script_output_prefix}#{interpolated_code}"
|
415
|
+
interpolated_code = code[code_start_char_index...scanner.charpos - 1]
|
408
416
|
|
409
417
|
if interpolated_code.include?("\n")
|
410
418
|
# We can't correct multiline interpolation.
|
411
419
|
# Finding meaningful code to generate and then transfer back is pretty complex
|
420
|
+
|
421
|
+
# Since we can't fix it, strip around the code to reduce RuboCop lints that we won't be able to fix.
|
422
|
+
interpolated_code = interpolated_code.strip
|
423
|
+
interpolated_code = "#{' ' * indent}#{script_output_prefix}#{interpolated_code}"
|
424
|
+
|
412
425
|
placeholder_code = interpolated_code.gsub(/\s*\n\s*/, ' ').rstrip
|
413
426
|
unless parse_ruby(placeholder_code)
|
414
427
|
placeholder_code = interpolated_code.gsub(/\s*\n\s*/, '; ').rstrip
|
@@ -416,9 +429,10 @@ module HamlLint::RubyExtraction
|
|
416
429
|
@ruby_chunks << AdHocChunk.new(node, [placeholder_code],
|
417
430
|
haml_line_index: haml_line_index + line_index)
|
418
431
|
else
|
432
|
+
interpolated_code = "#{' ' * indent}#{script_output_prefix}#{interpolated_code}"
|
419
433
|
@ruby_chunks << InterpolationChunk.new(node, [interpolated_code],
|
420
434
|
haml_line_index: haml_line_index + line_index,
|
421
|
-
start_char_index:
|
435
|
+
start_char_index: line_start_char_index,
|
422
436
|
end_marker_indent: indent)
|
423
437
|
end
|
424
438
|
end
|
@@ -433,6 +447,15 @@ module HamlLint::RubyExtraction
|
|
433
447
|
end
|
434
448
|
end
|
435
449
|
|
450
|
+
def process_plain_multiline!(line)
|
451
|
+
if line&.end_with?(' |')
|
452
|
+
line[-2..] = ''
|
453
|
+
true
|
454
|
+
else
|
455
|
+
false
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
436
459
|
# Returns the raw lines from the haml for the given index.
|
437
460
|
# Multiple lines are returned when a line ends with a comma as that is the only
|
438
461
|
# time HAMLs allows Ruby lines to be split.
|
@@ -517,6 +540,25 @@ module HamlLint::RubyExtraction
|
|
517
540
|
[first_line_offset, ruby_lines]
|
518
541
|
end
|
519
542
|
|
543
|
+
def extract_piped_plain_multilines(first_line_index)
|
544
|
+
lines = []
|
545
|
+
|
546
|
+
cur_line = @original_haml_lines[first_line_index].rstrip
|
547
|
+
cur_line_index = first_line_index
|
548
|
+
|
549
|
+
# The pipes must also be on the last line of the multi-line section
|
550
|
+
while cur_line && process_plain_multiline!(cur_line)
|
551
|
+
lines << cur_line
|
552
|
+
cur_line_index += 1
|
553
|
+
cur_line = @original_haml_lines[cur_line_index].rstrip
|
554
|
+
end
|
555
|
+
|
556
|
+
if lines.empty?
|
557
|
+
lines << cur_line
|
558
|
+
end
|
559
|
+
lines
|
560
|
+
end
|
561
|
+
|
520
562
|
# Tag attributes actually handle multiline differently than scripts.
|
521
563
|
# The basic system basically keeps considering more lines until it meets the closing braces, but still
|
522
564
|
# processes pipes too (same as extract_raw_ruby_lines).
|
data/lib/haml_lint/version.rb
CHANGED
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.
|
4
|
+
version: 0.49.2
|
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-
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|