@@ -269,7 +269,7 @@ defmodule Code.Comments do
269269 end_line = get_end_line ( quoted , start_line )
270270
271271 { trailing_comments , comments } =
272- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
272+ split_trailing_comments ( comments , start_line , end_line )
273273
274274 quoted = append_comments ( quoted , :inner_comments , trailing_comments )
275275
@@ -281,7 +281,7 @@ defmodule Code.Comments do
281281 end_line = get_end_line ( quoted , start_line )
282282
283283 { trailing_comments , comments } =
284- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
284+ split_trailing_comments ( comments , start_line , end_line )
285285
286286 last_value = append_comments ( last_value , :trailing_comments , trailing_comments )
287287
@@ -295,7 +295,7 @@ defmodule Code.Comments do
295295 end_line = get_end_line ( quoted , start_line )
296296
297297 { trailing_comments , comments } =
298- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
298+ split_trailing_comments ( comments , start_line , end_line )
299299
300300 unquote_splicing =
301301 append_comments ( unquote_splicing , :trailing_comments , trailing_comments )
@@ -316,7 +316,7 @@ defmodule Code.Comments do
316316 end_line = get_end_line ( quoted , start_line )
317317
318318 { trailing_comments , comments } =
319- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
319+ split_trailing_comments ( comments , start_line , end_line )
320320
321321 value = append_comments ( value , :trailing_comments , trailing_comments )
322322
@@ -342,7 +342,7 @@ defmodule Code.Comments do
342342 end_line = get_end_line ( quoted , start_line )
343343
344344 { trailing_comments , comments } =
345- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
345+ split_trailing_comments ( comments , start_line , end_line )
346346
347347 right = append_comments ( right , :trailing_comments , trailing_comments )
348348
@@ -366,7 +366,7 @@ defmodule Code.Comments do
366366 line = get_line ( call )
367367
368368 { trailing_comments , comments } =
369- Enum . split_with ( state . comments , & ( & 1 . line > line and & 1 . line < end_line ) )
369+ split_trailing_comments ( state . comments , line , end_line )
370370
371371 call = append_comments ( call , :trailing_comments , trailing_comments )
372372
@@ -380,7 +380,7 @@ defmodule Code.Comments do
380380 case left do
381381 [ ] ->
382382 { leading_comments , comments } =
383- Enum . split_with ( comments , & ( & 1 . line > block_start and & 1 . line < start_line ) )
383+ split_leading_comments ( comments , block_start , start_line )
384384
385385 quoted = append_comments ( quoted , :leading_comments , leading_comments )
386386
@@ -401,11 +401,11 @@ defmodule Code.Comments do
401401 with true <- is_atom ( form ) ,
402402 << "sigil_" , _name :: binary >> <- Atom . to_string ( form ) ,
403403 true <- not is_nil ( meta ) do
404- [ content , modifiers ] = args
404+ [ content | modifiers ] = args
405405
406406 { content , state } = merge_mixed_comments ( content , state )
407407
408- quoted = put_args ( quoted , [ content , modifiers ] )
408+ quoted = put_args ( quoted , [ content | modifiers ] )
409409
410410 { quoted , state }
411411 else
@@ -461,7 +461,7 @@ defmodule Code.Comments do
461461 line = get_line ( last_value )
462462
463463 { trailing_comments , comments } =
464- Enum . split_with ( comments , & ( & 1 . line > line and & 1 . line < end_line ) )
464+ split_trailing_comments ( comments , line , end_line )
465465
466466 last_value = append_comments ( last_value , :trailing_comments , trailing_comments )
467467
@@ -488,7 +488,7 @@ defmodule Code.Comments do
488488 start_line = get_line ( last_block_arg )
489489
490490 { trailing_comments , comments } =
491- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
491+ split_trailing_comments ( comments , start_line , end_line )
492492
493493 last_block_arg = append_comments ( last_block_arg , :trailing_comments , trailing_comments )
494494
@@ -510,7 +510,7 @@ defmodule Code.Comments do
510510 line = get_end_line ( last_arg , get_line ( last_arg ) )
511511
512512 { trailing_comments , comments } =
513- Enum . split_with ( comments , & ( & 1 . line > line and & 1 . line < end_line ) )
513+ split_trailing_comments ( comments , line , end_line )
514514
515515 last_arg = append_comments ( last_arg , :trailing_comments , trailing_comments )
516516
@@ -523,7 +523,7 @@ defmodule Code.Comments do
523523
524524 nil ->
525525 { trailing_comments , comments } =
526- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
526+ split_trailing_comments ( comments , start_line , end_line )
527527
528528 quoted = append_comments ( quoted , :inner_comments , trailing_comments )
529529 { quoted , comments }
@@ -544,10 +544,10 @@ defmodule Code.Comments do
544544 value_line = get_line ( value )
545545
546546 { leading_comments , comments } =
547- Enum . split_with ( state . comments , & ( & 1 . line > start_line and & 1 . line <= value_line ) )
547+ split_leading_comments ( state . comments , start_line , value_line )
548548
549549 { trailing_comments , comments } =
550- Enum . split_with ( comments , & ( & 1 . line > value_line and & 1 . line < end_line ) )
550+ split_trailing_comments ( comments , value_line , end_line )
551551
552552 value = put_leading_comments ( value , leading_comments )
553553 value = put_trailing_comments ( value , trailing_comments )
@@ -566,10 +566,10 @@ defmodule Code.Comments do
566566 value_line = get_line ( value )
567567
568568 { leading_comments , comments } =
569- Enum . split_with ( state . comments , & ( & 1 . line > start_line and & 1 . line <= value_line ) )
569+ split_leading_comments ( state . comments , start_line , value_line )
570570
571571 { trailing_comments , comments } =
572- Enum . split_with ( comments , & ( & 1 . line > value_line and & 1 . line < end_line ) )
572+ split_trailing_comments ( comments , value_line , end_line )
573573
574574 value = put_leading_comments ( value , leading_comments )
575575 value = put_trailing_comments ( value , trailing_comments )
@@ -590,7 +590,7 @@ defmodule Code.Comments do
590590 end_line = get_end_line ( quoted , start_line )
591591
592592 { trailing_comments , comments } =
593- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
593+ split_trailing_comments ( comments , start_line , end_line )
594594
595595 last_value = append_comments ( last_value , :trailing_comments , trailing_comments )
596596
@@ -603,7 +603,7 @@ defmodule Code.Comments do
603603 end_line = get_end_line ( quoted , start_line )
604604
605605 { trailing_comments , comments } =
606- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
606+ split_trailing_comments ( comments , start_line , end_line )
607607
608608 unquote_splicing =
609609 append_comments ( unquote_splicing , :trailing_comments , trailing_comments )
@@ -654,7 +654,7 @@ defmodule Code.Comments do
654654 case last_arg do
655655 nil ->
656656 { trailing_comments , comments } =
657- Enum . split_with ( comments , & ( & 1 . line > block_start and & 1 . line < block_end ) )
657+ split_trailing_comments ( comments , block_start , block_end )
658658
659659 block_args = append_comments ( block_args , :inner_comments , trailing_comments )
660660
@@ -736,7 +736,7 @@ defmodule Code.Comments do
736736 stab_line = get_line ( stab )
737737
738738 { leading_comments , comments } =
739- Enum . split_with ( comments , & ( & 1 . line > block_start and & 1 . line < stab_line ) )
739+ split_leading_comments ( comments , block_start , stab_line )
740740
741741 stab = append_comments ( stab , :leading_comments , leading_comments )
742742
@@ -753,7 +753,7 @@ defmodule Code.Comments do
753753
754754 call ->
755755 { trailing_comments , comments } =
756- Enum . split_with ( comments , & ( & 1 . line > start_line and & 1 . line < end_line ) )
756+ split_trailing_comments ( comments , start_line , end_line )
757757
758758 call = append_comments ( call , :trailing_comments , trailing_comments )
759759
@@ -775,7 +775,7 @@ defmodule Code.Comments do
775775 case last_arg do
776776 nil ->
777777 { trailing_comments , comments } =
778- Enum . split_with ( comments , & ( & 1 . line > block_start and & 1 . line < block_end ) )
778+ split_trailing_comments ( comments , block_start , block_end )
779779
780780 trailing_comments = Enum . sort_by ( trailing_comments , & & 1 . line )
781781
@@ -810,13 +810,14 @@ defmodule Code.Comments do
810810 line =
811811 case last_arg do
812812 [ ] -> block_start
813+ [ { _key , value } | _ ] -> get_line ( value )
813814 [ first | _ ] -> get_line ( first )
814815 { _ , _ , _ } -> get_line ( last_arg )
815816 _ -> block_start
816817 end
817818
818819 { trailing_comments , comments } =
819- Enum . split_with ( comments , & ( & 1 . line > line and & 1 . line < block_end ) )
820+ split_trailing_comments ( comments , line , block_end )
820821
821822 last_arg = append_comments ( last_arg , :trailing_comments , trailing_comments )
822823
@@ -938,4 +939,12 @@ defmodule Code.Comments do
938939 _ -> false
939940 end )
940941 end
942+
943+ defp split_leading_comments ( comments , min , max ) do
944+ Enum . split_with ( comments , & ( & 1 . line > min and & 1 . line <= max ) )
945+ end
946+
947+ defp split_trailing_comments ( comments , min , max ) do
948+ Enum . split_with ( comments , & ( & 1 . line > min and & 1 . line < max ) )
949+ end
941950end
0 commit comments