add option -bfvt=n, see issue git #110
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 20 Dec 2022 17:17:24 +0000 (09:17 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 20 Dec 2022 17:17:24 +0000 (09:17 -0800)
13 files changed:
dev-bin/perltidy_random_setup.pl
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
t/snippets/bfvt.in [new file with mode: 0644]
t/snippets/bfvt0.par [new file with mode: 0644]
t/snippets/bfvt2.par [new file with mode: 0644]
t/snippets/expect/bfvt.bfvt0 [new file with mode: 0644]
t/snippets/expect/bfvt.bfvt2 [new file with mode: 0644]
t/snippets/expect/bfvt.def [new file with mode: 0644]
t/snippets/expect/cpb.cpb [new file with mode: 0644]
t/snippets/expect/cpb.def [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets27.t

index b82c6ff8d89a70f538d9e895e5ff599aa5c7304b..9b46493a128362556274341a1cb28f813d58fd83 100755 (executable)
@@ -1129,6 +1129,7 @@ EOM
             'paren-tightness'               => [ 0, 2 ],
             'square-bracket-tightness'      => [ 0, 2 ],
 
+            'brace-follower-vertical-tightness'         => [ 0, 2 ],
             'block-brace-vertical-tightness'            => [ 0, 2 ],
             'brace-vertical-tightness'                  => [ 0, 2 ],
             'brace-vertical-tightness-closing'          => [ 0, 2 ],
@@ -1285,6 +1286,7 @@ EOM
           tee-pod
           tee-side-comments
           version
+          warning-output
           delete-pod
           tabs
           entab-leading-whitespace
index 9f64bd55015dbf6691a32dd42daaa3d9d9afbbf8..e509c8a463925f20c26fa0cd2efaa82d588264aa 100644 (file)
@@ -3256,6 +3256,7 @@ sub generate_options {
     $add_option->( 'add-newlines',                            'anl',   '!' );
     $add_option->( 'block-brace-vertical-tightness',          'bbvt',  '=i' );
     $add_option->( 'block-brace-vertical-tightness-list',     'bbvtl', '=s' );
+    $add_option->( 'brace-follower-vertical-tightness',       'bfvt',  '=i' );
     $add_option->( 'brace-vertical-tightness',                'bvt',   '=i' );
     $add_option->( 'brace-vertical-tightness-closing',        'bvtc',  '=i' );
     $add_option->( 'cuddled-else',                            'ce',    '!' );
@@ -3446,6 +3447,7 @@ sub generate_options {
         'square-bracket-tightness'      => [ 0,      2 ],
 
         'block-brace-vertical-tightness'            => [ 0, 2 ],
+        'brace-follower-vertical-tightness'         => [ 0, 2 ],
         'brace-vertical-tightness'                  => [ 0, 2 ],
         'brace-vertical-tightness-closing'          => [ 0, 2 ],
         'paren-vertical-tightness'                  => [ 0, 2 ],
@@ -3497,6 +3499,7 @@ sub generate_options {
 
       block-brace-tightness=0
       block-brace-vertical-tightness=0
+      brace-follower-vertical-tightness=1
       brace-tightness=1
       brace-vertical-tightness-closing=0
       brace-vertical-tightness=0
index e34ebbfe8330c98336745ac60edd9c2c57e4a788..c5a13403ab512da9b07398e3fa9e22491559df2d 100644 (file)
@@ -176,6 +176,7 @@ my (
     $rOpts_blank_lines_after_opening_block,
     $rOpts_block_brace_tightness,
     $rOpts_block_brace_vertical_tightness,
+    $rOpts_brace_follower_vertical_tightness,
     $rOpts_break_after_labels,
     $rOpts_break_at_old_attribute_breakpoints,
     $rOpts_break_at_old_comma_breakpoints,
@@ -1852,6 +1853,8 @@ EOM
     $rOpts_block_brace_tightness = $rOpts->{'block-brace-tightness'};
     $rOpts_block_brace_vertical_tightness =
       $rOpts->{'block-brace-vertical-tightness'};
+    $rOpts_brace_follower_vertical_tightness =
+      $rOpts->{'brace-follower-vertical-tightness'};
     $rOpts_break_after_labels = $rOpts->{'break-after-labels'};
     $rOpts_break_at_old_attribute_breakpoints =
       $rOpts->{'break-at-old-attribute-breakpoints'};
@@ -1873,8 +1876,7 @@ EOM
       $rOpts->{'closing-side-comment-maximum-text'};
     $rOpts_comma_arrow_breakpoints  = $rOpts->{'comma-arrow-breakpoints'};
     $rOpts_continuation_indentation = $rOpts->{'continuation-indentation'};
-    $rOpts_cuddled_paren_brace =
-      $rOpts->{'cuddled-paren-brace'};
+    $rOpts_cuddled_paren_brace      = $rOpts->{'cuddled-paren-brace'};
     $rOpts_delete_closing_side_comments =
       $rOpts->{'delete-closing-side-comments'};
     $rOpts_delete_old_whitespace = $rOpts->{'delete-old-whitespace'};
@@ -18461,10 +18463,24 @@ EOM
             # the indentation of a leading line like 'or do {'.
             # This doesn't work well with -icb through
             if (
-                   $block_type_to_go[$iend_1] eq 'eval'
-                && !ref( $leading_spaces_to_go[$iend_1] )
-                && !$rOpts_indent_closing_brace
-                && $tokens_to_go[$iend_2] eq '{'
+                   $block_type_to_go[$iend_1]
+                && $rOpts_brace_follower_vertical_tightness > 0
+                && (
+
+                    # -bfvt=1, allow cuddled eval chains [default]
+                    (
+                           $tokens_to_go[$iend_2] eq '{'
+                        && $block_type_to_go[$iend_1] eq 'eval'
+                        && !ref( $leading_spaces_to_go[$iend_1] )
+                        && !$rOpts_indent_closing_brace
+                    )
+
+                    # -bfvt=2, allow most brace followers [part of git #110]
+                    || (   $rOpts_brace_follower_vertical_tightness > 1
+                        && $ibeg_1 == $iend_1 )
+
+                )
+
                 && (
                     ( $type_ibeg_2 =~ /^(\&\&|\|\|)$/ )
                     || (   $type_ibeg_2 eq 'k'
diff --git a/t/snippets/bfvt.in b/t/snippets/bfvt.in
new file mode 100644 (file)
index 0000000..ee5e262
--- /dev/null
@@ -0,0 +1,34 @@
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+}
+  or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+  };
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+}
+  or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+}
+  || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+} || "";
diff --git a/t/snippets/bfvt0.par b/t/snippets/bfvt0.par
new file mode 100644 (file)
index 0000000..55472b3
--- /dev/null
@@ -0,0 +1 @@
+-bfvt=0
diff --git a/t/snippets/bfvt2.par b/t/snippets/bfvt2.par
new file mode 100644 (file)
index 0000000..947852a
--- /dev/null
@@ -0,0 +1 @@
+-bfvt=2
diff --git a/t/snippets/expect/bfvt.bfvt0 b/t/snippets/expect/bfvt.bfvt0
new file mode 100644 (file)
index 0000000..91b5b32
--- /dev/null
@@ -0,0 +1,34 @@
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+}
+  or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+  };
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+}
+  or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  }
+  || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
diff --git a/t/snippets/expect/bfvt.bfvt2 b/t/snippets/expect/bfvt.bfvt2
new file mode 100644 (file)
index 0000000..1b55694
--- /dev/null
@@ -0,0 +1,31 @@
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+} or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+};
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+} or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
diff --git a/t/snippets/expect/bfvt.def b/t/snippets/expect/bfvt.def
new file mode 100644 (file)
index 0000000..9c9cea6
--- /dev/null
@@ -0,0 +1,33 @@
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+} or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+};
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+}
+  or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  }
+  || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
diff --git a/t/snippets/expect/cpb.cpb b/t/snippets/expect/cpb.cpb
new file mode 100644 (file)
index 0000000..648c5f1
--- /dev/null
@@ -0,0 +1,8 @@
+foreach my $dir (
+    '05_lexer', '07_token', '08_regression', '11_util',
+    '13_data',  '15_transform'
+) {
+    my @perl = find_files( catdir( 't', 'data', $dir ) );
+    push @files, @perl;
+}
+
diff --git a/t/snippets/expect/cpb.def b/t/snippets/expect/cpb.def
new file mode 100644 (file)
index 0000000..ef9a855
--- /dev/null
@@ -0,0 +1,9 @@
+foreach my $dir (
+    '05_lexer', '07_token', '08_regression', '11_util',
+    '13_data',  '15_transform'
+  )
+{
+    my @perl = find_files( catdir( 't', 'data', $dir ) );
+    push @files, @perl;
+}
+
index 6ca99208bad237b71aeb98419675baae918fd383..6307b9a1ce6b555e027b2cd50c43ab2852bdacf7 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets27.t        bfvt.bfvt0
+../snippets27.t        bfvt.bfvt2
+../snippets27.t        bfvt.def
+../snippets27.t        cpb.cpb
+../snippets27.t        cpb.def
index beb1ef51e03ebb035e2fa1972e927bfb4a485599..01ed0e433f50c3105307b3dbf88620e1fabe3f04 100644 (file)
 #9 wtc.wtc7
 #10 rt144979.def
 #11 rt144979.rt144979
