]> git.donarmstrong.com Git - perltidy.git/commitdiff
add option -ipscl
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 26 Jun 2023 01:47:34 +0000 (18:47 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 26 Jun 2023 01:47:34 +0000 (18:47 -0700)
14 files changed:
CHANGES.md
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
t/snippets/comments.in
t/snippets/comments3.par
t/snippets/expect/comments.comments1
t/snippets/expect/comments.comments2
t/snippets/expect/comments.comments3
t/snippets/expect/comments.comments4
t/snippets/expect/comments.comments5
t/snippets/expect/comments.def
t/snippets17.t
t/snippets18.t

index a6c8ae4c51babfae0f3961b76dde5d886857175c..57f33edfdc3bbbc52eb57b4b7d71256199f3e3f8 100644 (file)
@@ -2,6 +2,13 @@
 
 ## 2023 03 09.03
 
+    - Add parameter -ipscl, or --ignore-perlcritic-side-comment-lengths. This
+      is on by default to help avoid problems due to unwanted line breaks
+      caused by long side comments beginning with '## no critic'. Perlcritic
+      users can also use the more general parameter B<-iscl> for this purpose,
+      but that parameter is off by default.  This new parameter is on by
+      default and serves as a backup in case B<-iscl> has not been set.
+
     - Issue git #121. Added parameters -xbt, or --extended-block-tightness,
       and -xbtl=s, or --extended-block-tightness-list=s, to allow
       certain small code blocks to have internal spacing controlled by
index f5cec5a84361bc023000051120193bc39633885c..228d13dbbb8c2633f91965486eb50fa1d1e603fd 100755 (executable)
@@ -1793,6 +1793,14 @@ whereas without the -iscl flag the line will be broken:
         $vmsfile =~ s/;[\d\-]*$//
           ;    # Clip off version number; we can use a newer version as well
 
+=item B<-ipscl>,  B<--ignore-perlcritic-side-comment-lengths>
+
+The parameter B<-ipscl> tells perltidy to ignore the length of side comments
+beginning with B<## no critic> when making line breaks, even if the previous
+parameter B<-iscl> has not been set.  This parameter is on by default to avoid
+allowing these special B<perlcritic> comments, which are often quite long, to
+cause an unwanted line break, and thereby making the side comment ineffective
+in controlling B<perlcritic>.
 
 =item B<-hsc>, B<--hanging-side-comments>
 
index 9c0f56a015d629552191b18804de9ac7d96fe71d..35436e7c650f1f8e5b5f7a42f827f66445acdd42 100644 (file)
@@ -3243,34 +3243,35 @@ sub generate_options {
     ########################################
     $category = 4;    # Comment controls
     ########################################
-    $add_option->( 'closing-side-comment-else-flag',    'csce', '=i' );
-    $add_option->( 'closing-side-comment-interval',     'csci', '=i' );
-    $add_option->( 'closing-side-comment-list',         'cscl', '=s' );
-    $add_option->( 'closing-side-comment-maximum-text', 'csct', '=i' );
-    $add_option->( 'closing-side-comment-prefix',       'cscp', '=s' );
-    $add_option->( 'closing-side-comment-warnings',     'cscw', '!' );
-    $add_option->( 'closing-side-comments',             'csc',  '!' );
-    $add_option->( 'closing-side-comments-balanced',    'cscb', '!' );
-    $add_option->( 'code-skipping',                     'cs',   '!' );
-    $add_option->( 'code-skipping-begin',               'csb',  '=s' );
-    $add_option->( 'code-skipping-end',                 'cse',  '=s' );
-    $add_option->( 'format-skipping',                   'fs',   '!' );
-    $add_option->( 'format-skipping-begin',             'fsb',  '=s' );
-    $add_option->( 'format-skipping-end',               'fse',  '=s' );
-    $add_option->( 'hanging-side-comments',             'hsc',  '!' );
-    $add_option->( 'indent-block-comments',             'ibc',  '!' );
-    $add_option->( 'indent-spaced-block-comments',      'isbc', '!' );
-    $add_option->( 'fixed-position-side-comment',       'fpsc', '=i' );
-    $add_option->( 'minimum-space-to-comment',          'msc',  '=i' );
-    $add_option->( 'non-indenting-braces',              'nib',  '!' );
-    $add_option->( 'non-indenting-brace-prefix',        'nibp', '=s' );
-    $add_option->( 'outdent-long-comments',             'olc',  '!' );
-    $add_option->( 'outdent-static-block-comments',     'osbc', '!' );
-    $add_option->( 'static-block-comment-prefix',       'sbcp', '=s' );
-    $add_option->( 'static-block-comments',             'sbc',  '!' );
-    $add_option->( 'static-side-comment-prefix',        'sscp', '=s' );
-    $add_option->( 'static-side-comments',              'ssc',  '!' );
-    $add_option->( 'ignore-side-comment-lengths',       'iscl', '!' );
+    $add_option->( 'closing-side-comment-else-flag',         'csce', '=i' );
+    $add_option->( 'closing-side-comment-interval',          'csci', '=i' );
+    $add_option->( 'closing-side-comment-list',              'cscl', '=s' );
+    $add_option->( 'closing-side-comment-maximum-text',      'csct', '=i' );
+    $add_option->( 'closing-side-comment-prefix',            'cscp', '=s' );
+    $add_option->( 'closing-side-comment-warnings',          'cscw', '!' );
+    $add_option->( 'closing-side-comments',                  'csc',  '!' );
+    $add_option->( 'closing-side-comments-balanced',         'cscb', '!' );
+    $add_option->( 'code-skipping',                          'cs',   '!' );
+    $add_option->( 'code-skipping-begin',                    'csb',  '=s' );
+    $add_option->( 'code-skipping-end',                      'cse',  '=s' );
+    $add_option->( 'format-skipping',                        'fs',   '!' );
+    $add_option->( 'format-skipping-begin',                  'fsb',  '=s' );
+    $add_option->( 'format-skipping-end',                    'fse',  '=s' );
+    $add_option->( 'hanging-side-comments',                  'hsc',  '!' );
+    $add_option->( 'indent-block-comments',                  'ibc',  '!' );
+    $add_option->( 'indent-spaced-block-comments',           'isbc', '!' );
+    $add_option->( 'fixed-position-side-comment',            'fpsc', '=i' );
+    $add_option->( 'minimum-space-to-comment',               'msc',  '=i' );
+    $add_option->( 'non-indenting-braces',                   'nib',  '!' );
+    $add_option->( 'non-indenting-brace-prefix',             'nibp', '=s' );
+    $add_option->( 'outdent-long-comments',                  'olc',  '!' );
+    $add_option->( 'outdent-static-block-comments',          'osbc', '!' );
+    $add_option->( 'static-block-comment-prefix',            'sbcp', '=s' );
+    $add_option->( 'static-block-comments',                  'sbc',  '!' );
+    $add_option->( 'static-side-comment-prefix',             'sscp', '=s' );
+    $add_option->( 'static-side-comments',                   'ssc',  '!' );
+    $add_option->( 'ignore-side-comment-lengths',            'iscl', '!' );
+    $add_option->( 'ignore-perlcritic-side-comment-lengths', 'ipcl', '!' );
 
     ########################################
     $category = 5;    # Linebreak controls
@@ -3559,6 +3560,7 @@ sub generate_options {
       function-paren-vertical-alignment
       fuzzy-line-length
       hanging-side-comments
+      ignore-perlcritic-side-comment-lengths
       indent-block-comments
       indent-columns=4
       iterations=1
index 19e63447eaa1ec8b161b5d4397dddf1ca3deacad..6b5a692241b6d5ebcc0749dc837f2a9b2e744076 100644 (file)
@@ -209,6 +209,7 @@ my (
     $rOpts_fuzzy_line_length,
     $rOpts_ignore_old_breakpoints,
     $rOpts_ignore_side_comment_lengths,
+    $rOpts_ignore_perlcritic_side_comment_lengths,
     $rOpts_indent_closing_brace,
     $rOpts_indent_columns,
     $rOpts_indent_only,
@@ -2444,6 +2445,8 @@ sub initialize_global_option_vars {
     $rOpts_ignore_old_breakpoints = $rOpts->{'ignore-old-breakpoints'};
     $rOpts_ignore_side_comment_lengths =
       $rOpts->{'ignore-side-comment-lengths'};
+    $rOpts_ignore_perlcritic_side_comment_lengths =
+      $rOpts->{'ignore-perlcritic-side-comment-lengths'};
     $rOpts_indent_closing_brace     = $rOpts->{'indent-closing-brace'};
     $rOpts_indent_columns           = $rOpts->{'indent-columns'};
     $rOpts_indent_only              = $rOpts->{'indent-only'};
@@ -9184,12 +9187,43 @@ sub store_token {
             $item->[_TOKEN_] = $token;
         }
 
-        # Mark length of side comments as just 1 if sc lengths are ignored
-        if ( $rOpts_ignore_side_comment_lengths
-            && ( !$CODE_type || $CODE_type eq 'HSC' ) )
+        my $ignore_sc_length = $rOpts_ignore_side_comment_lengths;
+
+        # Ignore length of '## no critic' comments if requested
+        if (   $rOpts_ignore_perlcritic_side_comment_lengths
+            && $token_length > 10
+            && substr( $token, 1, 1 ) eq '#'
+            && $token =~ /^##\s*no\s+critic\b/ )
         {
+
+            # Is it a side comment or a block comment?
+            if ( $Ktoken_vars > $Kfirst_old ) {
+
+                # This is a side comment. If we do not ignore its length, and
+                # -iscl has not been set, then the line could be broken and
+                # perlcritic will complain. So this is essential:
+                $ignore_sc_length ||= 1;
+
+                # It would be a good idea to also make this behave like a
+                # static side comment, but this is not essential and would
+                # change existing formatting.  So we will leave it to the user
+                # to set -ssc if desired.
+            }
+            else {
+
+                # This is a full-line (block) comment.
+                # It would be a good idea to make this behave like a static
+                # block comment, but this is not essential and would change
+                # existing formatting.  So we will leave it to the user to
+                # set -sbc if desired
+            }
+        }
+
+        # Set length of ignored side comments as just 1
+        if ( $ignore_sc_length && ( !$CODE_type || $CODE_type eq 'HSC' ) ) {
             $token_length = 1;
         }
+
         my $seqno = $seqno_stack{ $depth_next - 1 };
         if ( defined($seqno) ) {
             $self->[_rblank_and_comment_count_]->{$seqno} += 1
index 261c4db88b9a6c64ab9fe3d10150a666a570a40c..0c34f161e70a4929f6be25897390f853b17db99b 100644 (file)
@@ -65,6 +65,10 @@ sub macro_get_names { #
                 1, 4, 6, 4, 1,);
 #>>
 
+    local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+    ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 
 # some blank lines follow
index a7e7943e8762acd0dbbebb9e1e745b5f4f2ccc78..c3b787cb2b3541ab7c1ec32988c757c07e50fe88 100644 (file)
@@ -1,2 +1,4 @@
-# testing --maximum-consecutive-blank-lines=2 and --indent-spaced-block-comments --no-format-skipping
--mbl=2 -isbc -nfs
+--maximum-consecutive-blank-lines=2   # -mbl=2
+--indent-spaced-block-comments        # -isbc
+--no-format-skipping                  # -nfs
+--noignore-perlcritic-side-comment-lengths # -nipscl
index aedc7d89120a8d085a78f71f4b7aacb78fa3f2d0..66b7fdfe9dcdb534d0ceb2152ea04af16b25e8ba 100644 (file)
@@ -68,6 +68,10 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 # some blank lines follow
 
 =pod
index cddf93a82bf669ed806fbb995ae92aa44cc75fa7..e401a53e8cef953f4f1c887966bd351de7294b4b 100644 (file)
@@ -50,6 +50,8 @@ sub macro_get_names {          #
 
 my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;          ## no critic (Variables::ProhibitPackageVars)
+
 
 __END__
 
index 732a5d49092da572a38af1a4d5dd14b1d5a188b3..15191c2eb10f30f86a3042ff1bc2143d2aff52b8 100644 (file)
@@ -68,6 +68,11 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level =
+  $Test::Builder::Level + 1;    ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 # some blank lines follow
 
index f6139ec1ae988530b233b6bf1ca92bad1b0e1d8e..962adf74623a141ccc082dc96c90e5fd3302f4db 100644 (file)
@@ -74,6 +74,10 @@ sub macro_get_names {    #
                 1, 4, 6, 4, 1,);
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;    ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 
 # some blank lines follow
index df9774d9ff20b52e9b43f6ed50e8de77d2c2166c..b7f0543766ee04ea372c903a5797f5e1f509d8f6 100644 (file)
@@ -62,6 +62,10 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 # some blank lines follow
 
 =pod
index 4f2440e0e50087c65daf05e4216a773d40b269f4..be8db91130745a49a1209cdb80dde66cc6d3d14c 100644 (file)
@@ -67,6 +67,10 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;    ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 # some blank lines follow
 
 =pod
index 033da5f9b17710b1c642118a154f085cbcabdb88..16ea5ce48d242fd2461fb4588aa68027f9786dd9 100644 (file)
@@ -52,8 +52,10 @@ BEGIN {
 -msc=10 -dbc -dp
 ----------
         'comments3' => <<'----------',
-# testing --maximum-consecutive-blank-lines=2 and --indent-spaced-block-comments --no-format-skipping
--mbl=2 -isbc -nfs
+--maximum-consecutive-blank-lines=2   # -mbl=2
+--indent-spaced-block-comments        # -isbc
+--no-format-skipping                  # -nfs
+--noignore-perlcritic-side-comment-lengths # -nipscl
 ----------
         'comments4' => <<'----------',
 # testing --keep-old-blank-lines=2 [=all] and 
@@ -172,6 +174,10 @@ sub macro_get_names { #
                 1, 4, 6, 4, 1,);
 #>>
 
+    local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+    ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 
 # some blank lines follow
@@ -446,6 +452,10 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 # some blank lines follow
 
 =pod
@@ -522,6 +532,8 @@ sub macro_get_names {          #
 
 my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;          ## no critic (Variables::ProhibitPackageVars)
+
 
 __END__
 
@@ -608,6 +620,11 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level =
+  $Test::Builder::Level + 1;    ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 # some blank lines follow
 
@@ -711,6 +728,10 @@ sub macro_get_names {    #
                 1, 4, 6, 4, 1,);
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;    ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 
 # some blank lines follow
@@ -809,6 +830,10 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;    ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 # some blank lines follow
 
 =pod
index 2dec3547ce344baf570d0c6004e5a76eda4bc69d..6f532b0553df859d5c4b1f32a3851fcf23f639ff 100644 (file)
@@ -184,6 +184,10 @@ sub macro_get_names { #
                 1, 4, 6, 4, 1,);
 #>>
 
+    local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+    ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 
 
 # some blank lines follow
@@ -430,6 +434,10 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );
 
 #>>
 
+local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
 # some blank lines follow
 
 =pod