Single line code like: if (foo) bar; should generally be written: if (foo) bar; Add a --fix test to do so. This fix is not done when an ASSIGN_IN_IF in the same line exists.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -5551,6 +5551,7 @@ sub process { · 5550 unmodified lines | |||
| 5551 | defined($stat) && defined($cond) && | 5551 | defined($stat) && defined($cond) && |
| 5552 | $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { | 5552 | $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { |
| 5553 | my ($s, $c) = ($stat, $cond); | 5553 | my ($s, $c) = ($stat, $cond); |
| 5554 | my $fixed_assign_in_if = 0; | ||
| 5554 | 5555 | ||
| 5555 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { | 5556 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { |
| 5556 | if (ERROR("ASSIGN_IN_IF", | 5557 | if (ERROR("ASSIGN_IN_IF", |
| @@ -5575,6 +5576,7 @@ sub process { · 18 unmodified lines | |||
| 5575 | $newline .= ')'; | 5576 | $newline .= ')'; |
| 5576 | $newline .= " {" if (defined($brace)); | 5577 | $newline .= " {" if (defined($brace)); |
| 5577 | fix_insert_line($fixlinenr + 1, $newline); | 5578 | fix_insert_line($fixlinenr + 1, $newline); |
| 5579 | $fixed_assign_in_if = 1; | ||
| 5578 | } | 5580 | } |
| 5579 | } | 5581 | } |
| 5580 | } | 5582 | } |
| @@ -5598,8 +5600,20 @@ sub process { · 17 unmodified lines | |||
| 5598 | $stat_real = "[...]\n$stat_real"; | 5600 | $stat_real = "[...]\n$stat_real"; |
| 5599 | } | 5601 | } |
| 5600 | 5602 | ||
| 5601 | ERROR("TRAILING_STATEMENTS", | 5603 | if (ERROR("TRAILING_STATEMENTS", |
| 5602 | "trailing statements should be on next line\n" . $herecurr . $stat_real); | 5604 | "trailing statements should be on next line\n" . $herecurr . $stat_real) && |
| 5605 | !$fixed_assign_in_if && | ||
| 5606 | $cond_lines == 0 && | ||
| 5607 | $fix && $perl_version_ok && | ||
| 5608 | $fixed[$fixlinenr] =~ /^\+(\s*)((?:if|while|for)\s*$balanced_parens)\s*(.*)$/) { | ||
| 5609 | my $indent = $1; | ||
| 5610 | my $test = $2; | ||
| 5611 | my $rest = rtrim($4); | ||
| 5612 | if ($rest =~ /;$/) { | ||
| 5613 | $fixed[$fixlinenr] = "\+$indent$test"; | ||
| 5614 | fix_insert_line($fixlinenr + 1, "$indent\t$rest"); | ||
| 5615 | } | ||
| 5616 | } | ||
| 5603 | } | 5617 | } |
| 5604 | } | 5618 | } |
| 5605 | 5619 | ||