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