]> git.donarmstrong.com Git - perltidy.git/commitdiff
document -olbs=n and add test snippet
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 24 Jan 2019 00:32:33 +0000 (16:32 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 24 Jan 2019 00:32:33 +0000 (16:32 -0800)
bin/perltidy
docs/perltidy.html
t/snippets/expect/olbs.def [new file with mode: 0644]
t/snippets/expect/olbs.olbs0 [new file with mode: 0644]
t/snippets/expect/olbs.olbs2 [new file with mode: 0644]
t/snippets/olbs.in [new file with mode: 0644]
t/snippets/olbs0.par [new file with mode: 0644]
t/snippets/olbs2.par [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets15.t

index 66dee3d1c251b73e5c8fccf48dd8c66c8bab96a5..db794dfa93a76ab18b58aa9e867026fc74fdc0dd 100755 (executable)
@@ -2936,6 +2936,87 @@ after the -pbp parameter.  For example,
 
 =back
 
+=item  One-line blocks 
+
+There are a few points to note regarding one-line blocks.  A one-line
+block is something like this,
+
+       if ($x > 0) { $y = 1 / $x }  
+
+where the contents within the curly braces is short enough to fit
+on a single line.
+
+With few exceptions, perltidy retains existing one-line blocks, if it
+is possible within the line-length constraint, but it does not attempt
+to form new ones.  In other words, perltidy will try to follow the
+one-line block style of the input file.
+
+If an existing one-line block is longer than the maximum line length,
+however, it will be broken into multiple lines.  When this happens, perltidy
+checks for and adds any optional terminating semicolon (unless the B<-nasc>
+option is used) if the block is a code block.  
+
+The main exception is that perltidy will attempt to form new one-line
+blocks following the keywords C<map>, C<eval>, and C<sort>, because
+these code blocks are often small and most clearly displayed in a single
+line.
+
+One-line block rules can conflict with the cuddled-else option.  When
+the cuddled-else option is used, perltidy retains existing one-line
+blocks, even if they do not obey cuddled-else formatting.
+
+Occasionally, when one-line blocks get broken because they exceed the
+available line length, the formatting will violate the requested brace style.
+If this happens, reformatting the script a second time should correct
+the problem.
+
+Sometimes it might be desirable to convert a script to have one-line blocks
+whenever possible.  Although there is currently no flag for this, a simple
+workaround is to execute perltidy twice, once with the flag B<-noadd-newlines>
+and then once again with normal parameters, like this:  
+
+     cat infile | perltidy -nanl | perltidy >outfile
+
+When executed on this snippet
+
+    if ( $? == -1 ) {
+        die "failed to execute: $!\n";
+    }
+    if ( $? == -1 ) {
+        print "Had enough.\n";
+        die "failed to execute: $!\n";
+    }
+
+the result is
+
+    if ( $? == -1 ) { die "failed to execute: $!\n"; }
+    if ( $? == -1 ) {
+        print "Had enough.\n";
+        die "failed to execute: $!\n";
+    }
+
+This shows that blocks with a single statement become one-line blocks.
+
+
+=item B<-olbs=n>, B<--one-line-block-semicolons=n>
+
+This flag controls the placement of semicolons at the end of one-line blocks.
+Semicolons are optional before a closing block brace, and frequently they are
+omitted at the end of a one-line block containing just a single statement.
+By default, perltidy follows the input file regarding these semicolons, 
+but this behavior can be controlled by this flag.  The values of n are:
+
+  n=0 remove terminal semicolons in one-line blocks having a single statement
+  n=1 stable; keep input file placement of terminal semicolons [DEFAULT ]
+  n=2 add terminal semicolons in all one-line blocks
+
+Note that the B<n=2> option has no effect if adding semicolons is prohibited
+with the B<-nasc> flag.  Also not that while B<n=2> adds missing semicolons to
+all one-line blocks, regardless of complexity, the B<n=0> option only removes
+ending semicolons which terminate one-line blocks containing just one
+semicolon.  So these two options are not exact inverses.
+
+
 =head2 Controlling Vertical Alignment
 
 Vertical alignment refers to lining up certain symbols in list of consecutive
@@ -3167,68 +3248,6 @@ to make the minimum number of one-line blocks.
 Another use for B<--mangle> is to combine it with B<-dac> to reduce
 the file size of a perl script.
 
-=item  One-line blocks 
-
-There are a few points to note regarding one-line blocks.  A one-line
-block is something like this,
-
-       if ($x > 0) { $y = 1 / $x }  
-
-where the contents within the curly braces is short enough to fit
-on a single line.
-
-With few exceptions, perltidy retains existing one-line blocks, if it
-is possible within the line-length constraint, but it does not attempt
-to form new ones.  In other words, perltidy will try to follow the
-one-line block style of the input file.
-
-If an existing one-line block is longer than the maximum line length,
-however, it will be broken into multiple lines.  When this happens, perltidy
-checks for and adds any optional terminating semicolon (unless the B<-nasc>
-option is used) if the block is a code block.  
-
-The main exception is that perltidy will attempt to form new one-line
-blocks following the keywords C<map>, C<eval>, and C<sort>, because
-these code blocks are often small and most clearly displayed in a single
-line.
-
-One-line block rules can conflict with the cuddled-else option.  When
-the cuddled-else option is used, perltidy retains existing one-line
-blocks, even if they do not obey cuddled-else formatting.
-
-Occasionally, when one-line blocks get broken because they exceed the
-available line length, the formatting will violate the requested brace style.
-If this happens, reformatting the script a second time should correct
-the problem.
-
-Sometimes it might be desirable to convert a script to have one-line blocks
-whenever possible.  Although there is currently no flag for this, a simple
-workaround is to execute perltidy twice, once with the flag B<-noadd-newlines>
-and then once again with normal parameters, like this:  
-
-     cat infile | perltidy -nanl | perltidy >outfile
-
-When executed on this snippet
-
-    if ( $? == -1 ) {
-        die "failed to execute: $!\n";
-    }
-    if ( $? == -1 ) {
-        print "Had enough.\n";
-        die "failed to execute: $!\n";
-    }
-
-the result is
-
-    if ( $? == -1 ) { die "failed to execute: $!\n"; }
-    if ( $? == -1 ) {
-        print "Had enough.\n";
-        die "failed to execute: $!\n";
-    }
-
-This shows that blocks with a single statement become one-line blocks.
-
-
 =item  Debugging 
 
 The following flags are available for debugging:
index 37420dffeb8c1905769eb48d57a1dd50fa940abd..f2f0b8732313cb7d093b30edda3716344d525f1a 100644 (file)
 </dd>
 </dl>
 
+<dl>
+
+<dt id="One-line-blocks">One-line blocks</dt>
+<dd>
+
+<p>There are a few points to note regarding one-line blocks. A one-line block is something like this,</p>
+
+<pre><code>        if ($x &gt; 0) { $y = 1 / $x }  </code></pre>
+
+<p>where the contents within the curly braces is short enough to fit on a single line.</p>
+
+<p>With few exceptions, perltidy retains existing one-line blocks, if it is possible within the line-length constraint, but it does not attempt to form new ones. In other words, perltidy will try to follow the one-line block style of the input file.</p>
+
+<p>If an existing one-line block is longer than the maximum line length, however, it will be broken into multiple lines. When this happens, perltidy checks for and adds any optional terminating semicolon (unless the <b>-nasc</b> option is used) if the block is a code block.</p>
+
+<p>The main exception is that perltidy will attempt to form new one-line blocks following the keywords <code>map</code>, <code>eval</code>, and <code>sort</code>, because these code blocks are often small and most clearly displayed in a single line.</p>
+
+<p>One-line block rules can conflict with the cuddled-else option. When the cuddled-else option is used, perltidy retains existing one-line blocks, even if they do not obey cuddled-else formatting.</p>
+
+<p>Occasionally, when one-line blocks get broken because they exceed the available line length, the formatting will violate the requested brace style. If this happens, reformatting the script a second time should correct the problem.</p>
+
+<p>Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag <b>-noadd-newlines</b> and then once again with normal parameters, like this:</p>
+
+<pre><code>     cat infile | perltidy -nanl | perltidy &gt;outfile</code></pre>
+
+<p>When executed on this snippet</p>
+
+<pre><code>    if ( $? == -1 ) {
+        die &quot;failed to execute: $!\n&quot;;
+    }
+    if ( $? == -1 ) {
+        print &quot;Had enough.\n&quot;;
+        die &quot;failed to execute: $!\n&quot;;
+    }</code></pre>
+
+<p>the result is</p>
+
+<pre><code>    if ( $? == -1 ) { die &quot;failed to execute: $!\n&quot;; }
+    if ( $? == -1 ) {
+        print &quot;Had enough.\n&quot;;
+        die &quot;failed to execute: $!\n&quot;;
+    }</code></pre>
+
+<p>This shows that blocks with a single statement become one-line blocks.</p>
+
+</dd>
+<dt id="olbs-n---one-line-block-semicolons-n"><b>-olbs=n</b>, <b>--one-line-block-semicolons=n</b></dt>
+<dd>
+
+<p>This flag controls the placement of semicolons at the end of one-line blocks. Semicolons are optional before a closing block brace, and frequently they are omitted at the end of a one-line block containing just a single statement. By default, perltidy follows the input file regarding these semicolons, but this behavior can be controlled by this flag. The values of n are:</p>
+
+<pre><code>  n=0 remove terminal semicolons in one-line blocks having a single statement
+  n=1 stable; keep input file placement of terminal semicolons [DEFAULT ]
+  n=2 add terminal semicolons in all one-line blocks</code></pre>
+
+<p>Note that the <b>n=2</b> option has no effect if adding semicolons is prohibited with the <b>-nasc</b> flag. Also not that while <b>n=2</b> adds missing semicolons to all one-line blocks, regardless of complexity, the <b>n=0</b> option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses.</p>
+
+</dd>
+</dl>
+
 <h2 id="Controlling-Vertical-Alignment">Controlling Vertical Alignment</h2>
 
 <p>Vertical alignment refers to lining up certain symbols in list of consecutive similar lines to improve readability. For example, the &quot;fat commas&quot; are aligned in the following statement:</p>
 
 <p>Another use for <b>--mangle</b> is to combine it with <b>-dac</b> to reduce the file size of a perl script.</p>
 
-</dd>
-<dt id="One-line-blocks">One-line blocks</dt>
-<dd>
-
-<p>There are a few points to note regarding one-line blocks. A one-line block is something like this,</p>
-
-<pre><code>        if ($x &gt; 0) { $y = 1 / $x }  </code></pre>
-
-<p>where the contents within the curly braces is short enough to fit on a single line.</p>
-
-<p>With few exceptions, perltidy retains existing one-line blocks, if it is possible within the line-length constraint, but it does not attempt to form new ones. In other words, perltidy will try to follow the one-line block style of the input file.</p>
-
-<p>If an existing one-line block is longer than the maximum line length, however, it will be broken into multiple lines. When this happens, perltidy checks for and adds any optional terminating semicolon (unless the <b>-nasc</b> option is used) if the block is a code block.</p>
-
-<p>The main exception is that perltidy will attempt to form new one-line blocks following the keywords <code>map</code>, <code>eval</code>, and <code>sort</code>, because these code blocks are often small and most clearly displayed in a single line.</p>
-
-<p>One-line block rules can conflict with the cuddled-else option. When the cuddled-else option is used, perltidy retains existing one-line blocks, even if they do not obey cuddled-else formatting.</p>
-
-<p>Occasionally, when one-line blocks get broken because they exceed the available line length, the formatting will violate the requested brace style. If this happens, reformatting the script a second time should correct the problem.</p>
-
-<p>Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag <b>-noadd-newlines</b> and then once again with normal parameters, like this:</p>
-
-<pre><code>     cat infile | perltidy -nanl | perltidy &gt;outfile</code></pre>
-
-<p>When executed on this snippet</p>
-
-<pre><code>    if ( $? == -1 ) {
-        die &quot;failed to execute: $!\n&quot;;
-    }
-    if ( $? == -1 ) {
-        print &quot;Had enough.\n&quot;;
-        die &quot;failed to execute: $!\n&quot;;
-    }</code></pre>
-
-<p>the result is</p>
-
-<pre><code>    if ( $? == -1 ) { die &quot;failed to execute: $!\n&quot;; }
-    if ( $? == -1 ) {
-        print &quot;Had enough.\n&quot;;
-        die &quot;failed to execute: $!\n&quot;;
-    }</code></pre>
-
-<p>This shows that blocks with a single statement become one-line blocks.</p>
-
 </dd>
 <dt id="Debugging">Debugging</dt>
 <dd>
 
 <p>You forgot a &#39;=back&#39; before &#39;=head2&#39;</p>
 
+</dd>
+<dt id="Around-line-2939">Around line 2939:</dt>
+<dd>
+
+<p>&#39;=item&#39; outside of any &#39;=over&#39;</p>
+
+</dd>
+<dt id="Around-line-3020">Around line 3020:</dt>
+<dd>
+
+<p>You forgot a &#39;=back&#39; before &#39;=head2&#39;</p>
+
 </dd>
 </dl>
 
diff --git a/t/snippets/expect/olbs.def b/t/snippets/expect/olbs.def
new file mode 100644 (file)
index 0000000..1a37af3
--- /dev/null
@@ -0,0 +1,6 @@
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
diff --git a/t/snippets/expect/olbs.olbs0 b/t/snippets/expect/olbs.olbs0
new file mode 100644 (file)
index 0000000..0d708c6
--- /dev/null
@@ -0,0 +1,6 @@
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
diff --git a/t/snippets/expect/olbs.olbs2 b/t/snippets/expect/olbs.olbs2
new file mode 100644 (file)
index 0000000..fe2048b
--- /dev/null
@@ -0,0 +1,6 @@
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
diff --git a/t/snippets/olbs.in b/t/snippets/olbs.in
new file mode 100644 (file)
index 0000000..1a37af3
--- /dev/null
@@ -0,0 +1,6 @@
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
diff --git a/t/snippets/olbs0.par b/t/snippets/olbs0.par
new file mode 100644 (file)
index 0000000..9e2d752
--- /dev/null
@@ -0,0 +1 @@
+-olbs=0
diff --git a/t/snippets/olbs2.par b/t/snippets/olbs2.par
new file mode 100644 (file)
index 0000000..99bc452
--- /dev/null
@@ -0,0 +1 @@
+-olbs=2
index 4a4fc6e81b21b420b8f9f901982042baecfaa2de..24cd258b4731ced9cf9f863c0e1136398a97b2a3 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets15.t        olbs.def
+../snippets15.t        olbs.olbs0
+../snippets15.t        olbs.olbs2
index 21c705e8a714bdbb65210048c11157527783ded4..97c28756134d6bb643af7e51cd53b8a930ec89c2 100644 (file)
@@ -3,6 +3,9 @@
 # Contents:
 #1 gnu5.gnu
 #2 wngnu1.def
+#3 olbs.def
+#4 olbs.olbs0
+#5 olbs.olbs2
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -20,8 +23,10 @@ BEGIN {
     # BEGIN SECTION 1: Parameter combinations #
     ###########################################
     $rparams = {
-        'def' => "",
-        'gnu' => "-gnu",
+        'def'   => "",
+        'gnu'   => "-gnu",
+        'olbs0' => "-olbs=0",
+        'olbs2' => "-olbs=2",
     };
 
     ############################
@@ -39,6 +44,15 @@ BEGIN {
           ;
 ----------
 
+        'olbs' => <<'----------',
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
+----------
+
         'wngnu1' => <<'----------',
     # test with -wn -gnu
     foreach my $parameter (
@@ -102,6 +116,45 @@ BEGIN {
     }
 #2...........
         },
+
+        'olbs.def' => {
+            source => "olbs",
+            params => "def",
+            expect => <<'#3...........',
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
+#3...........
+        },
+
+        'olbs.olbs0' => {
+            source => "olbs",
+            params => "olbs0",
+            expect => <<'#4...........',
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked" }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }
+for $x ( 1, 2 ) { s/(.*)/+$1/ }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
+#4...........
+        },
+
+        'olbs.olbs2' => {
+            source => "olbs",
+            params => "olbs2",
+            expect => <<'#5...........',
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }
+for $x ( 1, 2 ) { s/(.*)/+$1/; }    # side comment
+if ( $editlblk eq 1 ) { $editlblk = "on"; $editlblkchecked = "checked"; }
+#5...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};