Maintains module-wide state..
| 1247 | |
| 1248 | |
| 1249 | class _CppLintState(object): |
| 1250 | """Maintains module-wide state..""" |
| 1251 | |
| 1252 | def __init__(self): |
| 1253 | self.verbose_level = 1 # global setting. |
| 1254 | self.error_count = 0 # global count of reported errors |
| 1255 | # filters to apply when emitting error messages |
| 1256 | self.filters = _DEFAULT_FILTERS[:] |
| 1257 | # backup of filter list. Used to restore the state after each file. |
| 1258 | self._filters_backup = self.filters[:] |
| 1259 | self.counting = 'total' # In what way are we counting errors? |
| 1260 | self.errors_by_category = {} # string to int dict storing error counts |
| 1261 | self.quiet = False # Suppress non-error messages? |
| 1262 | |
| 1263 | # output format: |
| 1264 | # "emacs" - format that emacs can parse (default) |
| 1265 | # "eclipse" - format that eclipse can parse |
| 1266 | # "vs7" - format that Microsoft Visual Studio 7 can parse |
| 1267 | # "junit" - format that Jenkins, Bamboo, etc can parse |
| 1268 | # "sed" - returns a gnu sed command to fix the problem |
| 1269 | # "gsed" - like sed, but names the command gsed, e.g. for macOS homebrew users |
| 1270 | self.output_format = 'emacs' |
| 1271 | |
| 1272 | # For JUnit output, save errors and failures until the end so that they |
| 1273 | # can be written into the XML |
| 1274 | self._junit_errors = [] |
| 1275 | self._junit_failures = [] |
| 1276 | |
| 1277 | def SetOutputFormat(self, output_format): |
| 1278 | """Sets the output format for errors.""" |
| 1279 | self.output_format = output_format |
| 1280 | |
| 1281 | def SetQuiet(self, quiet): |
| 1282 | """Sets the module's quiet settings, and returns the previous setting.""" |
| 1283 | last_quiet = self.quiet |
| 1284 | self.quiet = quiet |
| 1285 | return last_quiet |
| 1286 | |
| 1287 | def SetVerboseLevel(self, level): |
| 1288 | """Sets the module's verbosity, and returns the previous setting.""" |
| 1289 | last_verbose_level = self.verbose_level |
| 1290 | self.verbose_level = level |
| 1291 | return last_verbose_level |
| 1292 | |
| 1293 | def SetCountingStyle(self, counting_style): |
| 1294 | """Sets the module's counting options.""" |
| 1295 | self.counting = counting_style |
| 1296 | |
| 1297 | def SetFilters(self, filters): |
| 1298 | """Sets the error-message filters. |
| 1299 | |
| 1300 | These filters are applied when deciding whether to emit a given |
| 1301 | error message. |
| 1302 | |
| 1303 | Args: |
| 1304 | filters: A string of comma-separated filters (eg "+whitespace/indent"). |
| 1305 | Each filter should start with + or -; else we die. |
| 1306 |