From 46ce93ef683d4a5fd0fbc2d2f8238951b08c05cb Mon Sep 17 00:00:00 2001 From: pocci Date: Sat, 23 Apr 2016 15:30:51 +0200 Subject: [PATCH] Allow end-of-namespace lines that begin with whitespace. Without this change, indented end-of-namespace lines (mostly due to nested namespaces) would still cause an error even if the appropriate change is made to the line. Example: namespace x { namespace y { // this is a nontrivial namespace according // to cpplint static const int nontrivial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // end of namespace y is indented, so would // still cause an error! } // namespace y } // namespace x Based on https://github.com/google/styleguide/issues/17 by pocci...@gmail.com --- cpplint.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpplint.py b/cpplint.py index 7ccdda0..be43b82 100644 --- a/cpplint.py +++ b/cpplint.py @@ -2170,7 +2170,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error): # deciding what these nontrivial things are, so this check is # triggered by namespace size only, which works most of the time. if (linenum - self.starting_linenum < 10 - and not Match(r'};*\s*(//|/\*).*\bnamespace\b', line)): + and not Match(r'\s*};*\s*(//|/\*).*\bnamespace\b', line)): return # Look for matching comment at end of namespace. @@ -2187,7 +2187,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error): # expected namespace. if self.name: # Named namespace - if not Match((r'};*\s*(//|/\*).*\bnamespace\s+' + re.escape(self.name) + + if not Match((r'\s*};*\s*(//|/\*).*\bnamespace\s+' + re.escape(self.name) + r'[\*/\.\\\s]*$'), line): error(filename, linenum, 'readability/namespace', 5, @@ -2195,7 +2195,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error): self.name) else: # Anonymous namespace - if not Match(r'};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line): + if not Match(r'\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line): # If "// namespace anonymous" or "// anonymous namespace (more text)", # mention "// anonymous namespace" as an acceptable form if Match(r'}.*\b(namespace anonymous|anonymous namespace)\b', line):