From: Steve Hancock Date: Sat, 6 Feb 2021 16:32:02 +0000 (-0800) Subject: add rule to avoid welding at some barewords X-Git-Tag: 20210402~60 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6b1f44a6e3c1d9e25de5e5cce3ffdd6d47c4abac;p=perltidy.git add rule to avoid welding at some barewords --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index e2cd6847..be081297 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6702,6 +6702,15 @@ sub is_excluded_weld { return $match; } +# types needed for welding RULE 6 +my %type_ok_after_bareword; + +BEGIN { + + my @q = qw# => -> { ( [ #; + @type_ok_after_bareword{@q} = (1) x scalar(@q); +} + sub weld_nested_containers { my ($self) = @_; @@ -6989,6 +6998,29 @@ sub weld_nested_containers { $do_not_weld ||= $self->is_excluded_weld( $Kinner_opening, 0 ); } + # DO-NOT-WELD RULE 6: Do not weld to a container which is followed on + # the same line by an unknown bareword token. This can cause + # blinkers (cases b626, b611). + if ( !$do_not_weld ) { + my $Knext_io = $self->K_next_nonblank($Kinner_opening); + next unless ( defined($Knext_io) ); + my $iline_io_next = $rLL->[$Knext_io]->[_LINE_INDEX_]; + if ( $iline_io_next == $iline_io ) { + my $type_io_next = $rLL->[$Knext_io]->[_TYPE_]; + + # Note: may need to eventually also include other types here, + # such as 'Z' and 'Y': if ($type_io_next =~ /^[ZYw]$/) { + if ( $type_io_next eq 'w' ) { + my $Knext_io2 = $self->K_next_nonblank($Knext_io); + next unless ( defined($Knext_io) ); + my $type_io_next2 = $rLL->[$Knext_io2]->[_TYPE_]; + if ( !$type_ok_after_bareword{$type_io_next2} ) { + $do_not_weld = 1; + } + } + } + } + if ($do_not_weld) { # After neglecting a pair, we start measuring from start of point io diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 60ea105d..25832316 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,16 @@ =over 4 +=item B + +A rule was added to prevent certain rare blinking states involving welding. +The rule is that if an opening container is immediately followed by a bareword which is +unknown, a weld will be avoided. + +The following cases were fixed with this update: b611 b626. + +6 Feb 2021. + =item B This update adds a new variable which indicates if a container is permanently