Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2012 the V8 project authors. All rights reserved. | 3 # Copyright 2012 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 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 'earley-boyer.js', | 324 'earley-boyer.js', |
| 325 'raytrace.js', | 325 'raytrace.js', |
| 326 'crypto.js', | 326 'crypto.js', |
| 327 'libraries.cc', | 327 'libraries.cc', |
| 328 'libraries-empty.cc', | 328 'libraries-empty.cc', |
| 329 'jsmin.py', | 329 'jsmin.py', |
| 330 'regexp-pcre.js', | 330 'regexp-pcre.js', |
| 331 'gnuplot-4.6.3-emscripten.js'] | 331 'gnuplot-4.6.3-emscripten.js'] |
| 332 IGNORE_TABS = IGNORE_COPYRIGHTS + ['unicode-test.js', 'html-comments.js'] | 332 IGNORE_TABS = IGNORE_COPYRIGHTS + ['unicode-test.js', 'html-comments.js'] |
| 333 | 333 |
| 334 def EndOfDeclaration(self, line): | |
| 335 return line == "}" or line == "};" | |
| 336 | |
| 337 def StartOfDeclaration(self, line): | |
| 338 return line.find("//") == 0 or \ | |
| 339 line.find("/*") == 0 or \ | |
| 340 line.find(") {") != -1 | |
| 341 | |
| 334 def ProcessContents(self, name, contents): | 342 def ProcessContents(self, name, contents): |
| 335 result = True | 343 result = True |
| 336 base = basename(name) | 344 base = basename(name) |
| 337 if not base in SourceProcessor.IGNORE_TABS: | 345 if not base in SourceProcessor.IGNORE_TABS: |
| 338 if '\t' in contents: | 346 if '\t' in contents: |
| 339 print "%s contains tabs" % name | 347 print "%s contains tabs" % name |
| 340 result = False | 348 result = False |
| 341 if not base in SourceProcessor.IGNORE_COPYRIGHTS: | 349 if not base in SourceProcessor.IGNORE_COPYRIGHTS: |
| 342 if not COPYRIGHT_HEADER_PATTERN.search(contents): | 350 if not COPYRIGHT_HEADER_PATTERN.search(contents): |
| 343 print "%s is missing a correct copyright header." % name | 351 print "%s is missing a correct copyright header." % name |
| 344 result = False | 352 result = False |
| 345 ext = base.split('.').pop() | |
| 346 if ' \n' in contents or contents.endswith(' '): | 353 if ' \n' in contents or contents.endswith(' '): |
| 347 line = 0 | 354 line = 0 |
| 348 lines = [] | 355 lines = [] |
| 349 parts = contents.split(' \n') | 356 parts = contents.split(' \n') |
| 350 if not contents.endswith(' '): | 357 if not contents.endswith(' '): |
| 351 parts.pop() | 358 parts.pop() |
| 352 for part in parts: | 359 for part in parts: |
| 353 line += part.count('\n') + 1 | 360 line += part.count('\n') + 1 |
| 354 lines.append(str(line)) | 361 lines.append(str(line)) |
| 355 linenumbers = ', '.join(lines) | 362 linenumbers = ', '.join(lines) |
| 356 if len(lines) > 1: | 363 if len(lines) > 1: |
| 357 print "%s has trailing whitespaces in lines %s." % (name, linenumbers) | 364 print "%s has trailing whitespaces in lines %s." % (name, linenumbers) |
| 358 else: | 365 else: |
| 359 print "%s has trailing whitespaces in line %s." % (name, linenumbers) | 366 print "%s has trailing whitespaces in line %s." % (name, linenumbers) |
| 360 result = False | 367 result = False |
| 368 # Check two empty lines between declarations. | |
| 369 if name.endswith(".cc"): | |
| 370 line = 0 | |
| 371 lines = [] | |
| 372 parts = contents.split('\n') | |
| 373 while line < len(parts) - 2: | |
| 374 if self.EndOfDeclaration(parts[line]): | |
| 375 if self.StartOfDeclaration(parts[line + 1]): | |
| 376 lines.append(str(line + 1)) | |
| 377 elif parts[line + 1] == "" and \ | |
| 378 self.StartOfDeclaration(parts[line + 2]): | |
| 379 lines.append(str(line + 1)) | |
| 380 line += 1 | |
| 381 if len(lines) >= 1: | |
| 382 linenumbers = ', '.join(lines) | |
| 383 if len(lines) > 1: | |
| 384 print "{0} does not have two empty lines between declarations " \ | |
| 385 "in lines {1}.".format(name, linenumbers) | |
|
Yang
2013/07/04 16:33:00
I think for consistency we could use
"%s ... %s .
haitao.feng
2013/07/05 05:16:37
Done.
| |
| 386 else: | |
| 387 print "{0} does not have two empty lines between declarations " \ | |
| 388 "in line {1}.".format(name, linenumbers) | |
| 389 result = False | |
| 361 return result | 390 return result |
| 362 | 391 |
| 363 def ProcessFiles(self, files, path): | 392 def ProcessFiles(self, files, path): |
| 364 success = True | 393 success = True |
| 365 violations = 0 | 394 violations = 0 |
| 366 for file in files: | 395 for file in files: |
| 367 try: | 396 try: |
| 368 handle = open(file) | 397 handle = open(file) |
| 369 contents = handle.read() | 398 contents = handle.read() |
| 370 if not self.ProcessContents(file, contents): | 399 if not self.ProcessContents(file, contents): |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 394 print "Running copyright header and trailing whitespaces check..." | 423 print "Running copyright header and trailing whitespaces check..." |
| 395 success = SourceProcessor().Run(workspace) and success | 424 success = SourceProcessor().Run(workspace) and success |
| 396 if success: | 425 if success: |
| 397 return 0 | 426 return 0 |
| 398 else: | 427 else: |
| 399 return 1 | 428 return 1 |
| 400 | 429 |
| 401 | 430 |
| 402 if __name__ == '__main__': | 431 if __name__ == '__main__': |
| 403 sys.exit(Main()) | 432 sys.exit(Main()) |
| OLD | NEW |