From 7b2c2369ae7f34811cc69e90b77a534142736e5b Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 7 Apr 2013 13:15:33 +0200 Subject: [PATCH] Check for whitespace errors in lint --- build.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/build.py b/build.py index ec71b6182a..47f65b9ec1 100755 --- a/build.py +++ b/build.py @@ -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)