Axel Beckert pushed to branch master at lintian / lintian
Commits: 71198035 by Andrius Merkys at 2024-06-10T00:52:06+00:00 Rewrite files/contents/line-length in a more effective manner. - - - - - 1 changed file: - lib/Lintian/Check/Files/Contents/LineLength.pm Changes: ===================================== lib/Lintian/Check/Files/Contents/LineLength.pm ===================================== @@ -31,13 +31,13 @@ use warnings; use utf8; use Const::Fast; -use List::UtilsBy qw(max_by); use Unicode::UTF8 qw(encode_utf8 decode_utf8 valid_utf8); const my $GREATER_THAN => q{>}; const my $VERTICAL_BAR => q{|}; const my $VERY_LONG => 512; +const my $ITEM_NOT_FOUND => -1; use Moo; use namespace::clean; @@ -97,10 +97,12 @@ sub visit_patched_files { open(my $fd, '<', $item->unpacked_path) or die encode_utf8('Cannot open ' . $item->unpacked_path); - my %line_lengths; - - my $position = 1; + my $longest; + my $length = $ITEM_NOT_FOUND; + my $position = 0; while (my $line = <$fd>) { + $position++; + # Skip SQL insert and select statements next if ($line =~ /^(INSERT|SELECT)\s/i and $item->basename =~ /sql/i); @@ -109,24 +111,22 @@ sub visit_patched_files { $line = decode_utf8($line) if valid_utf8($line); - $line_lengths{$position} = length $line; - - } continue { - ++$position; + if( length $line > $length ) { + $longest = $position; + $length = length $line; + } } close $fd; - my $longest = max_by { $line_lengths{$_} } keys %line_lengths; - return unless defined $longest; my $pointer = $item->pointer($longest); $self->pointed_hint('very-long-line-length-in-source-file', - $pointer, $line_lengths{$longest}, $GREATER_THAN, $VERY_LONG) - if $line_lengths{$longest} > $VERY_LONG; + $pointer, $length, $GREATER_THAN, $VERY_LONG) + if $length > $VERY_LONG; return; } View it on GitLab: https://salsa.debian.org/lintian/lintian/-/commit/7119803571b9abb8cea3a4834e0c2e6b183fffba -- This project does not include diff previews in email notifications. View it on GitLab: https://salsa.debian.org/lintian/lintian/-/commit/7119803571b9abb8cea3a4834e0c2e6b183fffba You're receiving this email because of your account on salsa.debian.org.