[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][lintian/lintian][master] Rewrite files/contents/line-length in a more effective manner.



Title: GitLab

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:

Changes:

  • lib/Lintian/Check/Files/Contents/LineLength.pm
    ... ... @@ -31,13 +31,13 @@ use warnings;
    31 31
     use utf8;
    
    32 32
     
    
    33 33
     use Const::Fast;
    
    34
    -use List::UtilsBy qw(max_by);
    
    35 34
     use Unicode::UTF8 qw(encode_utf8 decode_utf8 valid_utf8);
    
    36 35
     
    
    37 36
     const my $GREATER_THAN => q{>};
    
    38 37
     const my $VERTICAL_BAR => q{|};
    
    39 38
     
    
    40 39
     const my $VERY_LONG => 512;
    
    40
    +const my $ITEM_NOT_FOUND => -1;
    
    41 41
     
    
    42 42
     use Moo;
    
    43 43
     use namespace::clean;
    
    ... ... @@ -97,10 +97,12 @@ sub visit_patched_files {
    97 97
         open(my $fd, '<', $item->unpacked_path)
    
    98 98
           or die encode_utf8('Cannot open ' . $item->unpacked_path);
    
    99 99
     
    
    100
    -    my %line_lengths;
    
    101
    -
    
    102
    -    my $position = 1;
    
    100
    +    my $longest;
    
    101
    +    my $length = $ITEM_NOT_FOUND;
    
    102
    +    my $position = 0;
    
    103 103
         while (my $line = <$fd>) {
    
    104
    +        $position++;
    
    105
    +
    
    104 106
             # Skip SQL insert and select statements
    
    105 107
             next if ($line =~ /^(INSERT|SELECT)\s/i
    
    106 108
                 and $item->basename =~ /sql/i);
    
    ... ... @@ -109,24 +111,22 @@ sub visit_patched_files {
    109 111
             $line = decode_utf8($line)
    
    110 112
               if valid_utf8($line);
    
    111 113
     
    
    112
    -        $line_lengths{$position} = length $line;
    
    113
    -
    
    114
    -    } continue {
    
    115
    -        ++$position;
    
    114
    +        if( length $line > $length ) {
    
    115
    +            $longest = $position;
    
    116
    +            $length = length $line;
    
    117
    +        }
    
    116 118
         }
    
    117 119
     
    
    118 120
         close $fd;
    
    119 121
     
    
    120
    -    my $longest = max_by { $line_lengths{$_} } keys %line_lengths;
    
    121
    -
    
    122 122
         return
    
    123 123
           unless defined $longest;
    
    124 124
     
    
    125 125
         my $pointer = $item->pointer($longest);
    
    126 126
     
    
    127 127
         $self->pointed_hint('very-long-line-length-in-source-file',
    
    128
    -        $pointer, $line_lengths{$longest}, $GREATER_THAN, $VERY_LONG)
    
    129
    -      if $line_lengths{$longest} > $VERY_LONG;
    
    128
    +        $pointer, $length, $GREATER_THAN, $VERY_LONG)
    
    129
    +      if $length > $VERY_LONG;
    
    130 130
     
    
    131 131
         return;
    
    132 132
     }
    


  • Reply to: