MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / CheckComment

Function CheckComment

util/cpplint.py:3021–3069  ·  view source on GitHub ↗

Checks for common mistakes in comments. Args: line: The line in question. filename: The name of the current file. linenum: The number of the line to check. next_line_start: The first non-whitespace column of the next line. error: The function to call with any errors found.

(line, filename, linenum, next_line_start, error)

Source from the content-addressed store, hash-verified

3019
3020
3021def CheckComment(line, filename, linenum, next_line_start, error):
3022 """Checks for common mistakes in comments.
3023
3024 Args:
3025 line: The line in question.
3026 filename: The name of the current file.
3027 linenum: The number of the line to check.
3028 next_line_start: The first non-whitespace column of the next line.
3029 error: The function to call with any errors found.
3030 """
3031 commentpos = line.find('//')
3032 if commentpos != -1:
3033 # Check if the // may be in quotes. If so, ignore it
3034 if re.sub(r'\\.', '', line[0:commentpos]).count('"') % 2 == 0:
3035 # Allow one space for new scopes, two spaces otherwise:
3036 if (commentpos >= 1 and
3037 line[commentpos-1] not in string.whitespace):
3038 error(filename, linenum, 'whitespace/comments', 2,
3039 'At least a single space is required between code and comments')
3040
3041 # Checks for common mistakes in TODO comments.
3042 comment = line[commentpos:]
3043 match = _RE_PATTERN_TODO.match(comment)
3044 if match:
3045 # One whitespace is correct; zero whitespace is handled elsewhere.
3046 leading_whitespace = match.group(1)
3047 if len(leading_whitespace) > 1:
3048 error(filename, linenum, 'whitespace/todo', 2,
3049 'Too many spaces before TODO')
3050
3051 username = match.group(2)
3052 if not username:
3053 error(filename, linenum, 'readability/todo', 2,
3054 'Missing username in TODO; it should look like '
3055 '"// TODO(my_username): Stuff."')
3056
3057 middle_whitespace = match.group(3)
3058 # Comparisons made explicit for correctness -- pylint: disable=g-explicit-bool-comparison
3059 if middle_whitespace != ' ' and middle_whitespace != '':
3060 error(filename, linenum, 'whitespace/todo', 2,
3061 'TODO(my_username) should be followed by a space')
3062
3063 # If the comment contains an alphanumeric character, there
3064 # should be a space somewhere between it and the // unless
3065 # it's a /// or //! Doxygen comment.
3066 if (Match(r'//[^ ]*\w', comment) and
3067 not Match(r'(///|//\!)(\s+|$)', comment)):
3068 error(filename, linenum, 'whitespace/comments', 4,
3069 'Should have a space between // and comment')
3070
3071
3072def CheckAccess(filename, clean_lines, linenum, nesting_state, error):

Callers 1

CheckSpacingFunction · 0.85

Calls 2

errorFunction · 0.85
MatchFunction · 0.85

Tested by

no test coverage detected