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 t
(filename, linenum, category, confidence, message)
| 1842 | |
| 1843 | |
| 1844 | def Error(filename, linenum, category, confidence, message): |
| 1845 | """Logs the fact we've found a lint error. |
| 1846 | |
| 1847 | We log where the error was found, and also our confidence in the error, |
| 1848 | that is, how certain we are this is a legitimate style regression, and |
| 1849 | not a misidentification or a use that's sometimes justified. |
| 1850 | |
| 1851 | False positives can be suppressed by the use of "NOLINT(category)" |
| 1852 | comments, NOLINTNEXTLINE or in blocks started by NOLINTBEGIN. These |
| 1853 | are parsed into _error_suppressions. |
| 1854 | |
| 1855 | Args: |
| 1856 | filename: The name of the file containing the error. |
| 1857 | linenum: The number of the line containing the error. |
| 1858 | category: A string used to describe the "category" this bug |
| 1859 | falls under: "whitespace", say, or "runtime". Categories |
| 1860 | may have a hierarchy separated by slashes: "whitespace/indent". |
| 1861 | confidence: A number from 1-5 representing a confidence score for |
| 1862 | the error, with 5 meaning that we are certain of the problem, |
| 1863 | and 1 meaning that it could be a legitimate construct. |
| 1864 | message: The error message. |
| 1865 | """ |
| 1866 | if _ShouldPrintError(category, confidence, filename, linenum): |
| 1867 | _cpplint_state.IncrementErrorCount(category) |
| 1868 | if _cpplint_state.output_format == "vs7": |
| 1869 | _cpplint_state.PrintError( |
| 1870 | f"{filename}({linenum}): error cpplint: [{category}] {message} [{confidence}]\n" |
| 1871 | ) |
| 1872 | elif _cpplint_state.output_format == "eclipse": |
| 1873 | sys.stderr.write( |
| 1874 | f"{filename}:{linenum}: warning: {message} [{category}] [{confidence}]\n" |
| 1875 | ) |
| 1876 | elif _cpplint_state.output_format == "junit": |
| 1877 | _cpplint_state.AddJUnitFailure(filename, linenum, message, category, confidence) |
| 1878 | elif _cpplint_state.output_format in ["sed", "gsed"]: |
| 1879 | if message in _SED_FIXUPS: |
| 1880 | sys.stdout.write( |
| 1881 | f"{_cpplint_state.output_format} -i" |
| 1882 | f" '{linenum}{_SED_FIXUPS[message]}' {filename}" |
| 1883 | f" # {message} [{category}] [{confidence}]\n" |
| 1884 | ) |
| 1885 | else: |
| 1886 | sys.stderr.write( |
| 1887 | f'# {filename}:{linenum}: "{message}" [{category}] [{confidence}]\n' |
| 1888 | ) |
| 1889 | else: |
| 1890 | final_message = f"{filename}:{linenum}: {message} [{category}] [{confidence}]\n" |
| 1891 | sys.stderr.write(final_message) |
| 1892 | |
| 1893 | |
| 1894 | # Matches standard C++ escape sequences per 2.13.2.3 of the C++ standard. |
no test coverage detected