def ProcessFile()

in cpplint.py [0:0]


def ProcessFile(filename, vlevel, extra_check_functions=[]):
    """Does google-lint on a single file.

  Args:
    filename: The name of the file to parse.

    vlevel: The level of errors to report.  Every error of confidence
    >= verbose_level will be reported.  0 is a good default.

    extra_check_functions: An array of additional check functions that will be
                           run on each source line. Each function takes 4
                           arguments: filename, clean_lines, line, error
  """

    _SetVerboseLevel(vlevel)
    _BackupFilters()
    old_errors = _cpplint_state.error_count

    if not ProcessConfigOverrides(filename):
        _RestoreFilters()
        return

    lf_lines = []
    crlf_lines = []
    try:
        # Support the UNIX convention of using "-" for stdin.  Note that
        # we are not opening the file with universal newline support
        # (which codecs doesn't support anyway), so the resulting lines do
        # contain trailing '\r' characters if we are reading a file that
        # has CRLF endings.
        # If after the split a trailing '\r' is present, it is removed
        # below.
        if filename == '-':
            lines = codecs.StreamReaderWriter(sys.stdin,
                                              codecs.getreader('utf8'),
                                              codecs.getwriter('utf8'),
                                              'replace').read().split('\n')
        else:
            lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n')

        # Remove trailing '\r'.
        # The -1 accounts for the extra trailing blank line we get from split()
        for linenum in range(len(lines) - 1):
            if lines[linenum].endswith('\r'):
                lines[linenum] = lines[linenum].rstrip('\r')
                crlf_lines.append(linenum + 1)
            else:
                lf_lines.append(linenum + 1)

    except IOError:
        sys.stderr.write(
            "Skipping input '%s': Can't open for reading\n" % filename)
        _RestoreFilters()
        return

    # Note, if no dot is found, this will give the entire filename as the ext.
    file_extension = filename[filename.rfind('.') + 1:]

    # When reading from stdin, the extension is unknown, so no cpplint tests
    # should rely on the extension.
    if filename != '-' and file_extension not in _valid_extensions:
        sys.stderr.write('Ignoring %s; not a valid file name '
                         '(%s)\n' % (filename, ', '.join(_valid_extensions)))
    else:
        ProcessFileData(filename, file_extension, lines, Error,
                        extra_check_functions)

        # If end-of-line sequences are a mix of LF and CR-LF, issue
        # warnings on the lines with CR.
        #
        # Don't issue any warnings if all lines are uniformly LF or CR-LF,
        # since critique can handle these just fine, and the style guide
        # doesn't dictate a particular end of line sequence.
        #
        # We can't depend on os.linesep to determine what the desired
        # end-of-line sequence should be, since that will return the
        # server-side end-of-line sequence.
        if lf_lines and crlf_lines:
            # Warn on every line with CR.  An alternative approach might be to
            # check whether the file is mostly CRLF or just LF, and warn on the
            # minority, we bias toward LF here since most tools prefer LF.
            for linenum in crlf_lines:
                Error(filename, linenum, 'whitespace/newline', 1,
                      'Unexpected \\r (^M) found; better to use only \\n')

    # Suppress printing anything if --quiet was passed unless the error
    # count has increased after processing this file.
    if not _cpplint_state.quiet or old_errors != _cpplint_state.error_count:
        sys.stdout.write('Done processing %s\n' % filename)
    _RestoreFilters()