3 # Common lint functions applicable to multiple types of files.
7 def VerifyLineLength(filename, lines, max_length):
8 """Checkes to make sure the file has no lines with lines exceeding the length
12 filename: the file under consideration as string
13 lines: contents of the file as string array
14 max_length: maximum acceptable line length as number
18 length = len(line.rstrip()) # strip off EOL char(s)
19 if length > max_length:
20 print '%s:%d:Line exceeds %d chars (%d)' % (filename, line_num,
25 def VerifyTrailingWhitespace(filename, lines):
26 """Checkes to make sure the file has no lines with trailing whitespace.
29 filename: the file under consideration as string
30 lines: contents of the file as string array
32 trailing_whitespace_re = re.compile(r'\s+$')
35 if trailing_whitespace_re.match(line):
36 print '%s:%d:Trailing whitespace' % (filename, line_num)
41 def RunOnFile(filename, lines):
42 raise Exception('RunOnFile() unimplemented')
45 def RunLintOverAllFiles(lint, filenames):
46 """Runs linter over the contents of all files.
49 lint: subclass of BaseLint, implementing RunOnFile()
50 filenames: list of all files whose contents will be linted
52 for filename in filenames:
53 file = open(filename, 'r')
55 print 'Cound not open %s' % filename
57 lines = file.readlines()
58 lint.RunOnFile(filename, lines)