|
68 | 68 | [--filter=-x,+y,...] |
69 | 69 | [--counting=total|toplevel|detailed] [--root=subdir] |
70 | 70 | [--repository=path] |
71 | | - [--linelength=digits] [--headers=x,y,...] |
| 71 | + [--linelength=digits] [--headers=x,y,...] [--third_party_headers=pattern] |
72 | 72 | [--recursive] |
73 | 73 | [--exclude=path] |
74 | 74 | [--extensions=hpp,cpp,...] |
|
240 | 240 | The header extensions that cpplint will treat as .h in checks. Values are |
241 | 241 | automatically added to --extensions list. |
242 | 242 | (by default, only files with extensions %s will be assumed to be headers) |
| 243 | + third_party_headers=pattern |
| 244 | + Regex for identifying third-party headers to exclude from include checks. |
243 | 245 |
|
244 | 246 | Examples: |
245 | 247 | --headers=%s |
|
256 | 258 | linelength=80 |
257 | 259 | root=subdir |
258 | 260 | headers=x,y,... |
| 261 | + third_party_headers=pattern |
259 | 262 |
|
260 | 263 | "set noparent" option prevents cpplint from traversing directory tree |
261 | 264 | upwards looking for more .cfg files in parent directories. This option |
|
812 | 815 | r")$" |
813 | 816 | ) |
814 | 817 |
|
815 | | - |
816 | | -# These headers are excluded from [build/include] and [build/include_order] |
817 | | -# checks: |
818 | | -# - Anything not following google file name conventions (containing an |
819 | | -# uppercase character, such as Python.h or nsStringAPI.h, for example). |
820 | | -# - Lua headers. |
821 | | -_THIRD_PARTY_HEADERS_PATTERN = re.compile(r"^(?:[^/]*[A-Z][^/]*\.h|lua\.h|lauxlib\.h|lualib\.h)$") |
822 | | - |
823 | 818 | # Pattern for matching FileInfo.BaseName() against test file name |
824 | 819 | _test_suffixes = ["_test", "_regtest", "_unittest"] |
825 | 820 | _TEST_FILE_SUFFIX = "(" + "|".join(_test_suffixes) + r")$" |
|
981 | 976 | # This is set by --headers flag. |
982 | 977 | _hpp_headers: set[str] = set() |
983 | 978 |
|
| 979 | +# These headers are excluded from [build/include_subdir], [build/include_order], and |
| 980 | +# [build/include_alpha] |
| 981 | +# The default checks are following |
| 982 | +# - Anything not following google file name conventions (containing an |
| 983 | +# uppercase character, such as Python.h or nsStringAPI.h, for example). |
| 984 | +# - Lua headers. |
| 985 | +# Default pattern for third-party headers (uppercase .h or Lua headers). |
| 986 | +_THIRD_PARTY_HEADERS_DEFAULT = r"^(?:[^/]*[A-Z][^/]*\.h|lua\.h|lauxlib\.h|lualib\.h)$" |
| 987 | +_third_party_headers_pattern = re.compile(_THIRD_PARTY_HEADERS_DEFAULT) |
| 988 | + |
984 | 989 |
|
985 | 990 | class ErrorSuppressions: |
986 | 991 | """Class to track all error suppressions for cpplint""" |
@@ -1072,6 +1077,15 @@ def ProcessIncludeOrderOption(val): |
1072 | 1077 | PrintUsage("Invalid includeorder value %s. Expected default|standardcfirst") |
1073 | 1078 |
|
1074 | 1079 |
|
| 1080 | +def ProcessThirdPartyHeadersOption(val): |
| 1081 | + """Sets the regex pattern for third-party headers.""" |
| 1082 | + global _third_party_headers_pattern |
| 1083 | + try: |
| 1084 | + _third_party_headers_pattern = re.compile(val) |
| 1085 | + except re.error: |
| 1086 | + PrintUsage(f"Invalid third_party_headers pattern: {val}") |
| 1087 | + |
| 1088 | + |
1075 | 1089 | def IsHeaderExtension(file_extension): |
1076 | 1090 | return file_extension in GetHeaderExtensions() |
1077 | 1091 |
|
@@ -5744,7 +5758,7 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): |
5744 | 5758 | if ( |
5745 | 5759 | match |
5746 | 5760 | and IsHeaderExtension(match.group(2)) |
5747 | | - and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1)) |
| 5761 | + and not _third_party_headers_pattern.match(match.group(1)) |
5748 | 5762 | ): |
5749 | 5763 | error( |
5750 | 5764 | filename, |
@@ -5797,7 +5811,7 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): |
5797 | 5811 | third_src_header = True |
5798 | 5812 | break |
5799 | 5813 |
|
5800 | | - if third_src_header or not _THIRD_PARTY_HEADERS_PATTERN.match(include): |
| 5814 | + if third_src_header or not _third_party_headers_pattern.match(include): |
5801 | 5815 | include_state.include_list[-1].append((include, linenum)) |
5802 | 5816 |
|
5803 | 5817 | # We want to ensure that headers appear in the right order: |
@@ -7527,6 +7541,8 @@ def ProcessConfigOverrides(filename): |
7527 | 7541 | _root = os.path.join(os.path.dirname(cfg_file), val) |
7528 | 7542 | elif name == "headers": |
7529 | 7543 | ProcessHppHeadersOption(val) |
| 7544 | + elif name == "third_party_headers": |
| 7545 | + ProcessThirdPartyHeadersOption(val) |
7530 | 7546 | elif name == "includeorder": |
7531 | 7547 | ProcessIncludeOrderOption(val) |
7532 | 7548 | else: |
@@ -7711,6 +7727,7 @@ def ParseArguments(args): |
7711 | 7727 | "exclude=", |
7712 | 7728 | "recursive", |
7713 | 7729 | "headers=", |
| 7730 | + "third_party_headers=", |
7714 | 7731 | "includeorder=", |
7715 | 7732 | "config=", |
7716 | 7733 | "quiet", |
@@ -7770,6 +7787,8 @@ def ParseArguments(args): |
7770 | 7787 | ProcessExtensionsOption(val) |
7771 | 7788 | elif opt == "--headers": |
7772 | 7789 | ProcessHppHeadersOption(val) |
| 7790 | + elif opt == "--third_party_headers": |
| 7791 | + ProcessThirdPartyHeadersOption(val) |
7773 | 7792 | elif opt == "--recursive": |
7774 | 7793 | recursive = True |
7775 | 7794 | elif opt == "--includeorder": |
|
0 commit comments