How to use the cpplint.ProcessConfigOverrides 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 TheOstrichIO / cpplint / nitpick.py View on Github external
def stylify_file(args, filepath):
  """Stylify `filepath`."""
  if '-' == filepath:
    # Reading from STDIN
    old_content = sys.stdin.read()
    filename = args.filename or '-'
  else:
    # Reading from filepath
    filename = filepath
    with codecs.open(filepath, 'r', 'utf8', 'replace') as src_f:
      old_content = src_f.read()
  if _ROOT:
    cpplint._root = _ROOT
  cpplint.ProcessConfigOverrides(filename)
  lines = old_content.split(u'\n')
  new_lines = stylify_lines(args, filename, lines)
  new_content = u'\n'.join(new_lines)
  if new_content != old_content:
    if args.show_diff:
      info(u'Modified content of %s. Diff:', filename)
      for diffline in difflib.unified_diff(lines, new_lines,
                                           fromfile='%s (before)' % (filename),
                                           tofile='%s (after)' % (filename)):
        differ(diffline)
    if '-' == filepath:
      sys.stdout.write(new_content)
    elif not args.no_edit:
      info(u'Writing changes back to filepath %s ...', filepath)
      with codecs.open(filepath, 'w', 'utf8', 'replace') as f_out:
        f_out.write(new_content)