aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/sanitize_source_files.py
diff options
context:
space:
mode:
authorGravatar rmistry@google.com <rmistry@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-25 18:26:58 +0000
committerGravatar rmistry@google.com <rmistry@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-25 18:26:58 +0000
commit647ca8bc893bd8edaaa7dc8ab5fb3f5e148bcdbb (patch)
tree0a45de2d90a894056fa1ca72644d3c60d6ef8daa /tools/sanitize_source_files.py
parentbbec4e6be2b7351bdc7e2d1ae627813f67441d7c (diff)
Leave one and only one newline at the end of source files
Review URL: https://codereview.appspot.com/7216043 git-svn-id: http://skia.googlecode.com/svn/trunk@7398 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/sanitize_source_files.py')
-rwxr-xr-xtools/sanitize_source_files.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/tools/sanitize_source_files.py b/tools/sanitize_source_files.py
index d6e3ec62ae..c7edaa0bd2 100755
--- a/tools/sanitize_source_files.py
+++ b/tools/sanitize_source_files.py
@@ -23,7 +23,7 @@ def SanitizeFilesWithModifiers(directory, file_modifiers, line_modifiers):
directory: string - The directory which will be recursively traversed to
find source files to apply modifiers to.
file_modifiers: list - file-modification methods which should be applied to
- the complete file content (Eg: EOFNewlineAdder).
+ the complete file content (Eg: EOFOneAndOnlyOneNewlineAdder).
line_modifiers: list - line-modification methods which should be applied to
lines in a file (Eg: TabReplacer).
"""
@@ -114,11 +114,12 @@ def CopywriteChecker(file_content, unused_file_path):
return file_content
-def EOFNewlineAdder(file_content, file_path):
- """Adds a LF at the end of the file if it does not have one."""
- if file_content and file_content[-1] != '\n':
+def EOFOneAndOnlyOneNewlineAdder(file_content, file_path):
+ """Adds one and only one LF at the end of the file."""
+ if file_content and (file_content[-1] != '\n' or file_content[-2:-1] == '\n'):
+ file_content = file_content.rstrip()
file_content += '\n'
- print 'Added newline to %s' % file_path
+ print 'Added exactly one newline to %s' % file_path
return file_content
@@ -140,7 +141,7 @@ if '__main__' == __name__:
os.getcwd(),
file_modifiers=[
CopywriteChecker,
- EOFNewlineAdder,
+ EOFOneAndOnlyOneNewlineAdder,
SvnEOLChecker,
],
line_modifiers=[
@@ -149,4 +150,3 @@ if '__main__' == __name__:
TrailingWhitespaceRemover,
],
))
-