#!/usr/bin/perl # "doclint" that really only checks for whitespace problems # WB 2011-09-26 use strict; use warnings; die "Usage: doclint.pl filename\n" unless ($#ARGV == 0); # highlight 1: ANSI highlight sequences (pipe output to 'less -R') # highlight 0: use plain old brackets my $highlight = 1; my $start = "\033[7m"; my $stop = "\033[0m"; unless ($highlight) { $start = "["; $stop = "]"; } my $checkblock = 1; while (<>) { chomp; $checkblock = 0 if /||/; /^\s+$/ && print "$.: blank line with whitespace\n\n"; s/(\S+)(\s+)$/$1$start$2$stop/ && print "$.:$_\ntrailing whitespace\n\n"; s/^( {8})+/$start$1$stop/g && print "$.:$_\nuse tabs instead of spaces\n\n"; # (one or more double spaces) or (one or more tabs) followed # by a single space and non-space character is a bad indent # "checkblock" is used to ignore blocks where # odd indents are allowed $checkblock && s/^(( {2})+|\t+)*( {1})\b/$start$1$3$stop/ && print "$.:$_\nbad indent\n\n"; }