Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1033)

Side by Side Diff: tools/presubmit.py

Issue 7826007: Added check for trailing whitespaces and corrected existing violations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Yet another iteration. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gdb-v8-support.py ('k') | tools/process-heap-prof.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2008 the V8 project authors. All rights reserved. 3 # Copyright 2011 the V8 project authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following 11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided 12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution. 13 # with the distribution.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 runtime/references 81 runtime/references
82 runtime/rtti 82 runtime/rtti
83 runtime/sizeof 83 runtime/sizeof
84 runtime/string 84 runtime/string
85 runtime/virtual 85 runtime/virtual
86 runtime/vlog 86 runtime/vlog
87 whitespace/blank_line 87 whitespace/blank_line
88 whitespace/braces 88 whitespace/braces
89 whitespace/comma 89 whitespace/comma
90 whitespace/comments 90 whitespace/comments
91 whitespace/end_of_line
92 whitespace/ending_newline 91 whitespace/ending_newline
93 whitespace/indent 92 whitespace/indent
94 whitespace/labels 93 whitespace/labels
95 whitespace/line_length 94 whitespace/line_length
96 whitespace/newline 95 whitespace/newline
97 whitespace/operators 96 whitespace/operators
98 whitespace/parens 97 whitespace/parens
99 whitespace/tab 98 whitespace/tab
100 whitespace/todo 99 whitespace/todo
101 """.split() 100 """.split()
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 223
225 good_files_cache.Save() 224 good_files_cache.Save()
226 return process.returncode == 0 225 return process.returncode == 0
227 226
228 227
229 COPYRIGHT_HEADER_PATTERN = re.compile( 228 COPYRIGHT_HEADER_PATTERN = re.compile(
230 r'Copyright [\d-]*20[0-1][0-9] the V8 project authors. All rights reserved.' ) 229 r'Copyright [\d-]*20[0-1][0-9] the V8 project authors. All rights reserved.' )
231 230
232 class SourceProcessor(SourceFileProcessor): 231 class SourceProcessor(SourceFileProcessor):
233 """ 232 """
234 Check that all files include a copyright notice. 233 Check that all files include a copyright notice and no trailing whitespaces.
235 """ 234 """
236 235
237 RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', 'SConscript', 236 RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', 'SConscript',
238 'SConstruct', '.status'] 237 'SConstruct', '.status', '.gyp', '.gypi']
238
239 def IsRelevant(self, name): 239 def IsRelevant(self, name):
240 for ext in SourceProcessor.RELEVANT_EXTENSIONS: 240 for ext in SourceProcessor.RELEVANT_EXTENSIONS:
241 if name.endswith(ext): 241 if name.endswith(ext):
242 return True 242 return True
243 return False 243 return False
244 244
245 def GetPathsToSearch(self): 245 def GetPathsToSearch(self):
246 return ['.'] 246 return ['.']
247 247
248 def IgnoreDir(self, name): 248 def IgnoreDir(self, name):
(...skipping 17 matching lines...) Expand all
266 result = True 266 result = True
267 base = basename(name) 267 base = basename(name)
268 if not base in SourceProcessor.IGNORE_TABS: 268 if not base in SourceProcessor.IGNORE_TABS:
269 if '\t' in contents: 269 if '\t' in contents:
270 print "%s contains tabs" % name 270 print "%s contains tabs" % name
271 result = False 271 result = False
272 if not base in SourceProcessor.IGNORE_COPYRIGHTS: 272 if not base in SourceProcessor.IGNORE_COPYRIGHTS:
273 if not COPYRIGHT_HEADER_PATTERN.search(contents): 273 if not COPYRIGHT_HEADER_PATTERN.search(contents):
274 print "%s is missing a correct copyright header." % name 274 print "%s is missing a correct copyright header." % name
275 result = False 275 result = False
276 ext = base.split('.').pop()
277 if ' \n' in contents or contents.endswith(' '):
278 line = 0
279 lines = []
280 parts = contents.split(' \n')
281 if not contents.endswith(' '):
282 parts.pop()
283 for part in parts:
284 line += part.count('\n') + 1
285 lines.append(str(line))
286 linenumbers = ', '.join(lines)
287 if len(lines) > 1:
288 print "%s has trailing whitespaces in lines %s." % (name, linenumbers)
289 else:
290 print "%s has trailing whitespaces in line %s." % (name, linenumbers)
291 result = False
276 return result 292 return result
277 293
278 def ProcessFiles(self, files, path): 294 def ProcessFiles(self, files, path):
279 success = True 295 success = True
280 for file in files: 296 for file in files:
281 try: 297 try:
282 handle = open(file) 298 handle = open(file)
283 contents = handle.read() 299 contents = handle.read()
284 success = self.ProcessContents(file, contents) and success 300 success = self.ProcessContents(file, contents) and success
285 finally: 301 finally:
(...skipping 17 matching lines...) Expand all
303 success = CppLintProcessor().Run(workspace) and success 319 success = CppLintProcessor().Run(workspace) and success
304 success = SourceProcessor().Run(workspace) and success 320 success = SourceProcessor().Run(workspace) and success
305 if success: 321 if success:
306 return 0 322 return 0
307 else: 323 else:
308 return 1 324 return 1
309 325
310 326
311 if __name__ == '__main__': 327 if __name__ == '__main__':
312 sys.exit(Main()) 328 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/gdb-v8-support.py ('k') | tools/process-heap-prof.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698