Maintains module-wide state..
| 1387 | |
| 1388 | |
| 1389 | class _CppLintState: |
| 1390 | """Maintains module-wide state..""" |
| 1391 | |
| 1392 | def __init__(self): |
| 1393 | self.verbose_level = 1 # global setting. |
| 1394 | self.error_count = 0 # global count of reported errors |
| 1395 | # filters to apply when emitting error messages |
| 1396 | self.filters = _DEFAULT_FILTERS[:] |
| 1397 | # backup of filter list. Used to restore the state after each file. |
| 1398 | self._filters_backup = self.filters[:] |
| 1399 | self.counting = "total" # In what way are we counting errors? |
| 1400 | self.errors_by_category = {} # string to int dict storing error counts |
| 1401 | self.quiet = False # Suppress non-error messages? |
| 1402 | |
| 1403 | # output format: |
| 1404 | # "emacs" - format that emacs can parse (default) |
| 1405 | # "eclipse" - format that eclipse can parse |
| 1406 | # "vs7" - format that Microsoft Visual Studio 7 can parse |
| 1407 | # "junit" - format that Jenkins, Bamboo, etc can parse |
| 1408 | # "sed" - returns a gnu sed command to fix the problem |
| 1409 | # "gsed" - like sed, but names the command gsed, e.g. for macOS homebrew users |
| 1410 | self.output_format = "emacs" |
| 1411 | |
| 1412 | # For JUnit output, save errors and failures until the end so that they |
| 1413 | # can be written into the XML |
| 1414 | self._junit_errors = [] |
| 1415 | self._junit_failures = [] |
| 1416 | |
| 1417 | def SetOutputFormat(self, output_format): |
| 1418 | """Sets the output format for errors.""" |
| 1419 | self.output_format = output_format |
| 1420 | |
| 1421 | def SetQuiet(self, quiet): |
| 1422 | """Sets the module's quiet settings, and returns the previous setting.""" |
| 1423 | last_quiet = self.quiet |
| 1424 | self.quiet = quiet |
| 1425 | return last_quiet |
| 1426 | |
| 1427 | def SetVerboseLevel(self, level): |
| 1428 | """Sets the module's verbosity, and returns the previous setting.""" |
| 1429 | last_verbose_level = self.verbose_level |
| 1430 | self.verbose_level = level |
| 1431 | return last_verbose_level |
| 1432 | |
| 1433 | def SetCountingStyle(self, counting_style): |
| 1434 | """Sets the module's counting options.""" |
| 1435 | self.counting = counting_style |
| 1436 | |
| 1437 | def SetFilters(self, filters): |
| 1438 | """Sets the error-message filters. |
| 1439 | |
| 1440 | These filters are applied when deciding whether to emit a given |
| 1441 | error message. |
| 1442 | |
| 1443 | Args: |
| 1444 | filters: A string of comma-separated filters (eg "+whitespace/indent"). |
| 1445 | Each filter should start with + or -; else we die. |
| 1446 |