Maintains module-wide state..
| 755 | |
| 756 | |
| 757 | class _CppLintState(object): |
| 758 | """Maintains module-wide state..""" |
| 759 | |
| 760 | def __init__(self): |
| 761 | self.verbose_level = 1 # global setting. |
| 762 | self.error_count = 0 # global count of reported errors |
| 763 | # filters to apply when emitting error messages |
| 764 | self.filters = _DEFAULT_FILTERS[:] |
| 765 | # backup of filter list. Used to restore the state after each file. |
| 766 | self._filters_backup = self.filters[:] |
| 767 | self.counting = 'total' # In what way are we counting errors? |
| 768 | self.errors_by_category = {} # string to int dict storing error counts |
| 769 | |
| 770 | # output format: |
| 771 | # "emacs" - format that emacs can parse (default) |
| 772 | # "vs7" - format that Microsoft Visual Studio 7 can parse |
| 773 | self.output_format = 'emacs' |
| 774 | |
| 775 | def SetOutputFormat(self, output_format): |
| 776 | """Sets the output format for errors.""" |
| 777 | self.output_format = output_format |
| 778 | |
| 779 | def SetVerboseLevel(self, level): |
| 780 | """Sets the module's verbosity, and returns the previous setting.""" |
| 781 | last_verbose_level = self.verbose_level |
| 782 | self.verbose_level = level |
| 783 | return last_verbose_level |
| 784 | |
| 785 | def SetCountingStyle(self, counting_style): |
| 786 | """Sets the module's counting options.""" |
| 787 | self.counting = counting_style |
| 788 | |
| 789 | def SetFilters(self, filters): |
| 790 | """Sets the error-message filters. |
| 791 | |
| 792 | These filters are applied when deciding whether to emit a given |
| 793 | error message. |
| 794 | |
| 795 | Args: |
| 796 | filters: A string of comma-separated filters (eg "+whitespace/indent"). |
| 797 | Each filter should start with + or -; else we die. |
| 798 | |
| 799 | Raises: |
| 800 | ValueError: The comma-separated filters did not all start with '+' or '-'. |
| 801 | E.g. "-,+whitespace,-whitespace/indent,whitespace/badfilter" |
| 802 | """ |
| 803 | # Default filters always have less priority than the flag ones. |
| 804 | self.filters = _DEFAULT_FILTERS[:] |
| 805 | self.AddFilters(filters) |
| 806 | |
| 807 | def AddFilters(self, filters): |
| 808 | """ Adds more filters to the existing list of error-message filters. """ |
| 809 | for filt in filters.split(','): |
| 810 | clean_filt = filt.strip() |
| 811 | if clean_filt: |
| 812 | self.filters.append(clean_filt) |
| 813 | for filt in self.filters: |
| 814 | if not (filt.startswith('+') or filt.startswith('-')): |