From: Steve Hancock Date: Thu, 24 Sep 2020 22:35:47 +0000 (-0700) Subject: fixed incorrect log entry for indentation disagreement X-Git-Tag: 20201001~11 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3d40545256baa5c42296dca3dfcf35850009b9b9;p=perltidy.git fixed incorrect log entry for indentation disagreement --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 54d68a81..f110174a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -246,10 +246,12 @@ BEGIN { _first_embedded_tab_at_ => $i++, _last_embedded_tab_at_ => $i++, - _first_tabbing_disagreement_ => $i++, - _last_tabbing_disagreement_ => $i++, - _tabbing_disagreement_count_ => $i++, - _in_tabbing_disagreement_ => $i++, + _first_tabbing_disagreement_ => $i++, + _last_tabbing_disagreement_ => $i++, + _tabbing_disagreement_count_ => $i++, + _in_tabbing_disagreement_ => $i++, + _first_brace_tabbing_disagreement_ => $i++, + _in_brace_tabbing_disagreement_ => $i++, _saw_VERSION_in_this_file_ => $i++, _saw_END_or_DATA_ => $i++, @@ -5959,15 +5961,37 @@ sub wrapup { my $last_tabbing_disagreement = $self->[_last_tabbing_disagreement_]; my $tabbing_disagreement_count = $self->[_tabbing_disagreement_count_]; my $in_tabbing_disagreement = $self->[_in_tabbing_disagreement_]; + if ($first_tabbing_disagreement) { write_logfile_entry( "First indentation disagreement seen at input line $first_tabbing_disagreement\n" ); } + + my $first_btd = $self->[_first_brace_tabbing_disagreement_]; + if ($first_btd) { + my $msg = +"First closing brace indentation disagreement started at input line $first_btd\n"; + write_logfile_entry($msg); + + # leave a hint in the .ERR file if there was a brace error + if ( get_saw_brace_error() ) { warning("NOTE: $msg") } + } + + my $in_btd = $self->[_in_brace_tabbing_disagreement_]; + if ($in_btd) { + my $msg = +"Ending with brace indentation disagreement which started at input line $in_btd\n"; + write_logfile_entry($msg); + + # leave a hint in the .ERR file if there was a brace error + if ( get_saw_brace_error() ) { warning("NOTE: $msg") } + } + if ($in_tabbing_disagreement) { - write_logfile_entry( -"Ending with indentation disagreement which started at input line $in_tabbing_disagreement\n" - ); + my $msg = +"Ending with indentation disagreement which started at input line $in_tabbing_disagreement\n"; + write_logfile_entry($msg); } else { @@ -5981,6 +6005,7 @@ sub wrapup { write_logfile_entry("No indentation disagreement seen\n"); } } + if ($first_tabbing_disagreement) { write_logfile_entry( "Note: Indentation disagreement detection is not accurate for outdenting and -lp.\n" @@ -7977,9 +8002,8 @@ sub copy_token_as_type { # compare input/output indentation except for continuation lines # (because they have an unknown amount of initial blank space) # and lines which are quotes (because they may have been outdented) - my $structural_indentation_level = $rLL->[$K_first]->[_LEVEL_]; - $self->compare_indentation_levels( $guessed_indentation_level, - $structural_indentation_level, $input_line_number ) + $self->compare_indentation_levels( $K_first, $guessed_indentation_level, + $input_line_number ) unless ( $is_hanging_side_comment || $rtok_first->[_CI_LEVEL_] > 0 || $guessed_indentation_level == 0 @@ -18970,15 +18994,35 @@ sub compare_indentation_levels { # this can be very useful for debugging a script which has an extra # or missing brace. - my ( $self, $guessed_indentation_level, $structural_indentation_level, - $line_number ) - = @_; + my ( $self, $K_first, $guessed_indentation_level, $line_number ) = @_; + return unless ( defined($K_first) ); + + my $rLL = $self->[_rLL_]; + + my $structural_indentation_level = $rLL->[$K_first]->[_LEVEL_]; + my $radjusted_levels = $self->[_radjusted_levels_]; + if ( defined($radjusted_levels) && @{$radjusted_levels} == @{$rLL} ) { + $structural_indentation_level = $radjusted_levels->[$K_first]; + } + + my $is_closing_block = $rLL->[$K_first]->[_TYPE_] eq '}' + && $rLL->[$K_first]->[_BLOCK_TYPE_]; + if ( $guessed_indentation_level ne $structural_indentation_level ) { $self->[_last_tabbing_disagreement_] = $line_number; - if ( $self->[_in_tabbing_disagreement_] ) { + if ($is_closing_block) { + + if ( !$self->[_in_brace_tabbing_disagreement_] ) { + $self->[_in_brace_tabbing_disagreement_] = $line_number; + } + if ( !$self->[_first_brace_tabbing_disagreement_] ) { + $self->[_first_brace_tabbing_disagreement_] = $line_number; + } + } - else { + + if ( !$self->[_in_tabbing_disagreement_] ) { $self->[_tabbing_disagreement_count_]++; if ( $self->[_tabbing_disagreement_count_] <= MAX_NAG_MESSAGES ) { @@ -18993,6 +19037,8 @@ sub compare_indentation_levels { } else { + $self->[_in_brace_tabbing_disagreement_] = 0 if ($is_closing_block); + my $in_tabbing_disagreement = $self->[_in_tabbing_disagreement_]; if ($in_tabbing_disagreement) { @@ -19008,6 +19054,7 @@ sub compare_indentation_levels { } } $self->[_in_tabbing_disagreement_] = 0; + } } return; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index ccbe6d9f..f127a3a9 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -5,6 +5,15 @@ found with the help of automated random testing. =over +=item B + +The .LOG file reports any disagreements between the indentation of the input and output files. +This can help locate brace errors. These were incorrect when some of the options were used, +including --whitespace-cycle, -bbhb, -nib. This was corrected 24 Sep 2020. At the same time, +locations of closing brace indentation disagreements are now tracked and reported in the +.ERR file when there is a brace error. This can help localize the error if the file was +previously formatted by perltidy. + =item B Previously only a complaint was given, which went into the log file and was not normally