## 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
$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>
########################################
$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
function-paren-vertical-alignment
fuzzy-line-length
hanging-side-comments
+ ignore-perlcritic-side-comment-lengths
indent-block-comments
indent-columns=4
iterations=1
$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,
$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'};
$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
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
-# 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
#>>
+local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
=pod
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__
#>>
+local $Test::Builder::Level =
+ $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
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
#>>
+local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
=pod
#>>
+local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
=pod
-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
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
#>>
+local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
=pod
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__
#>>
+local $Test::Builder::Level =
+ $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
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
#>>
+local $Test::Builder::Level = $Test::Builder::Level + 1; ## no critic (Variables::ProhibitPackageVars)
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
=pod
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
#>>
+local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
+
# some blank lines follow
=pod