MCPcopy Create free account
hub / github.com/tensorflow/tfjs / _NamespaceInfo

Class _NamespaceInfo

tfjs-backend-wasm/tools/cpplint.py:2331–2389  ·  view source on GitHub ↗

Stores information about a namespace.

Source from the content-addressed store, hash-verified

2329
2330
2331class _NamespaceInfo(_BlockInfo):
2332 """Stores information about a namespace."""
2333
2334 def __init__(self, name, linenum):
2335 _BlockInfo.__init__(self, linenum, False)
2336 self.name = name or ''
2337 self.check_namespace_indentation = True
2338
2339 def CheckEnd(self, filename, clean_lines, linenum, error):
2340 """Check end of namespace comments."""
2341 line = clean_lines.raw_lines[linenum]
2342
2343 # Check how many lines is enclosed in this namespace. Don't issue
2344 # warning for missing namespace comments if there aren't enough
2345 # lines. However, do apply checks if there is already an end of
2346 # namespace comment and it's incorrect.
2347 #
2348 # TODO(unknown): We always want to check end of namespace comments
2349 # if a namespace is large, but sometimes we also want to apply the
2350 # check if a short namespace contained nontrivial things (something
2351 # other than forward declarations). There is currently no logic on
2352 # deciding what these nontrivial things are, so this check is
2353 # triggered by namespace size only, which works most of the time.
2354 if (linenum - self.starting_linenum < 10
2355 and not Match(r'^\s*};*\s*(//|/\*).*\bnamespace\b', line)):
2356 return
2357
2358 # Look for matching comment at end of namespace.
2359 #
2360 # Note that we accept C style "/* */" comments for terminating
2361 # namespaces, so that code that terminate namespaces inside
2362 # preprocessor macros can be cpplint clean.
2363 #
2364 # We also accept stuff like "// end of namespace <name>." with the
2365 # period at the end.
2366 #
2367 # Besides these, we don't accept anything else, otherwise we might
2368 # get false negatives when existing comment is a substring of the
2369 # expected namespace.
2370 if self.name:
2371 # Named namespace
2372 if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' +
2373 re.escape(self.name) + r'[\*/\.\\\s]*$'),
2374 line):
2375 error(filename, linenum, 'readability/namespace', 5,
2376 'Namespace should be terminated with "// namespace %s"' %
2377 self.name)
2378 else:
2379 # Anonymous namespace
2380 if not Match(r'^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line):
2381 # If "// namespace anonymous" or "// anonymous namespace (more text)",
2382 # mention "// anonymous namespace" as an acceptable form
2383 if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line):
2384 error(filename, linenum, 'readability/namespace', 5,
2385 'Anonymous namespace should be terminated with "// namespace"'
2386 ' or "// anonymous namespace"')
2387 else:
2388 error(filename, linenum, 'readability/namespace', 5,

Callers 1

UpdateMethod · 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…