Presubmit should check that source files end in atleast one newline
authorrmistry@google.com <rmistry@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 25 Jan 2013 18:27:34 +0000 (18:27 +0000)
committerrmistry@google.com <rmistry@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 25 Jan 2013 18:27:34 +0000 (18:27 +0000)
Review URL: https://codereview.appspot.com/7193063

git-svn-id: http://skia.googlecode.com/svn/trunk@7399 2bbb7eff-a529-9590-31e7-b0007b416f81

PRESUBMIT.py

index b5aeffc..ddac74a 100644 (file)
@@ -10,6 +10,22 @@ for more details about the presubmit API built into gcl.
 """
 
 
+def _CheckChangeHasEol(input_api, output_api, source_file_filter=None):
+  """Checks that files end with atleast one \n (LF)."""
+  eof_files = []
+  for f in input_api.AffectedSourceFiles(source_file_filter):
+    contents = input_api.ReadFile(f, 'rb')
+    # Check that the file ends in atleast one newline character.
+    if len(contents) > 1 and contents[-1:] != '\n':
+      eof_files.append(f.LocalPath())
+
+  if eof_files:
+    return [output_api.PresubmitPromptWarning(
+      'These files should end in a newline character:',
+      items=eof_files)]
+  return []
+
+
 def _CommonChecks(input_api, output_api):
   """Presubmit checks common to upload and commit."""
   results = []
@@ -20,7 +36,7 @@ def _CommonChecks(input_api, output_api):
                        x.LocalPath().endswith('.sh') or
                        x.LocalPath().endswith('.cpp'))
   results.extend(
-      input_api.canned_checks.CheckChangeHasOnlyOneEol(
+      _CheckChangeHasEol(
           input_api, output_api, source_file_filter=sources))
   return results