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

Function CheckHeaderFileIncluded

cpplint.py:2698–2729  ·  view source on GitHub ↗

Logs an error if a source file does not include its header.

(filename, include_state, error)

Source from the content-addressed store, hash-verified

2696
2697
2698def CheckHeaderFileIncluded(filename, include_state, error):
2699 """Logs an error if a source file does not include its header."""
2700
2701 # Do not check test files
2702 fileinfo = FileInfo(filename)
2703 if re.search(_TEST_FILE_SUFFIX, fileinfo.BaseName()):
2704 return
2705
2706 first_include = message = None
2707 basefilename = filename[0 : len(filename) - len(fileinfo.Extension())]
2708 for ext in GetHeaderExtensions():
2709 headerfile = basefilename + "." + ext
2710 if not os.path.exists(headerfile):
2711 continue
2712 headername = FileInfo(headerfile).RepositoryName()
2713 include_uses_unix_dir_aliases = False
2714 for section_list in include_state.include_list:
2715 for f in section_list:
2716 include_text = f[0]
2717 if "./" in include_text:
2718 include_uses_unix_dir_aliases = True
2719 if headername in include_text or include_text in headername:
2720 return
2721 if not first_include:
2722 first_include = f[1]
2723
2724 message = f"{fileinfo.RepositoryName()} should include its header file {headername}"
2725 if include_uses_unix_dir_aliases:
2726 message += ". Relative paths like . and .. are not allowed."
2727
2728 if message:
2729 error(filename, first_include, "build/include", 5, message)
2730
2731
2732def CheckForBadCharacters(filename, lines, error):

Callers 1

ProcessFileDataFunction · 0.85

Calls 5

BaseNameMethod · 0.95
ExtensionMethod · 0.95
RepositoryNameMethod · 0.95
FileInfoClass · 0.85
GetHeaderExtensionsFunction · 0.85

Tested by

no test coverage detected