summaryrefslogtreecommitdiffstats
path: root/llvm/utils/lint/common_lint.py
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2009-02-20 23:44:54 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2009-02-20 23:44:54 +0000
commit0f35659b9aaad4e6d0883b9d1a6999b4c1022418 (patch)
treef56892d825d31a6c2f79122149d07dcc2b841cd7 /llvm/utils/lint/common_lint.py
parente7fe80fcf927f94f39c4707acd3c4027b70d7745 (diff)
downloadbcm5719-llvm-0f35659b9aaad4e6d0883b9d1a6999b4c1022418.tar.gz
bcm5719-llvm-0f35659b9aaad4e6d0883b9d1a6999b4c1022418.zip
* Fixed spelling
* Linters now return their information instead of printing it, to enable easier unittesting * Added support for finding tabs in files, added to C++ linter llvm-svn: 65202
Diffstat (limited to 'llvm/utils/lint/common_lint.py')
-rw-r--r--llvm/utils/lint/common_lint.py53
1 files changed, 46 insertions, 7 deletions
diff --git a/llvm/utils/lint/common_lint.py b/llvm/utils/lint/common_lint.py
index e08c93cb170..e982680c052 100644
--- a/llvm/utils/lint/common_lint.py
+++ b/llvm/utils/lint/common_lint.py
@@ -5,36 +5,68 @@
import re
def VerifyLineLength(filename, lines, max_length):
- """Checkes to make sure the file has no lines with lines exceeding the length
+ """Checks to make sure the file has no lines with lines exceeding the length
limit.
Args:
filename: the file under consideration as string
lines: contents of the file as string array
max_length: maximum acceptable line length as number
+
+ Returns:
+ A list of tuples with format [(filename, line number, msg), ...] with any
+ violations found.
"""
+ lint = []
line_num = 1
for line in lines:
length = len(line.rstrip('\n'))
if length > max_length:
- print '%s:%d:Line exceeds %d chars (%d)' % (filename, line_num,
- max_length, length)
+ lint.append((filename, line_num,
+ 'Line exceeds %d chars (%d)' % (max_length, length)))
+ line_num += 1
+ return lint
+
+def VerifyTabs(filename, lines):
+ """Checks to make sure the file has no tab characters.
+
+ Args:
+ filename: the file under consideration as string
+ lines: contents of the file as string array
+
+ Returns:
+ A list of tuples with format [(line_number, msg), ...] with any violations
+ found.
+ """
+ lint = []
+ tab_re = re.compile(r'\t')
+ line_num = 1
+ for line in lines:
+ if tab_re.match(line.rstrip('\n')):
+ lint.append((filename, line_num, 'Tab found instead of whitespace'))
line_num += 1
+ return lint
def VerifyTrailingWhitespace(filename, lines):
- """Checkes to make sure the file has no lines with trailing whitespace.
+ """Checks to make sure the file has no lines with trailing whitespace.
Args:
filename: the file under consideration as string
lines: contents of the file as string array
+
+ Returns:
+ A list of tuples with format [(filename, line number, msg), ...] with any
+ violations found.
"""
+ lint = []
trailing_whitespace_re = re.compile(r'\s+$')
line_num = 1
for line in lines:
if trailing_whitespace_re.match(line.rstrip('\n')):
- print '%s:%d:Trailing whitespace' % (filename, line_num)
+ lint.append((filename, line_num, 'Trailing whitespace'))
line_num += 1
+ return lint
class BaseLint:
@@ -42,17 +74,24 @@ class BaseLint:
raise Exception('RunOnFile() unimplemented')
-def RunLintOverAllFiles(lint, filenames):
+def RunLintOverAllFiles(linter, filenames):
"""Runs linter over the contents of all files.
Args:
lint: subclass of BaseLint, implementing RunOnFile()
filenames: list of all files whose contents will be linted
+
+ Returns:
+ A list of tuples with format [(filename, line number, msg), ...] with any
+ violations found.
"""
+ lint = []
for filename in filenames:
file = open(filename, 'r')
if not file:
print 'Cound not open %s' % filename
continue
lines = file.readlines()
- lint.RunOnFile(filename, lines)
+ lint.extend(linter.RunOnFile(filename, lines))
+
+ return lint
OpenPOWER on IntegriCloud