MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckEnd

Method CheckEnd

analytical_engine/misc/cpplint.py:2833–2883  ·  view source on GitHub ↗

Check end of namespace comments.

(self, filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

2831 self.check_namespace_indentation = True
2832
2833 def CheckEnd(self, filename, clean_lines, linenum, error):
2834 """Check end of namespace comments."""
2835 line = clean_lines.raw_lines[linenum]
2836
2837 # Check how many lines is enclosed in this namespace. Don't issue
2838 # warning for missing namespace comments if there aren't enough
2839 # lines. However, do apply checks if there is already an end of
2840 # namespace comment and it's incorrect.
2841 #
2842 # TODO(unknown): We always want to check end of namespace comments
2843 # if a namespace is large, but sometimes we also want to apply the
2844 # check if a short namespace contained nontrivial things (something
2845 # other than forward declarations). There is currently no logic on
2846 # deciding what these nontrivial things are, so this check is
2847 # triggered by namespace size only, which works most of the time.
2848 if (linenum - self.starting_linenum < 10
2849 and not Match(r'^\s*};*\s*(//|/\*).*\bnamespace\b', line)):
2850 return
2851
2852 # Look for matching comment at end of namespace.
2853 #
2854 # Note that we accept C style "/* */" comments for terminating
2855 # namespaces, so that code that terminate namespaces inside
2856 # preprocessor macros can be cpplint clean.
2857 #
2858 # We also accept stuff like "// end of namespace <name>." with the
2859 # period at the end.
2860 #
2861 # Besides these, we don't accept anything else, otherwise we might
2862 # get false negatives when existing comment is a substring of the
2863 # expected namespace.
2864 if self.name:
2865 # Named namespace
2866 if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' +
2867 re.escape(self.name) + r'[\*/\.\\\s]*$'),
2868 line):
2869 error(filename, linenum, 'readability/namespace', 5,
2870 'Namespace should be terminated with "// namespace %s"' %
2871 self.name)
2872 else:
2873 # Anonymous namespace
2874 if not Match(r'^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line):
2875 # If "// namespace anonymous" or "// anonymous namespace (more text)",
2876 # mention "// anonymous namespace" as an acceptable form
2877 if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line):
2878 error(filename, linenum, 'readability/namespace', 5,
2879 'Anonymous namespace should be terminated with "// namespace"'
2880 ' or "// anonymous namespace"')
2881 else:
2882 error(filename, linenum, 'readability/namespace', 5,
2883 'Anonymous namespace should be terminated with "// namespace"')
2884
2885
2886class _PreprocessorInfo(object):

Callers

nothing calls this directly

Calls 1

MatchFunction · 0.70

Tested by

no test coverage detected