File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments