Updates the global list of line error-suppressions. Parses any NOLINT comments on the current line, updating the global error_suppressions store. Reports an error if the NOLINT comment was malformed. Args: filename: str, the name of the input file. raw_line: str, the l
(filename, raw_line, linenum, error)
| 1132 | |
| 1133 | |
| 1134 | def ParseNolintSuppressions(filename, raw_line, linenum, error): |
| 1135 | """Updates the global list of line error-suppressions. |
| 1136 | |
| 1137 | Parses any NOLINT comments on the current line, updating the global |
| 1138 | error_suppressions store. Reports an error if the NOLINT comment |
| 1139 | was malformed. |
| 1140 | |
| 1141 | Args: |
| 1142 | filename: str, the name of the input file. |
| 1143 | raw_line: str, the line of input text, with comments. |
| 1144 | linenum: int, the number of the current line. |
| 1145 | error: function, an error handler. |
| 1146 | """ |
| 1147 | if matched := re.search(r"\bNOLINT(NEXTLINE|BEGIN|END)?\b(\([^)]+\))?", raw_line): |
| 1148 | no_lint_type = matched.group(1) |
| 1149 | if no_lint_type == "NEXTLINE": |
| 1150 | |
| 1151 | def ProcessCategory(category): |
| 1152 | _error_suppressions.AddLineSuppression(category, linenum + 1) |
| 1153 | elif no_lint_type == "BEGIN": |
| 1154 | if _error_suppressions.HasOpenBlock(): |
| 1155 | error( |
| 1156 | filename, |
| 1157 | linenum, |
| 1158 | "readability/nolint", |
| 1159 | 5, |
| 1160 | ( |
| 1161 | "NONLINT block already defined on line " |
| 1162 | f"{_error_suppressions.GetOpenBlockStart()}" |
| 1163 | ), |
| 1164 | ) |
| 1165 | |
| 1166 | def ProcessCategory(category): |
| 1167 | _error_suppressions.StartBlockSuppression(category, linenum) |
| 1168 | elif no_lint_type == "END": |
| 1169 | if not _error_suppressions.HasOpenBlock(): |
| 1170 | error(filename, linenum, "readability/nolint", 5, "Not in a NOLINT block") |
| 1171 | |
| 1172 | def ProcessCategory(category): |
| 1173 | if category is not None: |
| 1174 | error( |
| 1175 | filename, |
| 1176 | linenum, |
| 1177 | "readability/nolint", |
| 1178 | 5, |
| 1179 | f"NOLINT categories not supported in block END: {category}", |
| 1180 | ) |
| 1181 | _error_suppressions.EndBlockSuppression(linenum) |
| 1182 | else: |
| 1183 | |
| 1184 | def ProcessCategory(category): |
| 1185 | _error_suppressions.AddLineSuppression(category, linenum) |
| 1186 | |
| 1187 | categories = matched.group(2) |
| 1188 | if categories in (None, "(*)"): # => "suppress all" |
| 1189 | ProcessCategory(None) |
| 1190 | elif categories.startswith("(") and categories.endswith(")"): |
| 1191 | for category in {c.strip() for c in categories[1:-1].split(",")}: |
no test coverage detected
searching dependent graphs…