Checks for common mistakes in TODO comments. Args: comment: The text of the comment from the line in question. filename: The name of the current file. linenum: The number of the line to check. error: The function to call with any errors found.
(comment, filename, linenum, error)
| 2459 | |
| 2460 | |
| 2461 | def CheckComment(comment, filename, linenum, error): |
| 2462 | """Checks for common mistakes in TODO comments. |
| 2463 | |
| 2464 | Args: |
| 2465 | comment: The text of the comment from the line in question. |
| 2466 | filename: The name of the current file. |
| 2467 | linenum: The number of the line to check. |
| 2468 | error: The function to call with any errors found. |
| 2469 | """ |
| 2470 | match = _RE_PATTERN_TODO.match(comment) |
| 2471 | if match: |
| 2472 | # One whitespace is correct; zero whitespace is handled elsewhere. |
| 2473 | leading_whitespace = match.group(1) |
| 2474 | if len(leading_whitespace) > 1: |
| 2475 | error(filename, linenum, 'whitespace/todo', 2, |
| 2476 | 'Too many spaces before TODO') |
| 2477 | |
| 2478 | username = match.group(2) |
| 2479 | if not username: |
| 2480 | error(filename, linenum, 'readability/todo', 2, |
| 2481 | 'Missing username in TODO; it should look like ' |
| 2482 | '"// TODO(my_username): Stuff."') |
| 2483 | |
| 2484 | middle_whitespace = match.group(3) |
| 2485 | # Comparisons made explicit for correctness -- pylint: disable=g-explicit-bool-comparison |
| 2486 | if middle_whitespace != ' ' and middle_whitespace != '': |
| 2487 | error(filename, linenum, 'whitespace/todo', 2, |
| 2488 | 'TODO(my_username) should be followed by a space') |
| 2489 | |
| 2490 | def CheckAccess(filename, clean_lines, linenum, nesting_state, error): |
| 2491 | """Checks for improper use of DISALLOW* macros. |