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

Class _NamespaceInfo

tools/cpplint.py:3168–3242  ·  view source on GitHub ↗

Stores information about a namespace.

Source from the content-addressed store, hash-verified

3166
3167
3168class _NamespaceInfo(_BlockInfo):
3169 """Stores information about a namespace."""
3170
3171 def __init__(self, name, linenum):
3172 _BlockInfo.__init__(self, linenum, False)
3173 self.name = name or ""
3174 self.check_namespace_indentation = True
3175
3176 def CheckEnd(self, filename, clean_lines, linenum, error):
3177 """Check end of namespace comments."""
3178 line = clean_lines.raw_lines[linenum]
3179
3180 # Check how many lines is enclosed in this namespace. Don't issue
3181 # warning for missing namespace comments if there aren't enough
3182 # lines. However, do apply checks if there is already an end of
3183 # namespace comment and it's incorrect.
3184 #
3185 # TODO(google): We always want to check end of namespace comments
3186 # if a namespace is large, but sometimes we also want to apply the
3187 # check if a short namespace contained nontrivial things (something
3188 # other than forward declarations). There is currently no logic on
3189 # deciding what these nontrivial things are, so this check is
3190 # triggered by namespace size only, which works most of the time.
3191 if linenum - self.starting_linenum < 10 and not re.match(
3192 r"^\s*};*\s*(//|/\*).*\bnamespace\b", line
3193 ):
3194 return
3195
3196 # Look for matching comment at end of namespace.
3197 #
3198 # Note that we accept C style "/* */" comments for terminating
3199 # namespaces, so that code that terminate namespaces inside
3200 # preprocessor macros can be cpplint clean.
3201 #
3202 # We also accept stuff like "// end of namespace <name>." with the
3203 # period at the end.
3204 #
3205 # Besides these, we don't accept anything else, otherwise we might
3206 # get false negatives when existing comment is a substring of the
3207 # expected namespace.
3208 if self.name:
3209 # Named namespace
3210 if not re.match(
3211 (r"^\s*};*\s*(//|/\*).*\bnamespace\s+" + re.escape(self.name) + r"[\*/\.\\\s]*$"),
3212 line,
3213 ):
3214 error(
3215 filename,
3216 linenum,
3217 "readability/namespace",
3218 5,
3219 f'Namespace should be terminated with "// namespace {self.name}"',
3220 )
3221 else:
3222 # Anonymous namespace
3223 if not re.match(r"^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$", line):
3224 # If "// namespace anonymous" or "// anonymous namespace (more text)",
3225 # mention "// anonymous namespace" as an acceptable form

Callers 1

_UpdateNamesapceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…