| @@ 2439-2497 (lines=59) @@ | ||
| 2436 | 'Closing brace should be aligned with beginning of %s' % parent) |
|
| 2437 | ||
| 2438 | ||
| 2439 | class _NamespaceInfo(_BlockInfo): |
|
| 2440 | """Stores information about a namespace.""" |
|
| 2441 | ||
| 2442 | def __init__(self, name, linenum): |
|
| 2443 | _BlockInfo.__init__(self, linenum, False) |
|
| 2444 | self.name = name or '' |
|
| 2445 | self.check_namespace_indentation = True |
|
| 2446 | ||
| 2447 | def CheckEnd(self, filename, clean_lines, linenum, error): |
|
| 2448 | """Check end of namespace comments.""" |
|
| 2449 | line = clean_lines.raw_lines[linenum] |
|
| 2450 | ||
| 2451 | # Check how many lines is enclosed in this namespace. Don't issue |
|
| 2452 | # warning for missing namespace comments if there aren't enough |
|
| 2453 | # lines. However, do apply checks if there is already an end of |
|
| 2454 | # namespace comment and it's incorrect. |
|
| 2455 | # |
|
| 2456 | # TODO(unknown): We always want to check end of namespace comments |
|
| 2457 | # if a namespace is large, but sometimes we also want to apply the |
|
| 2458 | # check if a short namespace contained nontrivial things (something |
|
| 2459 | # other than forward declarations). There is currently no logic on |
|
| 2460 | # deciding what these nontrivial things are, so this check is |
|
| 2461 | # triggered by namespace size only, which works most of the time. |
|
| 2462 | if (linenum - self.starting_linenum < 10 |
|
| 2463 | and not Match(r'^\s*};*\s*(//|/\*).*\bnamespace\b', line)): |
|
| 2464 | return |
|
| 2465 | ||
| 2466 | # Look for matching comment at end of namespace. |
|
| 2467 | # |
|
| 2468 | # Note that we accept C style "/* */" comments for terminating |
|
| 2469 | # namespaces, so that code that terminate namespaces inside |
|
| 2470 | # preprocessor macros can be cpplint clean. |
|
| 2471 | # |
|
| 2472 | # We also accept stuff like "// end of namespace <name>." with the |
|
| 2473 | # period at the end. |
|
| 2474 | # |
|
| 2475 | # Besides these, we don't accept anything else, otherwise we might |
|
| 2476 | # get false negatives when existing comment is a substring of the |
|
| 2477 | # expected namespace. |
|
| 2478 | if self.name: |
|
| 2479 | # Named namespace |
|
| 2480 | if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' + |
|
| 2481 | re.escape(self.name) + r'[\*/\.\\\s]*$'), |
|
| 2482 | line): |
|
| 2483 | error(filename, linenum, 'readability/namespace', 5, |
|
| 2484 | 'Namespace should be terminated with "// namespace %s"' % |
|
| 2485 | self.name) |
|
| 2486 | else: |
|
| 2487 | # Anonymous namespace |
|
| 2488 | if not Match(r'^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line): |
|
| 2489 | # If "// namespace anonymous" or "// anonymous namespace (more text)", |
|
| 2490 | # mention "// anonymous namespace" as an acceptable form |
|
| 2491 | if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line): |
|
| 2492 | error(filename, linenum, 'readability/namespace', 5, |
|
| 2493 | 'Anonymous namespace should be terminated with "// namespace"' |
|
| 2494 | ' or "// anonymous namespace"') |
|
| 2495 | else: |
|
| 2496 | error(filename, linenum, 'readability/namespace', 5, |
|
| 2497 | 'Anonymous namespace should be terminated with "// namespace"') |
|
| 2498 | ||
| 2499 | ||
| 2500 | class _PreprocessorInfo(object): |
|
| @@ 2439-2497 (lines=59) @@ | ||
| 2436 | 'Closing brace should be aligned with beginning of %s' % parent) |
|
| 2437 | ||
| 2438 | ||
| 2439 | class _NamespaceInfo(_BlockInfo): |
|
| 2440 | """Stores information about a namespace.""" |
|
| 2441 | ||
| 2442 | def __init__(self, name, linenum): |
|
| 2443 | _BlockInfo.__init__(self, linenum, False) |
|
| 2444 | self.name = name or '' |
|
| 2445 | self.check_namespace_indentation = True |
|
| 2446 | ||
| 2447 | def CheckEnd(self, filename, clean_lines, linenum, error): |
|
| 2448 | """Check end of namespace comments.""" |
|
| 2449 | line = clean_lines.raw_lines[linenum] |
|
| 2450 | ||
| 2451 | # Check how many lines is enclosed in this namespace. Don't issue |
|
| 2452 | # warning for missing namespace comments if there aren't enough |
|
| 2453 | # lines. However, do apply checks if there is already an end of |
|
| 2454 | # namespace comment and it's incorrect. |
|
| 2455 | # |
|
| 2456 | # TODO(unknown): We always want to check end of namespace comments |
|
| 2457 | # if a namespace is large, but sometimes we also want to apply the |
|
| 2458 | # check if a short namespace contained nontrivial things (something |
|
| 2459 | # other than forward declarations). There is currently no logic on |
|
| 2460 | # deciding what these nontrivial things are, so this check is |
|
| 2461 | # triggered by namespace size only, which works most of the time. |
|
| 2462 | if (linenum - self.starting_linenum < 10 |
|
| 2463 | and not Match(r'^\s*};*\s*(//|/\*).*\bnamespace\b', line)): |
|
| 2464 | return |
|
| 2465 | ||
| 2466 | # Look for matching comment at end of namespace. |
|
| 2467 | # |
|
| 2468 | # Note that we accept C style "/* */" comments for terminating |
|
| 2469 | # namespaces, so that code that terminate namespaces inside |
|
| 2470 | # preprocessor macros can be cpplint clean. |
|
| 2471 | # |
|
| 2472 | # We also accept stuff like "// end of namespace <name>." with the |
|
| 2473 | # period at the end. |
|
| 2474 | # |
|
| 2475 | # Besides these, we don't accept anything else, otherwise we might |
|
| 2476 | # get false negatives when existing comment is a substring of the |
|
| 2477 | # expected namespace. |
|
| 2478 | if self.name: |
|
| 2479 | # Named namespace |
|
| 2480 | if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' + |
|
| 2481 | re.escape(self.name) + r'[\*/\.\\\s]*$'), |
|
| 2482 | line): |
|
| 2483 | error(filename, linenum, 'readability/namespace', 5, |
|
| 2484 | 'Namespace should be terminated with "// namespace %s"' % |
|
| 2485 | self.name) |
|
| 2486 | else: |
|
| 2487 | # Anonymous namespace |
|
| 2488 | if not Match(r'^\s*};*\s*(//|/\*).*\bnamespace[\*/\.\\\s]*$', line): |
|
| 2489 | # If "// namespace anonymous" or "// anonymous namespace (more text)", |
|
| 2490 | # mention "// anonymous namespace" as an acceptable form |
|
| 2491 | if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line): |
|
| 2492 | error(filename, linenum, 'readability/namespace', 5, |
|
| 2493 | 'Anonymous namespace should be terminated with "// namespace"' |
|
| 2494 | ' or "// anonymous namespace"') |
|
| 2495 | else: |
|
| 2496 | error(filename, linenum, 'readability/namespace', 5, |
|
| 2497 | 'Anonymous namespace should be terminated with "// namespace"') |
|
| 2498 | ||
| 2499 | ||
| 2500 | class _PreprocessorInfo(object): |
|