| 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 line += 1 |
| 378 elif parts[line + 1] == "" and \ |
| 379 self.StartOfDeclaration(parts[line + 2]): |
| 380 lines.append(str(line + 1)) |
| 381 line += 2 |
| 382 line += 1 |
| 383 if len(lines) >= 1: |
| 384 linenumbers = ', '.join(lines) |
| 385 if len(lines) > 1: |
| 386 print "%s does not have two empty lines between declarations " \ |
| 387 "in lines %s." % (name, linenumbers) |
| 388 else: |
| 389 print "%s does not have two empty lines between declarations " \ |
| 390 "in line %s." % (name, linenumbers) |
| 391 result = False |
| 361 return result | 392 return result |
| 362 | 393 |
| 363 def ProcessFiles(self, files, path): | 394 def ProcessFiles(self, files, path): |
| 364 success = True | 395 success = True |
| 365 violations = 0 | 396 violations = 0 |
| 366 for file in files: | 397 for file in files: |
| 367 try: | 398 try: |
| 368 handle = open(file) | 399 handle = open(file) |
| 369 contents = handle.read() | 400 contents = handle.read() |
| 370 if not self.ProcessContents(file, contents): | 401 if not self.ProcessContents(file, contents): |
| (...skipping 13 matching lines...) Expand all Loading... |
| 384 | 415 |
| 385 | 416 |
| 386 def Main(): | 417 def Main(): |
| 387 workspace = abspath(join(dirname(sys.argv[0]), '..')) | 418 workspace = abspath(join(dirname(sys.argv[0]), '..')) |
| 388 parser = GetOptions() | 419 parser = GetOptions() |
| 389 (options, args) = parser.parse_args() | 420 (options, args) = parser.parse_args() |
| 390 success = True | 421 success = True |
| 391 print "Running C++ lint check..." | 422 print "Running C++ lint check..." |
| 392 if not options.no_lint: | 423 if not options.no_lint: |
| 393 success = CppLintProcessor().Run(workspace) and success | 424 success = CppLintProcessor().Run(workspace) and success |
| 394 print "Running copyright header and trailing whitespaces check..." | 425 print "Running copyright header, trailing whitespaces and " \ |
| 426 "two empty lines between declarations check..." |
| 395 success = SourceProcessor().Run(workspace) and success | 427 success = SourceProcessor().Run(workspace) and success |
| 396 if success: | 428 if success: |
| 397 return 0 | 429 return 0 |
| 398 else: | 430 else: |
| 399 return 1 | 431 return 1 |
| 400 | 432 |
| 401 | 433 |
| 402 if __name__ == '__main__': | 434 if __name__ == '__main__': |
| 403 sys.exit(Main()) | 435 sys.exit(Main()) |
| OLD | NEW |