From 139457a89141550ee5a382fbd5b16905b9d62d88 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 8 Sep 2020 08:20:55 -0700 Subject: [PATCH] improved treatment of long lines with here targets --- bin/perltidy | 6 +++--- lib/Perl/Tidy/Formatter.pm | 14 +------------- t/snippets/expect/here_long.def | 2 +- t/snippets/expect/here_long.here_long | 5 +++-- t/snippets/here_long.in | 2 +- t/snippets/packing_list.txt | 4 ++-- t/snippets21.t | 4 ++-- t/snippets22.t | 7 ++++--- 8 files changed, 17 insertions(+), 27 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index c8753c4a..a6f65a71 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3613,9 +3613,9 @@ allow perltidy to parse interactive VMS scripts, but it should be used for any script which is normally invoked with C. Please note: do not use this flag unless you are sure your script needs it. -Parsing errors can occur if it does not have a hash-bang. For example, if the -actual first hash-bang is in a here-doc, a parsing error will occur because the -tokenization will begin in the middle of the here-doc. +Parsing errors can occur if it does not have a hash-bang, or, for example, if +the actual first hash-bang is in a here-doc. In that case a parsing error will +occur because the tokenization will begin in the middle of the here-doc. =item Making a file unreadable diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 305b6478..f5533640 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -3056,18 +3056,6 @@ sub respace_tokens { $rtoken_vars->[_TOKEN_] = $token; } - # change code type to be NIN at a here target to avoid breaking the line - elsif ( $type eq 'h' ) { - - # 'VB' = Verbatim - line goes out verbatim - # 'FS' = Format Skipping - line goes out verbatim, no blanks - # 'IO' = Indent Only - only indentation may be changed - unless ( $CODE_type && $CODE_type =~ /^(VB|FS|IO)$/ ) { - $CODE_type = 'NIN'; - $line_of_tokens->{_code_type} = $CODE_type; - } - } - # patch to add space to something like "x10" # This avoids having to split this token in the pre-tokenizer elsif ( $type eq 'n' ) { @@ -13861,7 +13849,7 @@ sub get_seqno { } } else { - $strength = NO_BREAK; + $strength = NO_BREAK + 1; } #--------------------------------------------------------------- diff --git a/t/snippets/expect/here_long.def b/t/snippets/expect/here_long.def index 4a75504e..259b9907 100644 --- a/t/snippets/expect/here_long.def +++ b/t/snippets/expect/here_long.def @@ -1,4 +1,4 @@ -# must not break first line regardless of value of maximum-line-length +# must not break after here target regardless of maximum-line-length $sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL"; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' diff --git a/t/snippets/expect/here_long.here_long b/t/snippets/expect/here_long.here_long index 4a75504e..d8998ca1 100644 --- a/t/snippets/expect/here_long.here_long +++ b/t/snippets/expect/here_long.here_long @@ -1,5 +1,6 @@ -# must not break first line regardless of value of maximum-line-length -$sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL"; +# must not break after here target regardless of maximum-line-length +$sth = $dbh->prepare( + <<"END_OF_SELECT") or die "Couldn't prepare SQL"; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' END_OF_SELECT diff --git a/t/snippets/here_long.in b/t/snippets/here_long.in index c4548912..f34d97fe 100644 --- a/t/snippets/here_long.in +++ b/t/snippets/here_long.in @@ -1,4 +1,4 @@ -# must not break first line regardless of value of maximum-line-length +# must not break after here target regardless of maximum-line-length $sth= $dbh->prepare (<<"END_OF_SELECT") or die "Couldn't prepare SQL" ; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index f4cd202e..c1c2cd6f 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -269,6 +269,8 @@ ../snippets21.t nib.nib2 ../snippets21.t scbb-csc.def ../snippets21.t scbb-csc.scbb-csc +../snippets21.t here_long.def +../snippets22.t here_long.here_long ../snippets3.t ce_wn1.ce_wn ../snippets3.t ce_wn1.def ../snippets3.t colin.colin @@ -409,5 +411,3 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets21.t here_long.def -../snippets22.t here_long.here_long diff --git a/t/snippets21.t b/t/snippets21.t index 6f684e72..5133d03e 100644 --- a/t/snippets21.t +++ b/t/snippets21.t @@ -99,7 +99,7 @@ else { # We're the third word to have this ---------- 'here_long' => <<'----------', -# must not break first line regardless of value of maximum-line-length +# must not break after here target regardless of maximum-line-length $sth= $dbh->prepare (<<"END_OF_SELECT") or die "Couldn't prepare SQL" ; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' @@ -786,7 +786,7 @@ sub perlmod_install_advice { source => "here_long", params => "def", expect => <<'#19...........', -# must not break first line regardless of value of maximum-line-length +# must not break after here target regardless of maximum-line-length $sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL"; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' diff --git a/t/snippets22.t b/t/snippets22.t index 6a04e27d..782c7c48 100644 --- a/t/snippets22.t +++ b/t/snippets22.t @@ -26,7 +26,7 @@ BEGIN { $rsources = { 'here_long' => <<'----------', -# must not break first line regardless of value of maximum-line-length +# must not break after here target regardless of maximum-line-length $sth= $dbh->prepare (<<"END_OF_SELECT") or die "Couldn't prepare SQL" ; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' @@ -44,8 +44,9 @@ END_OF_SELECT source => "here_long", params => "here_long", expect => <<'#1...........', -# must not break first line regardless of value of maximum-line-length -$sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL"; +# must not break after here target regardless of maximum-line-length +$sth = $dbh->prepare( + <<"END_OF_SELECT") or die "Couldn't prepare SQL"; SELECT COUNT(duration),SUM(duration) FROM logins WHERE username='$user' END_OF_SELECT -- 2.39.5