+#12 bfvt.bfvt0
+#13 bfvt.bfvt2
+#14 bfvt.def
+#15 cpb.cpb
+#16 cpb.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -29,6 +34,9 @@ BEGIN {
     # BEGIN SECTION 1: Parameter combinations #
     ###########################################
     $rparams = {
+        'bfvt0'    => "-bfvt=0",
+        'bfvt2'    => "-bfvt=2",
+        'cpb'      => "-cpb",
         'def'      => "",
         'dwic'     => "-wn -dwic",
         'rt144979' => "-xci -ce -lp",
@@ -46,6 +54,55 @@ BEGIN {
     ############################
     $rsources = {
 
+        'bfvt' => <<'----------',
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+}
+  or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+  };
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+}
+  or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+}
+  || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+} || "";
+----------
+
+        'cpb' => <<'----------',
+foreach my $dir (
+    '05_lexer', '07_token', '08_regression', '11_util',
+    '13_data',  '15_transform'
+  )
+{
+    my @perl = find_files( catdir( 't', 'data', $dir ) );
+    push @files, @perl;
+}
+
+----------
+
         'dwic' => <<'----------',
     skip_symbols(
         [ qw(
@@ -69,7 +126,7 @@ GetOptions(
           }
           return;
       },
-); 
+);
 
 # part 2
 {{{
@@ -645,6 +702,156 @@ GetOptions(
 
 #11...........
         },
+
+        'bfvt.bfvt0' => {
+            source => "bfvt",
+            params => "bfvt0",
+            expect => <<'#12...........',
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+}
+  or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+  };
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+}
+  or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  }
+  || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
+#12...........
+        },
+
+        'bfvt.bfvt2' => {
+            source => "bfvt",
+            params => "bfvt2",
+            expect => <<'#13...........',
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+} or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+};
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+} or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
+#13...........
+        },
+
+        'bfvt.def' => {
+            source => "bfvt",
+            params => "def",
+            expect => <<'#14...........',
+# combines with -bfvt>0
+eval {
+    require XSLoader;
+    XSLoader::load( 'Sys::Syslog', $VERSION );
+    1;
+} or do {
+    require DynaLoader;
+    push @ISA, 'DynaLoader';
+    bootstrap Sys::Syslog $VERSION;
+};
+
+# combines with -bfvt=2
+eval {
+    ( $line, $cond ) = $self->_normalize_if_elif($line);
+    1;
+}
+  or die sprintf "Error at line %d\nLine %d: %s\n%s",
+  ( $line_info->start_line_num() ) x 2, $line, $@;
+
+# stable for bfvt<2; combines for bfvt=2; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  }
+  || "";
+
+# stays combined for all bfvt; has ci
+my $domain = shift
+  || eval {
+    require Net::Domain;
+    Net::Domain::hostfqdn();
+  } || "";
+#14...........
+        },
+
+        'cpb.cpb' => {
+            source => "cpb",
+            params => "cpb",
+            expect => <<'#15...........',
+foreach my $dir (
+    '05_lexer', '07_token', '08_regression', '11_util',
+    '13_data',  '15_transform'
+) {
+    my @perl = find_files( catdir( 't', 'data', $dir ) );
+    push @files, @perl;
+}
+
+#15...........
+        },
+
+        'cpb.def' => {
+            source => "cpb",
+            params => "def",
+            expect => <<'#16...........',
+foreach my $dir (
+    '05_lexer', '07_token', '08_regression', '11_util',
+    '13_data',  '15_transform'
+  )
+{
+    my @perl = find_files( catdir( 't', 'data', $dir ) );
+    push @files, @perl;
+}
+
+#16...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};