MCPcopy Index your code
hub / github.com/nodejs/node / CheckLanguage

Function CheckLanguage

tools/cpplint.py:6041–6257  ·  view source on GitHub ↗

Checks rules from the 'C++ language rules' section of cppguide.html. Some of these rules are hard to test (function overloading, using uint32_t inappropriately), but we do the best we can. Args: filename: The name of the current file. clean_lines: A CleansedLines instance c

(
    filename, clean_lines, linenum, file_extension, include_state, nesting_state, error
)

Source from the content-addressed store, hash-verified

6039
6040
6041def CheckLanguage(
6042 filename, clean_lines, linenum, file_extension, include_state, nesting_state, error
6043):
6044 """Checks rules from the 'C++ language rules' section of cppguide.html.
6045
6046 Some of these rules are hard to test (function overloading, using
6047 uint32_t inappropriately), but we do the best we can.
6048
6049 Args:
6050 filename: The name of the current file.
6051 clean_lines: A CleansedLines instance containing the file.
6052 linenum: The number of the line to check.
6053 file_extension: The extension (without the dot) of the filename.
6054 include_state: An _IncludeState instance in which the headers are inserted.
6055 nesting_state: A NestingState instance which maintains information about
6056 the current stack of nested blocks being parsed.
6057 error: The function to call with any errors found.
6058 """
6059 # If the line is empty or consists of entirely a comment, no need to
6060 # check it.
6061 line = clean_lines.elided[linenum]
6062 if not line:
6063 return
6064
6065 match = _RE_PATTERN_INCLUDE.search(line)
6066 if match:
6067 CheckIncludeLine(filename, clean_lines, linenum, include_state, error)
6068 return
6069
6070 # Reset include state across preprocessor directives. This is meant
6071 # to silence warnings for conditional includes.
6072 match = re.match(r"^\s*#\s*(if|ifdef|ifndef|elif|else|endif)\b", line)
6073 if match:
6074 include_state.ResetSection(match.group(1))
6075
6076 # Perform other checks now that we are sure that this is not an include line
6077 CheckCasts(filename, clean_lines, linenum, error)
6078 CheckGlobalStatic(filename, clean_lines, linenum, error)
6079 CheckPrintf(filename, clean_lines, linenum, error)
6080
6081 if IsHeaderExtension(file_extension):
6082 # TODO(google): check that 1-arg constructors are explicit.
6083 # How to tell it's a constructor?
6084 # (handled in CheckForNonStandardConstructs for now)
6085 # TODO(google): check that classes declare or disable copy/assign
6086 # (level 1 error)
6087 pass
6088
6089 # Check if people are using the verboten C basic types. The only exception
6090 # we regularly allow is "unsigned short port" for port.
6091 if re.search(r"\bshort port\b", line):
6092 if not re.search(r"\bunsigned short port\b", line):
6093 error(
6094 filename, linenum, "runtime/int", 4, 'Use "unsigned short" for ports, not "short"'
6095 )
6096 else:
6097 match = re.search(r"\b(short|long(?! +double)|long long)\b", line)
6098 if match:

Callers 1

ProcessLineFunction · 0.85

Calls 14

CheckIncludeLineFunction · 0.85
CheckCastsFunction · 0.85
CheckGlobalStaticFunction · 0.85
CheckPrintfFunction · 0.85
IsHeaderExtensionFunction · 0.85
_GetTextInsideFunction · 0.85
_IsSourceExtensionFunction · 0.85
ResetSectionMethod · 0.80
InBlockScopeMethod · 0.80
matchMethod · 0.65
findMethod · 0.65
errorFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…