Skip to content

Commit a084623

Browse files
committed
Add style checking script from b3bp
1 parent 171487e commit a084623

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

developer-scripts/style.pl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env perl
2+
3+
use strict;
4+
use warnings;
5+
6+
die "usage: $0 <file>\n" if (not @ARGV);
7+
8+
my $rc = 0;
9+
my $file = shift;
10+
11+
open(my $fh, '<', $file) or die "Cannot open \`$file' for read: $!\n";
12+
while (<$fh>) {
13+
next if (/^\s*#/);
14+
15+
my $errors = 0;
16+
17+
# remove everything between single quotes
18+
# this will remove too much in case of: echo "var='$var'"
19+
# and thus miss an opportunity to complain later on
20+
# also it mangles the input line irreversible
21+
s/'[^']+'/'___'/g;
22+
23+
# highlight unbraced variables--
24+
# unless properly backslash'ed
25+
$errors += s/((?:^|[^\\]))(((\\\\)+)?\$\w)/$1\033[31m$2\033[0m/g;
26+
27+
# highlight single square brackets
28+
$errors += s/((?:^|\s+))\[([^\[].+[^\]])\](\s*(;|&&|\|\|))/$1\033[31m\[\033[0m$2\033[31m\]\033[0m$3/g;
29+
30+
# highlight double equal sign
31+
# $errors += s/(\[\[.*)(==)(.*\]\])/$1\033[31m$2\033[0m$3/g;
32+
33+
# highlight tabs mixed with whitespace at beginning of lines
34+
$errors += s/^( *)(\t+ *)/\033[31m\[$2\]\033[0m/;
35+
36+
# highlight trailing whitespace
37+
$errors += s/([ \t]+)$/\033[31m\[$1\]\033[0m/;
38+
39+
next if (not $errors);
40+
print "${file}[$.]: $_";
41+
$rc = 1;
42+
}
43+
close($fh);
44+
45+
exit $rc;

0 commit comments

Comments
 (0)