From: Steve Hancock Date: Mon, 26 Oct 2020 15:41:37 +0000 (-0700) Subject: prevent breaking package names with trailing dashes X-Git-Tag: 20201001.03~38 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9234b4e5469001f7c6de393cb1fcae617ea261f4;p=perltidy.git prevent breaking package names with trailing dashes --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 1192a4b0..c788c5ca 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -3227,6 +3227,11 @@ EOM } } + # keep 'bareword-' together, but only if there is no space between + # the word and dash. Do not keep together if there is a space. + # example 'use perl6-alpha' + elsif ( $type eq 'w' && $next_type eq 'm' ) { $bond_str = NO_BREAK } + # Breaking before a ? before a quote can cause trouble if # they are not separated by a blank. # Example: a syntax error occurs if you break before the ? here diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index fe4972a1..43f7cfb9 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -3202,6 +3202,17 @@ EOM # treat bare word followed by open paren like qw( if ( $next_nonblank_token eq '(' ) { + + # TODO: This works, but if $tok eq 'prototype' then we + # should really parse the prototype separately here so + # that we have its properties. This requires updating + # do_scan_sub to keep the subname available until we + # see the opening brace. So something like + # if ($tok eq 'prototype' ) {scan_prototype()} + # else { + + # All other attribute lists must be parsed as quotes + # (see 'signatures.t' for good examples) $in_quote = $quote_items{'q'}; $allowed_quote_modifiers = $quote_modifiers{'q'}; $type = 'q'; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 1551c05c..866efc11 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,10 +2,30 @@ =over 4 +=item b + +In stress testing perltidy with the -extrude option, the following test snippet + + use perl6-alpha; + +was broken into sepate lines + + use + perl6 + - + alpha + ; + +A rule was added to prevent breaking around a dash separating two barewords. +Rerunning gives + + use + perl6-alpha + ; =item b -In random testing with the following test snippet with the -extrude option +In stress testing perltidy with the -extrude option, using the following test snippet my %var; { @@ -19,7 +39,7 @@ In random testing with the following test snippet with the -extrude option $var{m} = 1; } -a syntax error was created in the resulting file when newlines were placed +a syntax error was created when newlines were placed before or after the dashes. It is necessary to always keep a dash on the same line with its surrounding tokens. A rule was added to do this. The new 'extruded' result for the above snippet is: