Code Duplication    Length = 57-57 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 1186-1242 (lines=57) @@
1183
  """ Restores filters previously backed up."""
1184
  _cpplint_state.RestoreFilters()
1185
1186
class _FunctionState(object):
1187
  """Tracks current function name and the number of lines in its body."""
1188
1189
  _NORMAL_TRIGGER = 250  # for --v=0, 500 for --v=1, etc.
1190
  _TEST_TRIGGER = 400    # about 50% more than _NORMAL_TRIGGER.
1191
1192
  def __init__(self):
1193
    self.in_a_function = False
1194
    self.lines_in_function = 0
1195
    self.current_function = ''
1196
1197
  def Begin(self, function_name):
1198
    """Start analyzing function body.
1199
1200
    Args:
1201
      function_name: The name of the function being tracked.
1202
    """
1203
    self.in_a_function = True
1204
    self.lines_in_function = 0
1205
    self.current_function = function_name
1206
1207
  def Count(self):
1208
    """Count line in current function body."""
1209
    if self.in_a_function:
1210
      self.lines_in_function += 1
1211
1212
  def Check(self, error, filename, linenum):
1213
    """Report if too many lines in function body.
1214
1215
    Args:
1216
      error: The function to call with any errors found.
1217
      filename: The name of the current file.
1218
      linenum: The number of the line to check.
1219
    """
1220
    if not self.in_a_function:
1221
      return
1222
1223
    if Match(r'T(EST|est)', self.current_function):
1224
      base_trigger = self._TEST_TRIGGER
1225
    else:
1226
      base_trigger = self._NORMAL_TRIGGER
1227
    trigger = base_trigger * 2**_VerboseLevel()
1228
1229
    if self.lines_in_function > trigger:
1230
      error_level = int(math.log(self.lines_in_function / base_trigger, 2))
1231
      # 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1232
      if error_level > 5:
1233
        error_level = 5
1234
      error(filename, linenum, 'readability/fn_size', error_level,
1235
            'Small and focused functions are preferred:'
1236
            ' %s has %d non-comment lines'
1237
            ' (error triggered by exceeding %d lines).'  % (
1238
                self.current_function, self.lines_in_function, trigger))
1239
1240
  def End(self):
1241
    """Stop analyzing function body."""
1242
    self.in_a_function = False
1243
1244
1245
class _IncludeError(Exception):

core/build-support/cpplint.py 1 location

@@ 1186-1242 (lines=57) @@
1183
  """ Restores filters previously backed up."""
1184
  _cpplint_state.RestoreFilters()
1185
1186
class _FunctionState(object):
1187
  """Tracks current function name and the number of lines in its body."""
1188
1189
  _NORMAL_TRIGGER = 250  # for --v=0, 500 for --v=1, etc.
1190
  _TEST_TRIGGER = 400    # about 50% more than _NORMAL_TRIGGER.
1191
1192
  def __init__(self):
1193
    self.in_a_function = False
1194
    self.lines_in_function = 0
1195
    self.current_function = ''
1196
1197
  def Begin(self, function_name):
1198
    """Start analyzing function body.
1199
1200
    Args:
1201
      function_name: The name of the function being tracked.
1202
    """
1203
    self.in_a_function = True
1204
    self.lines_in_function = 0
1205
    self.current_function = function_name
1206
1207
  def Count(self):
1208
    """Count line in current function body."""
1209
    if self.in_a_function:
1210
      self.lines_in_function += 1
1211
1212
  def Check(self, error, filename, linenum):
1213
    """Report if too many lines in function body.
1214
1215
    Args:
1216
      error: The function to call with any errors found.
1217
      filename: The name of the current file.
1218
      linenum: The number of the line to check.
1219
    """
1220
    if not self.in_a_function:
1221
      return
1222
1223
    if Match(r'T(EST|est)', self.current_function):
1224
      base_trigger = self._TEST_TRIGGER
1225
    else:
1226
      base_trigger = self._NORMAL_TRIGGER
1227
    trigger = base_trigger * 2**_VerboseLevel()
1228
1229
    if self.lines_in_function > trigger:
1230
      error_level = int(math.log(self.lines_in_function / base_trigger, 2))
1231
      # 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1232
      if error_level > 5:
1233
        error_level = 5
1234
      error(filename, linenum, 'readability/fn_size', error_level,
1235
            'Small and focused functions are preferred:'
1236
            ' %s has %d non-comment lines'
1237
            ' (error triggered by exceeding %d lines).'  % (
1238
                self.current_function, self.lines_in_function, trigger))
1239
1240
  def End(self):
1241
    """Stop analyzing function body."""
1242
    self.in_a_function = False
1243
1244
1245
class _IncludeError(Exception):