How to use the cpplint.ProcessFile function in cpplint

To help you get started, we’ve selected a few cpplint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hookflash / obsolete.op / hookflash-libs / webRTC / PRESUBMIT.py View on Github external
#                         cpplint.py.
  cpplint._SetFilters('-build/header_guard')

  # Use the strictest verbosity level for cpplint.py (level 1) which is the
  # default when running cpplint.py from command line.
  # To make it possible to work with not-yet-converted code, we're only applying
  # it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
  verbosity_level = 1
  files = []
  for f in input_api.AffectedSourceFiles(source_file_filter):
    # Note that moved/renamed files also count as added for svn.
    if (f.Action() == 'A'):
      files.append(f.AbsoluteLocalPath())

  for file_name in files:
    cpplint.ProcessFile(file_name, verbosity_level)

  if cpplint._cpplint_state.error_count > 0:
    if input_api.is_committing:
      # TODO(kjellander): Change back to PresubmitError below when we're
      # confident with the lint settings.
      res_type = output_api.PresubmitPromptWarning
    else:
      res_type = output_api.PresubmitPromptWarning
    result = [res_type('Changelist failed cpplint.py check.')]

  return result
github crosswalk-project / crosswalk / tools / lint.py View on Github external
if not white_list:
    white_list = gcl.DEFAULT_LINT_REGEX
  white_regex = re.compile(white_list)
  black_list = gcl.GetCodeReviewSetting("LINT_IGNORE_REGEX")
  if not black_list:
    black_list = gcl.DEFAULT_LINT_IGNORE_REGEX
  black_regex = re.compile(black_list)
  extra_check_functions = [cpplint_chromium.CheckPointerDeclarationWhitespace]
  # pylint: disable=W0212
  cpplint_state = cpplint._cpplint_state
  for filename in filenames:
    if white_regex.match(filename):
      if black_regex.match(filename):
        print "Ignoring file %s" % filename
      else:
        cpplint.ProcessFile(filename, cpplint_state.verbose_level,
                            extra_check_functions)
    else:
      print "Skipping file %s" % filename
  print "Total errors found: %d\n" % cpplint_state.error_count
github sdbg / sdbg / dart / runtime / PRESUBMIT.py View on Github external
# Find all .cc and .h files in the change list.
  for svn_file in input_api.AffectedTextFiles():
    filename = svn_file.AbsoluteLocalPath()
    if filename.endswith('.cc') or filename.endswith('.h'):
      cleanup_parent = None
      cleanup_runtime = None
      try:
        runtime_path = input_api.PresubmitLocalPath()
        parent_path = os.path.dirname(runtime_path)
        if filename.endswith('.h'):
          cleanup_runtime = AddSvnPathIfNeeded(runtime_path)
          cleanup_parent = TrySvnPathHack(parent_path)
      except PathHackException, exception:
        return [output_api.PresubmitError(str(exception))]
      # Run cpplint on the file.
      cpplint.ProcessFile(filename, 1)
      if cleanup_parent is not None:
        cleanup_parent()
      if cleanup_runtime is not None:
        cleanup_runtime()
      # memcpy does not handle overlapping memory regions. Even though this
      # is well documented it seems to be used in error quite often. To avoid
      # problems we disallow the direct use of memcpy.  The exceptions are in
      # third-party code and in platform/globals.h which uses it to implement
      # bit_cast and bit_copy.
      if not filename.endswith(os.path.join('platform', 'globals.h')) and \
         filename.find('third_party') == -1:
        fh = open(filename, 'r')
        content = fh.read()
        match = re.search('\\bmemcpy\\b', content)
        if match:
          line_number = content[0:match.start()].count('\n') + 1
github Qihoo360 / mongosync / dep / mongo-cxx-driver / site_scons / buildscripts / lint.py View on Github external
if fn.endswith( "_test.cpp" ):
            return True
        return False
    
    cpplint._IsTestFilename = _ourIsTestFilename

    # Change stderr to write with replacement characters so we don't die
    # if we try to print something containing non-ASCII characters.
    sys.stderr = codecs.StreamReaderWriter(sys.stderr,
                                           codecs.getreader('utf8'),
                                           codecs.getwriter('utf8'),
                                           'replace')
    
    cpplint._cpplint_state.ResetErrorCounts()
    for filename in filenames:
        cpplint.ProcessFile(filename, cpplint._cpplint_state.verbose_level)
    cpplint._cpplint_state.PrintErrorCounts()
    
    return cpplint._cpplint_state.error_count == 0