Maintains module-wide state..
| 865 | |
| 866 | |
| 867 | class _CppLintState(object): |
| 868 | """Maintains module-wide state..""" |
| 869 | |
| 870 | def __init__(self): |
| 871 | self.verbose_level = 1 # global setting. |
| 872 | self.error_count = 0 # global count of reported errors |
| 873 | # filters to apply when emitting error messages |
| 874 | self.filters = _DEFAULT_FILTERS[:] |
| 875 | # backup of filter list. Used to restore the state after each file. |
| 876 | self._filters_backup = self.filters[:] |
| 877 | self.counting = 'total' # In what way are we counting errors? |
| 878 | self.errors_by_category = {} # string to int dict storing error counts |
| 879 | self.quiet = False # Suppress non-error messagess? |
| 880 | |
| 881 | # output format: |
| 882 | # "emacs" - format that emacs can parse (default) |
| 883 | # "vs7" - format that Microsoft Visual Studio 7 can parse |
| 884 | self.output_format = 'emacs' |
| 885 | |
| 886 | def SetOutputFormat(self, output_format): |
| 887 | """Sets the output format for errors.""" |
| 888 | self.output_format = output_format |
| 889 | |
| 890 | def SetQuiet(self, quiet): |
| 891 | """Sets the module's quiet settings, and returns the previous setting.""" |
| 892 | last_quiet = self.quiet |
| 893 | self.quiet = quiet |
| 894 | return last_quiet |
| 895 | |
| 896 | def SetVerboseLevel(self, level): |
| 897 | """Sets the module's verbosity, and returns the previous setting.""" |
| 898 | last_verbose_level = self.verbose_level |
| 899 | self.verbose_level = level |
| 900 | return last_verbose_level |
| 901 | |
| 902 | def SetCountingStyle(self, counting_style): |
| 903 | """Sets the module's counting options.""" |
| 904 | self.counting = counting_style |
| 905 | |
| 906 | def SetFilters(self, filters): |
| 907 | """Sets the error-message filters. |
| 908 | |
| 909 | These filters are applied when deciding whether to emit a given |
| 910 | error message. |
| 911 | |
| 912 | Args: |
| 913 | filters: A string of comma-separated filters (eg "+whitespace/indent"). |
| 914 | Each filter should start with + or -; else we die. |
| 915 | |
| 916 | Raises: |
| 917 | ValueError: The comma-separated filters did not all start with '+' or '-'. |
| 918 | E.g. "-,+whitespace,-whitespace/indent,whitespace/badfilter" |
| 919 | """ |
| 920 | # Default filters always have less priority than the flag ones. |
| 921 | self.filters = _DEFAULT_FILTERS[:] |
| 922 | self.AddFilters(filters) |
| 923 | |
| 924 | def AddFilters(self, filters): |