ClickHouse/utils/check-style/double-whitespaces.pl

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
984 B
Perl
Raw Permalink Normal View History

2019-08-23 18:30:04 +00:00
#!/usr/bin/perl
use strict;
# Find double whitespace such as "a, b, c" that looks very ugly and annoying.
# But skip double whitespaces if they are used as an alignment - by comparing to surrounding lines.
my $ret = 0;
2024-02-28 14:17:27 +00:00
foreach my $file (@ARGV)
2019-08-23 18:30:04 +00:00
{
2024-02-28 14:17:27 +00:00
my @array;
open (FH,'<',$file);
while (<FH>)
2019-08-23 18:30:04 +00:00
{
2024-02-28 14:17:27 +00:00
push @array, $_;
}
2019-08-23 18:30:04 +00:00
2024-02-28 14:17:27 +00:00
for (my $i = 1; $i < $#array; ++$i)
{
if ($array[$i] =~ ',( {2,3})[^ /]')
2019-08-23 18:30:04 +00:00
{
2024-02-28 14:17:27 +00:00
# https://stackoverflow.com/questions/87380/how-can-i-find-the-location-of-a-regex-match-in-perl
if ((substr($array[$i - 1], $+[1] - 1, 2) !~ /^[ -][^ ]$/) # whitespaces are not part of alignment
&& (substr($array[$i + 1], $+[1] - 1, 2) !~ /^[ -][^ ]$/)
&& $array[$i] !~ /(-?\d+\w*,\s+){3,}/) # this is not a number table like { 10, -1, 2 }
{
print($file . ":" . ($i + 1) . $array[$i]);
$ret = 1;
}
2019-08-23 18:30:04 +00:00
}
}
}
exit $ret;