Check for whitespace errors in lint

This commit is contained in:
Tom Payne
2013-04-07 13:15:33 +02:00
parent f1cc5b87da
commit 7b2c2369ae

View File

@@ -341,7 +341,8 @@ def serve_precommit(t):
'buildcfg/ol-all.json', 'buildcfg/test.json')
virtual('lint', 'build/lint-timestamp', 'build/check-requires-timestamp')
virtual('lint', 'build/lint-timestamp', 'build/check-requires-timestamp',
'build/check-whitespace-timestamp')
@target('build/lint-timestamp', SRC, INTERNAL_SRC, EXTERNAL_SRC, EXAMPLES_SRC,
@@ -508,6 +509,36 @@ def build_check_requires_timestamp(t):
t.touch()
@target('build/check-whitespace-timestamp', SRC, INTERNAL_SRC, EXTERNAL_SRC,
EXAMPLES_SRC, SPEC, EXPORTS, 'src/objectliterals.exports',
precious=True)
def build_check_whitespace_timestamp(t):
CR_RE = re.compile(r'\r')
TRAILING_WHITESPACE_RE = re.compile(r'\s+\n\Z')
NO_NEWLINE_RE = re.compile(r'[^\n]\Z')
ALL_WHITESPACE_RE = re.compile(r'\s+\Z')
errors = 0
for filename in sorted(t.newer(t.dependencies)):
whitespace = False
for lineno, line in enumerate(open(filename)):
if CR_RE.search(line):
t.info('%s:%d: carriage return character in line', filename, lineno + 1)
errors += 1
if TRAILING_WHITESPACE_RE.search(line):
t.info('%s:%d: trailing whitespace', filename, lineno + 1)
errors += 1
if NO_NEWLINE_RE.search(line):
t.info('%s:%d: no newline at end of file', filename, lineno + 1)
errors += 1
whitespace = ALL_WHITESPACE_RE.match(line)
if whitespace:
t.info('%s: trailing whitespace at end of file', filename)
errors += 1
if errors:
t.error('%d whitespace errors' % (errors,))
t.touch()
virtual('plovr', PLOVR_JAR)