MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / CheckEnd

Method CheckEnd

src/tests/coding/cpplint.py:2830–2880  ·  view source on GitHub ↗

Check end of namespace comments.

(self, filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

MatchFunction · 0.70

Tested by

no test coverage detected