Maintains module-wide state..
| 685 | |
| 686 | |
| 687 | class _CppLintState(object): |
| 688 | """Maintains module-wide state..""" |
| 689 | |
| 690 | def __init__(self): |
| 691 | self.verbose_level = 1 # global setting. |
| 692 | self.error_count = 0 # global count of reported errors |
| 693 | # filters to apply when emitting error messages |
| 694 | self.filters = _DEFAULT_FILTERS[:] |
| 695 | self.counting = 'total' # In what way are we counting errors? |
| 696 | self.errors_by_category = {} # string to int dict storing error counts |
| 697 | |
| 698 | # output format: |
| 699 | # "emacs" - format that emacs can parse (default) |
| 700 | # "vs7" - format that Microsoft Visual Studio 7 can parse |
| 701 | self.output_format = 'emacs' |
| 702 | |
| 703 | def SetOutputFormat(self, output_format): |
| 704 | """Sets the output format for errors.""" |
| 705 | self.output_format = output_format |
| 706 | |
| 707 | def SetVerboseLevel(self, level): |
| 708 | """Sets the module's verbosity, and returns the previous setting.""" |
| 709 | last_verbose_level = self.verbose_level |
| 710 | self.verbose_level = level |
| 711 | return last_verbose_level |
| 712 | |
| 713 | def SetCountingStyle(self, counting_style): |
| 714 | """Sets the module's counting options.""" |
| 715 | self.counting = counting_style |
| 716 | |
| 717 | def SetFilters(self, filters): |
| 718 | """Sets the error-message filters. |
| 719 | |
| 720 | These filters are applied when deciding whether to emit a given |
| 721 | error message. |
| 722 | |
| 723 | Args: |
| 724 | filters: A string of comma-separated filters (eg "+whitespace/indent"). |
| 725 | Each filter should start with + or -; else we die. |
| 726 | |
| 727 | Raises: |
| 728 | ValueError: The comma-separated filters did not all start with '+' or '-'. |
| 729 | E.g. "-,+whitespace,-whitespace/indent,whitespace/badfilter" |
| 730 | """ |
| 731 | # Default filters always have less priority than the flag ones. |
| 732 | self.filters = _DEFAULT_FILTERS[:] |
| 733 | for filt in filters.split(','): |
| 734 | clean_filt = filt.strip() |
| 735 | if clean_filt: |
| 736 | self.filters.append(clean_filt) |
| 737 | for filt in self.filters: |
| 738 | if not (filt.startswith('+') or filt.startswith('-')): |
| 739 | raise ValueError('Every filter in --filters must start with + or -' |
| 740 | ' (%s does not)' % filt) |
| 741 | |
| 742 | def ResetErrorCounts(self): |
| 743 | """Sets the module's error statistic back to zero.""" |
| 744 | self.error_count = 0 |