MCPcopy Index your code
hub / github.com/cpplint/cpplint / CheckIncludeLine

Function CheckIncludeLine

cpplint.py:5690–5806  ·  view source on GitHub ↗

Check rules that are applicable to #include lines. Strings on #include lines are NOT removed from elided line, to make certain tasks easier. However, to prevent false positives, checks applicable to #include lines in CheckLanguage must be put here. Args: filename: The name of

(filename, clean_lines, linenum, include_state, error)

Source from the content-addressed store, hash-verified

5688
5689
5690def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5691 """Check rules that are applicable to #include lines.
5692
5693 Strings on #include lines are NOT removed from elided line, to make
5694 certain tasks easier. However, to prevent false positives, checks
5695 applicable to #include lines in CheckLanguage must be put here.
5696
5697 Args:
5698 filename: The name of the current file.
5699 clean_lines: A CleansedLines instance containing the file.
5700 linenum: The number of the line to check.
5701 include_state: An _IncludeState instance in which the headers are inserted.
5702 error: The function to call with any errors found.
5703 """
5704 fileinfo = FileInfo(filename)
5705 line = clean_lines.lines[linenum]
5706
5707 # "include" should use the new style "foo/bar.h" instead of just "bar.h"
5708 # Only do this check if the included header follows google naming
5709 # conventions. If not, assume that it's a 3rd party API that
5710 # requires special include conventions.
5711 #
5712 # We also make an exception for Lua headers, which follow google
5713 # naming convention but not the include convention.
5714 match = re.match(r'#include\s*"([^/]+\.(.*))"', line)
5715 if (
5716 match
5717 and IsHeaderExtension(match.group(2))
5718 and not _THIRD_PARTY_HEADERS_PATTERN.match(match.group(1))
5719 ):
5720 error(
5721 filename,
5722 linenum,
5723 "build/include_subdir",
5724 4,
5725 "Include the directory when naming header files",
5726 )
5727
5728 # we shouldn't include a file more than once. actually, there are a
5729 # handful of instances where doing so is okay, but in general it's
5730 # not.
5731 match = _RE_PATTERN_INCLUDE.search(line)
5732 if match:
5733 include = match.group(2)
5734 used_angle_brackets = match.group(1) == "<"
5735 duplicate_line = include_state.FindHeader(include)
5736 if duplicate_line >= 0:
5737 error(
5738 filename,
5739 linenum,
5740 "build/include",
5741 4,
5742 f'"{include}" already included at {filename}:{duplicate_line}',
5743 )
5744 return
5745
5746 for extension in GetNonHeaderExtensions():
5747 if include.endswith("." + extension) and os.path.dirname(

Callers 1

CheckLanguageFunction · 0.85

Calls 13

RepositoryNameMethod · 0.95
ExtensionMethod · 0.95
BaseNameMethod · 0.95
FileInfoClass · 0.85
IsHeaderExtensionFunction · 0.85
GetNonHeaderExtensionsFunction · 0.85
GetHeaderExtensionsFunction · 0.85
_ClassifyIncludeFunction · 0.85
FindHeaderMethod · 0.80
CheckNextIncludeOrderMethod · 0.80
IsInAlphabeticalOrderMethod · 0.80

Tested by

no test coverage detected