Code Duplication    Length = 52-52 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 3228-3279 (lines=52) @@
3225
_RE_PATTERN_TODO = re.compile(r'^//(\s*)TODO(\(.+?\))?:?(\s|$)?')
3226
3227
3228
def CheckComment(line, filename, linenum, next_line_start, error):
3229
  """Checks for common mistakes in comments.
3230
3231
  Args:
3232
    line: The line in question.
3233
    filename: The name of the current file.
3234
    linenum: The number of the line to check.
3235
    next_line_start: The first non-whitespace column of the next line.
3236
    error: The function to call with any errors found.
3237
  """
3238
  commentpos = line.find('//')
3239
  if commentpos != -1:
3240
    # Check if the // may be in quotes.  If so, ignore it
3241
    if re.sub(r'\\.', '', line[0:commentpos]).count('"') % 2 == 0:
3242
      # Allow one space for new scopes, two spaces otherwise:
3243
      if (not (Match(r'^.*{ *//', line) and next_line_start == commentpos) and
3244
          ((commentpos >= 1 and
3245
            line[commentpos-1] not in string.whitespace) or
3246
           (commentpos >= 2 and
3247
            line[commentpos-2] not in string.whitespace))):
3248
        error(filename, linenum, 'whitespace/comments', 2,
3249
              'At least two spaces is best between code and comments')
3250
3251
      # Checks for common mistakes in TODO comments.
3252
      comment = line[commentpos:]
3253
      match = _RE_PATTERN_TODO.match(comment)
3254
      if match:
3255
        # One whitespace is correct; zero whitespace is handled elsewhere.
3256
        leading_whitespace = match.group(1)
3257
        if len(leading_whitespace) > 1:
3258
          error(filename, linenum, 'whitespace/todo', 2,
3259
                'Too many spaces before TODO')
3260
3261
        username = match.group(2)
3262
        if not username:
3263
          error(filename, linenum, 'readability/todo', 2,
3264
                'Missing username in TODO; it should look like '
3265
                '"// TODO(my_username): Stuff."')
3266
3267
        middle_whitespace = match.group(3)
3268
        # Comparisons made explicit for correctness -- pylint: disable=g-explicit-bool-comparison
3269
        if middle_whitespace != ' ' and middle_whitespace != '':
3270
          error(filename, linenum, 'whitespace/todo', 2,
3271
                'TODO(my_username) should be followed by a space')
3272
3273
      # If the comment contains an alphanumeric character, there
3274
      # should be a space somewhere between it and the // unless
3275
      # it's a /// or //! Doxygen comment.
3276
      if (Match(r'//[^ ]*\w', comment) and
3277
          not Match(r'(///|//\!)(\s+|$)', comment)):
3278
        error(filename, linenum, 'whitespace/comments', 4,
3279
              'Should have a space between // and comment')
3280
3281
3282
def CheckAccess(filename, clean_lines, linenum, nesting_state, error):

core/build-support/cpplint.py 1 location

@@ 3228-3279 (lines=52) @@
3225
_RE_PATTERN_TODO = re.compile(r'^//(\s*)TODO(\(.+?\))?:?(\s|$)?')
3226
3227
3228
def CheckComment(line, filename, linenum, next_line_start, error):
3229
  """Checks for common mistakes in comments.
3230
3231
  Args:
3232
    line: The line in question.
3233
    filename: The name of the current file.
3234
    linenum: The number of the line to check.
3235
    next_line_start: The first non-whitespace column of the next line.
3236
    error: The function to call with any errors found.
3237
  """
3238
  commentpos = line.find('//')
3239
  if commentpos != -1:
3240
    # Check if the // may be in quotes.  If so, ignore it
3241
    if re.sub(r'\\.', '', line[0:commentpos]).count('"') % 2 == 0:
3242
      # Allow one space for new scopes, two spaces otherwise:
3243
      if (not (Match(r'^.*{ *//', line) and next_line_start == commentpos) and
3244
          ((commentpos >= 1 and
3245
            line[commentpos-1] not in string.whitespace) or
3246
           (commentpos >= 2 and
3247
            line[commentpos-2] not in string.whitespace))):
3248
        error(filename, linenum, 'whitespace/comments', 2,
3249
              'At least two spaces is best between code and comments')
3250
3251
      # Checks for common mistakes in TODO comments.
3252
      comment = line[commentpos:]
3253
      match = _RE_PATTERN_TODO.match(comment)
3254
      if match:
3255
        # One whitespace is correct; zero whitespace is handled elsewhere.
3256
        leading_whitespace = match.group(1)
3257
        if len(leading_whitespace) > 1:
3258
          error(filename, linenum, 'whitespace/todo', 2,
3259
                'Too many spaces before TODO')
3260
3261
        username = match.group(2)
3262
        if not username:
3263
          error(filename, linenum, 'readability/todo', 2,
3264
                'Missing username in TODO; it should look like '
3265
                '"// TODO(my_username): Stuff."')
3266
3267
        middle_whitespace = match.group(3)
3268
        # Comparisons made explicit for correctness -- pylint: disable=g-explicit-bool-comparison
3269
        if middle_whitespace != ' ' and middle_whitespace != '':
3270
          error(filename, linenum, 'whitespace/todo', 2,
3271
                'TODO(my_username) should be followed by a space')
3272
3273
      # If the comment contains an alphanumeric character, there
3274
      # should be a space somewhere between it and the // unless
3275
      # it's a /// or //! Doxygen comment.
3276
      if (Match(r'//[^ ]*\w', comment) and
3277
          not Match(r'(///|//\!)(\s+|$)', comment)):
3278
        error(filename, linenum, 'whitespace/comments', 4,
3279
              'Should have a space between // and comment')
3280
3281
3282
def CheckAccess(filename, clean_lines, linenum, nesting_state, error):