OLD | NEW |
1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
2 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) | 2 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) |
3 # Copyright (C) 2010 ProFUSION embedded systems | 3 # Copyright (C) 2010 ProFUSION embedded systems |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 from checkers.common import categories as CommonCategories | 38 from checkers.common import categories as CommonCategories |
39 from checkers.common import CarriageReturnChecker | 39 from checkers.common import CarriageReturnChecker |
40 from checkers.cpp import CppChecker | 40 from checkers.cpp import CppChecker |
41 from checkers.cmake import CMakeChecker | 41 from checkers.cmake import CMakeChecker |
42 from checkers.jsonchecker import JSONChecker | 42 from checkers.jsonchecker import JSONChecker |
43 from checkers.png import PNGChecker | 43 from checkers.png import PNGChecker |
44 from checkers.python import PythonChecker | 44 from checkers.python import PythonChecker |
45 from checkers.test_expectations import TestExpectationsChecker | 45 from checkers.test_expectations import TestExpectationsChecker |
46 from checkers.text import TextChecker | 46 from checkers.text import TextChecker |
47 from checkers.watchlist import WatchListChecker | |
48 from checkers.xcodeproj import XcodeProjectFileChecker | 47 from checkers.xcodeproj import XcodeProjectFileChecker |
49 from checkers.xml import XMLChecker | 48 from checkers.xml import XMLChecker |
50 from error_handlers import DefaultStyleErrorHandler | 49 from error_handlers import DefaultStyleErrorHandler |
51 from filter import FilterConfiguration | 50 from filter import FilterConfiguration |
52 from optparser import ArgumentParser | 51 from optparser import ArgumentParser |
53 from optparser import DefaultCommandOptionValues | 52 from optparser import DefaultCommandOptionValues |
54 from webkitpy.common.system.logutils import configure_logging as _configure_logg
ing | 53 from webkitpy.common.system.logutils import configure_logging as _configure_logg
ing |
55 | 54 |
56 | 55 |
57 _log = logging.getLogger(__name__) | 56 _log = logging.getLogger(__name__) |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 handlers=handlers) | 503 handlers=handlers) |
505 | 504 |
506 return handlers | 505 return handlers |
507 | 506 |
508 | 507 |
509 # Enum-like idiom | 508 # Enum-like idiom |
510 class FileType: | 509 class FileType: |
511 | 510 |
512 NONE = 0 # FileType.NONE evaluates to False. | 511 NONE = 0 # FileType.NONE evaluates to False. |
513 # Alphabetize remaining types | 512 # Alphabetize remaining types |
514 CHANGELOG = 1 | 513 # CHANGELOG = 1 |
515 CPP = 2 | 514 CPP = 2 |
516 JSON = 3 | 515 JSON = 3 |
517 PNG = 4 | 516 PNG = 4 |
518 PYTHON = 5 | 517 PYTHON = 5 |
519 TEXT = 6 | 518 TEXT = 6 |
520 WATCHLIST = 7 | 519 # WATCHLIST = 7 |
521 XML = 8 | 520 XML = 8 |
522 XCODEPROJ = 9 | 521 XCODEPROJ = 9 |
523 CMAKE = 10 | 522 CMAKE = 10 |
524 | 523 |
525 | 524 |
526 class CheckerDispatcher(object): | 525 class CheckerDispatcher(object): |
527 | 526 |
528 """Supports determining whether and how to check style, based on path.""" | 527 """Supports determining whether and how to check style, based on path.""" |
529 | 528 |
530 def _file_extension(self, file_path): | 529 def _file_extension(self, file_path): |
(...skipping 16 matching lines...) Expand all Loading... |
547 for skipped_file in _SKIPPED_FILES_WITH_WARNING: | 546 for skipped_file in _SKIPPED_FILES_WITH_WARNING: |
548 if self._should_skip_file_path(file_path, skipped_file): | 547 if self._should_skip_file_path(file_path, skipped_file): |
549 return True | 548 return True |
550 return False | 549 return False |
551 | 550 |
552 def should_skip_without_warning(self, file_path): | 551 def should_skip_without_warning(self, file_path): |
553 """Return whether the given file should be skipped without a warning.""" | 552 """Return whether the given file should be skipped without a warning.""" |
554 if not self._file_type(file_path): # FileType.NONE. | 553 if not self._file_type(file_path): # FileType.NONE. |
555 return True | 554 return True |
556 # Since "LayoutTests" is in _SKIPPED_FILES_WITHOUT_WARNING, make | 555 # Since "LayoutTests" is in _SKIPPED_FILES_WITHOUT_WARNING, make |
557 # an exception to prevent files like "LayoutTests/ChangeLog" and | 556 # an exception to prevent files like 'TestExpectations' from being skipp
ed. |
558 # "LayoutTests/ChangeLog-2009-06-16" from being skipped. | |
559 # Files like 'TestExpectations' are also should not be skipped. | |
560 # | 557 # |
561 # FIXME: Figure out a good way to avoid having to add special logic | 558 # FIXME: Figure out a good way to avoid having to add special logic |
562 # for this special case. | 559 # for this special case. |
563 basename = os.path.basename(file_path) | 560 basename = os.path.basename(file_path) |
564 if basename == 'TestExpectations': | 561 if basename == 'TestExpectations': |
565 return False | 562 return False |
566 for skipped_file in _SKIPPED_FILES_WITHOUT_WARNING: | 563 for skipped_file in _SKIPPED_FILES_WITHOUT_WARNING: |
567 if self._should_skip_file_path(file_path, skipped_file): | 564 if self._should_skip_file_path(file_path, skipped_file): |
568 return True | 565 return True |
569 return False | 566 return False |
(...skipping 12 matching lines...) Expand all Loading... |
582 # Treat stdin as C++. Since the extension is unknown when | 579 # Treat stdin as C++. Since the extension is unknown when |
583 # reading from stdin, cpp_style tests should not rely on | 580 # reading from stdin, cpp_style tests should not rely on |
584 # the extension. | 581 # the extension. |
585 return FileType.CPP | 582 return FileType.CPP |
586 elif file_extension == _JSON_FILE_EXTENSION: | 583 elif file_extension == _JSON_FILE_EXTENSION: |
587 return FileType.JSON | 584 return FileType.JSON |
588 elif file_extension == _PYTHON_FILE_EXTENSION: | 585 elif file_extension == _PYTHON_FILE_EXTENSION: |
589 return FileType.PYTHON | 586 return FileType.PYTHON |
590 elif file_extension in _XML_FILE_EXTENSIONS: | 587 elif file_extension in _XML_FILE_EXTENSIONS: |
591 return FileType.XML | 588 return FileType.XML |
592 elif os.path.basename(file_path).startswith('ChangeLog'): | |
593 return FileType.CHANGELOG | |
594 elif os.path.basename(file_path) == 'watchlist': | |
595 return FileType.WATCHLIST | |
596 elif file_extension == _XCODEPROJ_FILE_EXTENSION: | 589 elif file_extension == _XCODEPROJ_FILE_EXTENSION: |
597 return FileType.XCODEPROJ | 590 return FileType.XCODEPROJ |
598 elif file_extension == _PNG_FILE_EXTENSION: | 591 elif file_extension == _PNG_FILE_EXTENSION: |
599 return FileType.PNG | 592 return FileType.PNG |
600 elif ((file_extension == _CMAKE_FILE_EXTENSION) or os.path.basename(file
_path) == 'CMakeLists.txt'): | 593 elif ((file_extension == _CMAKE_FILE_EXTENSION) or os.path.basename(file
_path) == 'CMakeLists.txt'): |
601 return FileType.CMAKE | 594 return FileType.CMAKE |
602 elif ((not file_extension and os.path.join("Tools", "Scripts") in file_p
ath) or | 595 elif ((not file_extension and os.path.join("Tools", "Scripts") in file_p
ath) or |
603 file_extension in _TEXT_FILE_EXTENSIONS or os.path.basename(file_p
ath) == 'TestExpectations'): | 596 file_extension in _TEXT_FILE_EXTENSIONS or os.path.basename(file_p
ath) == 'TestExpectations'): |
604 return FileType.TEXT | 597 return FileType.TEXT |
605 else: | 598 else: |
606 return FileType.NONE | 599 return FileType.NONE |
607 | 600 |
608 def _create_checker(self, file_type, file_path, handle_style_error, | 601 def _create_checker(self, file_type, file_path, handle_style_error, |
609 min_confidence): | 602 min_confidence): |
610 """Instantiate and return a style checker based on file type.""" | 603 """Instantiate and return a style checker based on file type.""" |
611 if file_type == FileType.NONE: | 604 if file_type == FileType.NONE: |
612 checker = None | 605 checker = None |
613 elif file_type == FileType.CHANGELOG: | |
614 checker = None | |
615 elif file_type == FileType.CPP: | 606 elif file_type == FileType.CPP: |
616 file_extension = self._file_extension(file_path) | 607 file_extension = self._file_extension(file_path) |
617 checker = CppChecker(file_path, file_extension, | 608 checker = CppChecker(file_path, file_extension, |
618 handle_style_error, min_confidence) | 609 handle_style_error, min_confidence) |
619 elif file_type == FileType.JSON: | 610 elif file_type == FileType.JSON: |
620 checker = JSONChecker(file_path, handle_style_error) | 611 checker = JSONChecker(file_path, handle_style_error) |
621 elif file_type == FileType.PYTHON: | 612 elif file_type == FileType.PYTHON: |
622 checker = PythonChecker(file_path, handle_style_error) | 613 checker = PythonChecker(file_path, handle_style_error) |
623 elif file_type == FileType.XML: | 614 elif file_type == FileType.XML: |
624 checker = XMLChecker(file_path, handle_style_error) | 615 checker = XMLChecker(file_path, handle_style_error) |
625 elif file_type == FileType.XCODEPROJ: | 616 elif file_type == FileType.XCODEPROJ: |
626 checker = XcodeProjectFileChecker(file_path, handle_style_error) | 617 checker = XcodeProjectFileChecker(file_path, handle_style_error) |
627 elif file_type == FileType.PNG: | 618 elif file_type == FileType.PNG: |
628 checker = PNGChecker(file_path, handle_style_error) | 619 checker = PNGChecker(file_path, handle_style_error) |
629 elif file_type == FileType.CMAKE: | 620 elif file_type == FileType.CMAKE: |
630 checker = CMakeChecker(file_path, handle_style_error) | 621 checker = CMakeChecker(file_path, handle_style_error) |
631 elif file_type == FileType.TEXT: | 622 elif file_type == FileType.TEXT: |
632 basename = os.path.basename(file_path) | 623 basename = os.path.basename(file_path) |
633 if basename == 'TestExpectations': | 624 if basename == 'TestExpectations': |
634 checker = TestExpectationsChecker(file_path, handle_style_error) | 625 checker = TestExpectationsChecker(file_path, handle_style_error) |
635 else: | 626 else: |
636 checker = TextChecker(file_path, handle_style_error) | 627 checker = TextChecker(file_path, handle_style_error) |
637 elif file_type == FileType.WATCHLIST: | |
638 checker = WatchListChecker(file_path, handle_style_error) | |
639 else: | 628 else: |
640 raise ValueError('Invalid file type "%(file_type)s": the only valid
file types ' | 629 raise ValueError('Invalid file type "%(file_type)s": the only valid
file types ' |
641 "are %(NONE)s, %(CPP)s, and %(TEXT)s." | 630 "are %(NONE)s, %(CPP)s, and %(TEXT)s." |
642 % {"file_type": file_type, | 631 % {"file_type": file_type, |
643 "NONE": FileType.NONE, | 632 "NONE": FileType.NONE, |
644 "CPP": FileType.CPP, | 633 "CPP": FileType.CPP, |
645 "TEXT": FileType.TEXT}) | 634 "TEXT": FileType.TEXT}) |
646 | 635 |
647 return checker | 636 return checker |
648 | 637 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 checker = self._dispatcher.dispatch(file_path, | 868 checker = self._dispatcher.dispatch(file_path, |
880 style_error_handler, | 869 style_error_handler, |
881 min_confidence) | 870 min_confidence) |
882 | 871 |
883 if checker is None: | 872 if checker is None: |
884 raise AssertionError("File should not be checked: '%s'" % file_path) | 873 raise AssertionError("File should not be checked: '%s'" % file_path) |
885 | 874 |
886 _log.debug("Using class: " + checker.__class__.__name__) | 875 _log.debug("Using class: " + checker.__class__.__name__) |
887 | 876 |
888 checker.check(lines) | 877 checker.check(lines) |
OLD | NEW |