Logs the fact we've found a lint error. We log where the error was found, and also our confidence in the error, that is, how certain we are this is a legitimate style regression, and not a misidentification or a use that's sometimes justified. False positives can be suppressed by the use o
(filename, linenum, category, confidence, message)
| 1681 | |
| 1682 | |
| 1683 | def Error(filename, linenum, category, confidence, message): |
| 1684 | """Logs the fact we've found a lint error. |
| 1685 | |
| 1686 | We log where the error was found, and also our confidence in the error, |
| 1687 | that is, how certain we are this is a legitimate style regression, and |
| 1688 | not a misidentification or a use that's sometimes justified. |
| 1689 | |
| 1690 | False positives can be suppressed by the use of |
| 1691 | "cpplint(category)" comments on the offending line. These are |
| 1692 | parsed into _error_suppressions. |
| 1693 | |
| 1694 | Args: |
| 1695 | filename: The name of the file containing the error. |
| 1696 | linenum: The number of the line containing the error. |
| 1697 | category: A string used to describe the "category" this bug |
| 1698 | falls under: "whitespace", say, or "runtime". Categories |
| 1699 | may have a hierarchy separated by slashes: "whitespace/indent". |
| 1700 | confidence: A number from 1-5 representing a confidence score for |
| 1701 | the error, with 5 meaning that we are certain of the problem, |
| 1702 | and 1 meaning that it could be a legitimate construct. |
| 1703 | message: The error message. |
| 1704 | """ |
| 1705 | if _ShouldPrintError(category, confidence, linenum): |
| 1706 | _cpplint_state.IncrementErrorCount(category) |
| 1707 | if _cpplint_state.output_format == 'vs7': |
| 1708 | _cpplint_state.PrintError('%s(%s): error cpplint: [%s] %s [%d]\n' % ( |
| 1709 | filename, linenum, category, message, confidence)) |
| 1710 | elif _cpplint_state.output_format == 'eclipse': |
| 1711 | sys.stderr.write('%s:%s: warning: %s [%s] [%d]\n' % ( |
| 1712 | filename, linenum, message, category, confidence)) |
| 1713 | elif _cpplint_state.output_format == 'junit': |
| 1714 | _cpplint_state.AddJUnitFailure(filename, linenum, message, category, |
| 1715 | confidence) |
| 1716 | elif _cpplint_state.output_format in ['sed', 'gsed']: |
| 1717 | if message in _SED_FIXUPS: |
| 1718 | sys.stdout.write(_cpplint_state.output_format + " -i '%s%s' %s # %s [%s] [%d]\n" % ( |
| 1719 | linenum, _SED_FIXUPS[message], filename, message, category, confidence)) |
| 1720 | else: |
| 1721 | sys.stderr.write('# %s:%s: "%s" [%s] [%d]\n' % ( |
| 1722 | filename, linenum, message, category, confidence)) |
| 1723 | else: |
| 1724 | final_message = '%s:%s: %s [%s] [%d]\n' % ( |
| 1725 | filename, linenum, message, category, confidence) |
| 1726 | sys.stderr.write(final_message) |
| 1727 | |
| 1728 | # Matches standard C++ escape sequences per 2.13.2.3 of the C++ standard. |
| 1729 | _RE_PATTERN_CLEANSE_LINE_ESCAPES = re.compile( |
no test coverage detected