@@ -269,7 +269,7 @@ defmodule Code.Comments do
269
269
end_line = get_end_line ( quoted , start_line )
270
270
271
271
{ 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 )
273
273
274
274
quoted = append_comments ( quoted , :inner_comments , trailing_comments )
275
275
@@ -281,7 +281,7 @@ defmodule Code.Comments do
281
281
end_line = get_end_line ( quoted , start_line )
282
282
283
283
{ 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 )
285
285
286
286
last_value = append_comments ( last_value , :trailing_comments , trailing_comments )
287
287
@@ -295,7 +295,7 @@ defmodule Code.Comments do
295
295
end_line = get_end_line ( quoted , start_line )
296
296
297
297
{ 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 )
299
299
300
300
unquote_splicing =
301
301
append_comments ( unquote_splicing , :trailing_comments , trailing_comments )
@@ -316,7 +316,7 @@ defmodule Code.Comments do
316
316
end_line = get_end_line ( quoted , start_line )
317
317
318
318
{ 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 )
320
320
321
321
value = append_comments ( value , :trailing_comments , trailing_comments )
322
322
@@ -342,7 +342,7 @@ defmodule Code.Comments do
342
342
end_line = get_end_line ( quoted , start_line )
343
343
344
344
{ 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 )
346
346
347
347
right = append_comments ( right , :trailing_comments , trailing_comments )
348
348
@@ -366,7 +366,7 @@ defmodule Code.Comments do
366
366
line = get_line ( call )
367
367
368
368
{ 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 )
370
370
371
371
call = append_comments ( call , :trailing_comments , trailing_comments )
372
372
@@ -380,7 +380,7 @@ defmodule Code.Comments do
380
380
case left do
381
381
[ ] ->
382
382
{ 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 )
384
384
385
385
quoted = append_comments ( quoted , :leading_comments , leading_comments )
386
386
@@ -401,11 +401,11 @@ defmodule Code.Comments do
401
401
with true <- is_atom ( form ) ,
402
402
<< "sigil_" , _name :: binary >> <- Atom . to_string ( form ) ,
403
403
true <- not is_nil ( meta ) do
404
- [ content , modifiers ] = args
404
+ [ content | modifiers ] = args
405
405
406
406
{ content , state } = merge_mixed_comments ( content , state )
407
407
408
- quoted = put_args ( quoted , [ content , modifiers ] )
408
+ quoted = put_args ( quoted , [ content | modifiers ] )
409
409
410
410
{ quoted , state }
411
411
else
@@ -461,7 +461,7 @@ defmodule Code.Comments do
461
461
line = get_line ( last_value )
462
462
463
463
{ trailing_comments , comments } =
464
- Enum . split_with ( comments , & ( & 1 . line > line and & 1 . line < end_line ) )
464
+ split_trailing_comments ( comments , line , end_line )
465
465
466
466
last_value = append_comments ( last_value , :trailing_comments , trailing_comments )
467
467
@@ -488,7 +488,7 @@ defmodule Code.Comments do
488
488
start_line = get_line ( last_block_arg )
489
489
490
490
{ 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 )
492
492
493
493
last_block_arg = append_comments ( last_block_arg , :trailing_comments , trailing_comments )
494
494
@@ -510,7 +510,7 @@ defmodule Code.Comments do
510
510
line = get_end_line ( last_arg , get_line ( last_arg ) )
511
511
512
512
{ trailing_comments , comments } =
513
- Enum . split_with ( comments , & ( & 1 . line > line and & 1 . line < end_line ) )
513
+ split_trailing_comments ( comments , line , end_line )
514
514
515
515
last_arg = append_comments ( last_arg , :trailing_comments , trailing_comments )
516
516
@@ -523,7 +523,7 @@ defmodule Code.Comments do
523
523
524
524
nil ->
525
525
{ 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 )
527
527
528
528
quoted = append_comments ( quoted , :inner_comments , trailing_comments )
529
529
{ quoted , comments }
@@ -544,10 +544,10 @@ defmodule Code.Comments do
544
544
value_line = get_line ( value )
545
545
546
546
{ 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 )
548
548
549
549
{ 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 )
551
551
552
552
value = put_leading_comments ( value , leading_comments )
553
553
value = put_trailing_comments ( value , trailing_comments )
@@ -566,10 +566,10 @@ defmodule Code.Comments do
566
566
value_line = get_line ( value )
567
567
568
568
{ 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 )
570
570
571
571
{ 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 )
573
573
574
574
value = put_leading_comments ( value , leading_comments )
575
575
value = put_trailing_comments ( value , trailing_comments )
@@ -590,7 +590,7 @@ defmodule Code.Comments do
590
590
end_line = get_end_line ( quoted , start_line )
591
591
592
592
{ 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 )
594
594
595
595
last_value = append_comments ( last_value , :trailing_comments , trailing_comments )
596
596
@@ -603,7 +603,7 @@ defmodule Code.Comments do
603
603
end_line = get_end_line ( quoted , start_line )
604
604
605
605
{ 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 )
607
607
608
608
unquote_splicing =
609
609
append_comments ( unquote_splicing , :trailing_comments , trailing_comments )
@@ -654,7 +654,7 @@ defmodule Code.Comments do
654
654
case last_arg do
655
655
nil ->
656
656
{ 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 )
658
658
659
659
block_args = append_comments ( block_args , :inner_comments , trailing_comments )
660
660
@@ -736,7 +736,7 @@ defmodule Code.Comments do
736
736
stab_line = get_line ( stab )
737
737
738
738
{ 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 )
740
740
741
741
stab = append_comments ( stab , :leading_comments , leading_comments )
742
742
@@ -753,7 +753,7 @@ defmodule Code.Comments do
753
753
754
754
call ->
755
755
{ 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 )
757
757
758
758
call = append_comments ( call , :trailing_comments , trailing_comments )
759
759
@@ -775,7 +775,7 @@ defmodule Code.Comments do
775
775
case last_arg do
776
776
nil ->
777
777
{ 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 )
779
779
780
780
trailing_comments = Enum . sort_by ( trailing_comments , & & 1 . line )
781
781
@@ -810,13 +810,14 @@ defmodule Code.Comments do
810
810
line =
811
811
case last_arg do
812
812
[ ] -> block_start
813
+ [ { _key , value } | _ ] -> get_line ( value )
813
814
[ first | _ ] -> get_line ( first )
814
815
{ _ , _ , _ } -> get_line ( last_arg )
815
816
_ -> block_start
816
817
end
817
818
818
819
{ trailing_comments , comments } =
819
- Enum . split_with ( comments , & ( & 1 . line > line and & 1 . line < block_end ) )
820
+ split_trailing_comments ( comments , line , block_end )
820
821
821
822
last_arg = append_comments ( last_arg , :trailing_comments , trailing_comments )
822
823
@@ -938,4 +939,12 @@ defmodule Code.Comments do
938
939
_ -> false
939
940
end )
940
941
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
941
950
end
0 commit comments