Skip to content

Commit ec42a60

Browse files
committed
fix(nolint): skip unopened NOLINTEND blocks that specify a category
these are often for external tools like clang-tidy instead
1 parent c72387f commit ec42a60

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

cpplint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,11 @@ def ProcessCategory(category):
11571157
_error_suppressions.StartBlockSuppression(category, linenum)
11581158
elif no_lint_type == "END":
11591159
if not _error_suppressions.HasOpenBlock():
1160-
error(filename, linenum, "readability/nolint", 5, "Not in a NOLINT block")
1160+
if matched.group(2) not in (None, "(*)"):
1161+
# Has category; probably a clang-tidy rule. Safer to ignore.
1162+
pass
1163+
else:
1164+
error(filename, linenum, "readability/nolint", 5, "Not in a NOLINT block")
11611165

11621166
def ProcessCategory(category):
11631167
if category is not None:

cpplint_unittest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,24 @@ def testErrorSuppression(self):
773773
== "NOLINT categories not supported in block END: readability/casting "
774774
"[readability/nolint] [5]"
775775
)
776+
# categories for external tools like clang-tidy should be ignored
777+
error_collector = ErrorCollector(self.assertTrue)
778+
cpplint.ProcessFileData(
779+
"test.cc",
780+
"cc",
781+
[
782+
"// Copyright 2026 Space Dot",
783+
"// NOLINTBEGIN(clang-analyzer-core.uninitialized.UndefReturn)",
784+
"long c = 418;",
785+
"// NOLINTEND(clang-analyzer-core.uninitialized.UndefReturn)",
786+
"",
787+
],
788+
error_collector,
789+
)
790+
assert (
791+
error_collector.Results()
792+
== "Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]"
793+
)
776794
# nested NOLINTBEGIN is not allowed
777795
error_collector = ErrorCollector(self.assertTrue)
778796
cpplint.ProcessFileData(

0 commit comments

Comments
 (0)