From 1b2d5eaf684ab38f7ab44fdab173ca1be0cf4ba1 Mon Sep 17 00:00:00 2001 From: shanebishop Date: Fri, 31 May 2019 19:59:34 -0400 Subject: [PATCH] Fix for Issue 33: Should not succeed for empty CMakeLists.txt --- cmakelint/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmakelint/main.py b/cmakelint/main.py index 23fba6a..4ab007e 100644 --- a/cmakelint/main.py +++ b/cmakelint/main.py @@ -479,15 +479,24 @@ def _ProcessFile(filename): return global _package_state _package_state = _CMakePackageState() + + allWhitespace = True + for l in open(filename).readlines(): + allWhitespace = allWhitespace and l.isspace() l = l.rstrip('\n') if l.endswith('\r'): have_cr = True l = l.rstrip('\r') lines.append(l) CheckLintPragma(filename, len(lines) - 1, l) + + if allWhitespace or len(lines) == 1: + # File was empty, or only contained whitespace + Error(filename, 0, 'empty file', 'File must contain cmake commands') + lines.append('# Lines end here') - # Check file name after reading lines incase of a # lint_cmake: pragma + # Check file name after reading lines in case of a # lint_cmake: pragma CheckFileName(filename, Error) if have_cr and os.linesep != '\r\n': Error(filename, 0, 'whitespace/newline', 'Unexpected carriage return found; '