Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75d2d99

Browse files
suppress C++-only categories on C file extensions (#318)
".h" files don't, because many C++ headers also use this extension Closes #71 --------- Co-authored-by: Christian Clauss <[email protected]>
1 parent 9107df4 commit 75d2d99

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Changelog
88
Yet another overdue... hotfix. Sorry this took so long.
99

1010
* The false positive for indented function parameters in namespaces was eradicated. (https://github.com/cpplint/cpplint/pull/304)
11-
* build/include-what-you-use now recognizes c-style headers, such as <stdio.h> for symbols from <cstdio>. (https://github.com/cpplint/cpplint/pull/319)
11+
* Files that end in ".c", ".C", or ".cu" will now also automatically suppress C++-only categories. Previously, `// NO_LINT_C` was required. (https://github.com/cpplint/cpplint/pull/308)
12+
* build/include-what-you-use now recognizes c-style headers such as <stdio.h> for symbols from <cstdio>. (https://github.com/cpplint/cpplint/pull/319)
1213
* Ruff was ran on the project to improve performance and reader comprehension thanks to @cclauss.
1314

1415
2.0 (2024-10-06)

cpplint.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,6 @@
934934
"Missing space after ,": r"s/,\([^ ]\)/, \1/g",
935935
}
936936

937-
# {str, set(int)}: a map from error categories to sets of linenumbers
938-
# on which those errors are expected and should be suppressed.
939-
_error_suppressions: dict[str, set[int]] = {}
940-
941937
# The root directory used for deriving header guard CPP variable.
942938
# This is set by --root flag.
943939
_root = None
@@ -1036,7 +1032,9 @@ def Clear(self):
10361032
self._open_block_suppression = None
10371033

10381034

1039-
_error_suppressions = ErrorSuppressions() # type: ignore[assignment]
1035+
# {str, set(int)}: a map from error categories to sets of linenumbers
1036+
# on which those errors are expected and should be suppressed.
1037+
_error_suppressions = ErrorSuppressions()
10401038

10411039

10421040
def ProcessHppHeadersOption(val):
@@ -1166,22 +1164,18 @@ def ProcessCategory(category):
11661164
)
11671165

11681166

1169-
def ProcessGlobalSuppresions(lines):
1170-
"""Deprecated; use ProcessGlobalSuppressions."""
1171-
ProcessGlobalSuppressions(lines)
1172-
1173-
1174-
def ProcessGlobalSuppressions(lines):
1167+
def ProcessGlobalSuppressions(filename: str, lines: list[str]) -> None:
11751168
"""Updates the list of global error suppressions.
11761169
11771170
Parses any lint directives in the file that have global effect.
11781171
11791172
Args:
11801173
lines: An array of strings, each representing a line of the file, with the
11811174
last element being empty if the file is terminated with a newline.
1175+
filename: str, the name of the input file.
11821176
"""
11831177
for line in lines:
1184-
if _SEARCH_C_FILE.search(line):
1178+
if _SEARCH_C_FILE.search(line) or filename.lower().endswith((".c", ".cu")):
11851179
for category in _DEFAULT_C_SUPPRESSED_CATEGORIES:
11861180
_error_suppressions.AddGlobalSuppression(category)
11871181
if _SEARCH_KERNEL_FILE.search(line):
@@ -7279,7 +7273,7 @@ def ProcessFileData(filename, file_extension, lines, error, extra_check_function
72797273
ResetNolintSuppressions()
72807274

72817275
CheckForCopyright(filename, lines, error)
7282-
ProcessGlobalSuppressions(lines)
7276+
ProcessGlobalSuppressions(filename, lines)
72837277
RemoveMultiLineComments(filename, lines, error)
72847278
clean_lines = CleansedLines(lines)
72857279

cpplint_unittest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,17 @@ def testErrorSuppression(self):
470470
# All categories suppressed: (two aliases)
471471
self.TestLint("long a = (int64_t) 65; // NOLINT", "")
472472
self.TestLint("long a = (int64_t) 65; // NOLINT(*)", "")
473+
474+
# Linting a C file
475+
error_collector = ErrorCollector(self.assertTrue)
476+
cpplint.ProcessFileData(
477+
"test.c",
478+
"c",
479+
["// Copyright 2014 Your Majesty.", "int64_t a = (int64_t) 65;", ""],
480+
error_collector,
481+
)
482+
assert error_collector.Results() == ""
483+
473484
# Malformed NOLINT directive:
474485
self.TestLint(
475486
"long a = 65; // NOLINT(foo)",

samples/vlc-sample/simple.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ src/*
44
Done processing src/libvlc.c
55
Done processing src/libvlc.h
66
Done processing src/missing.c
7-
Total errors found: 601
7+
Total errors found: 599
88

99
src/libvlc.c:41: Found C system header after other header. Should be: libvlc.h, c system, c++ system, other. [build/include_order] [4]
1010
src/libvlc.c:47: Found C system header after other header. Should be: libvlc.h, c system, c++ system, other. [build/include_order] [4]
@@ -19,7 +19,6 @@ src/libvlc.c:86: Extra space before ( in function call [whitespace/parens] [4]
1919
src/libvlc.c:86: Extra space before ) [whitespace/parens] [2]
2020
src/libvlc.c:92: Extra space after ( in function call [whitespace/parens] [4]
2121
src/libvlc.c:93: { should almost always be at the end of the previous line [whitespace/braces] [4]
22-
src/libvlc.c:98: Using C-style cast. Use reinterpret_cast<vlc_object_t *>(...) instead [readability/casting] [4]
2322
src/libvlc.c:99: Extra space before ) [whitespace/parens] [2]
2423
src/libvlc.c:100: Missing space before ( in if( [whitespace/parens] [5]
2524
src/libvlc.c:103: Extra space before ( in function call [whitespace/parens] [4]
@@ -74,7 +73,6 @@ src/libvlc.c:219: Extra space before ) [whitespace/parens] [2]
7473
src/libvlc.c:220: Missing space before ( in if( [whitespace/parens] [5]
7574
src/libvlc.c:221: { should almost always be at the end of the previous line [whitespace/braces] [4]
7675
src/libvlc.c:222: Extra space after ( in function call [whitespace/parens] [4]
77-
src/libvlc.c:222: Using C-style cast. Use static_cast<int>(...) instead [readability/casting] [4]
7876
src/libvlc.c:223: Extra space after ( in function call [whitespace/parens] [4]
7977
src/libvlc.c:223: Extra space before ) [whitespace/parens] [2]
8078
src/libvlc.c:224: Extra space after ( in function call [whitespace/parens] [4]

0 commit comments

Comments
 (0)