MCPcopy Create free account
hub / github.com/SIPp/sipp / ProcessFile

Function ProcessFile

cpplint.py:3859–3923  ·  view source on GitHub ↗

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

(filename, vlevel, extra_check_functions=[])

Source from the content-addressed store, hash-verified

3857 CheckForNewlineAtEOF(filename, lines, error)
3858
3859def ProcessFile(filename, vlevel, extra_check_functions=[]):
3860 """Does google-lint on a single file.
3861
3862 Args:
3863 filename: The name of the file to parse.
3864
3865 vlevel: The level of errors to report. Every error of confidence
3866 >= verbose_level will be reported. 0 is a good default.
3867
3868 extra_check_functions: An array of additional check functions that will be
3869 run on each source line. Each function takes 4
3870 arguments: filename, clean_lines, line, error
3871 """
3872
3873 _SetVerboseLevel(vlevel)
3874
3875 try:
3876 # Support the UNIX convention of using "-" for stdin. Note that
3877 # we are not opening the file with universal newline support
3878 # (which codecs doesn't support anyway), so the resulting lines do
3879 # contain trailing '\r' characters if we are reading a file that
3880 # has CRLF endings.
3881 # If after the split a trailing '\r' is present, it is removed
3882 # below. If it is not expected to be present (i.e. os.linesep !=
3883 # '\r\n' as in Windows), a warning is issued below if this file
3884 # is processed.
3885
3886 if filename == '-':
3887 lines = codecs.StreamReaderWriter(sys.stdin,
3888 codecs.getreader('utf8'),
3889 codecs.getwriter('utf8'),
3890 'replace').read().split('\n')
3891 else:
3892 lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n')
3893
3894 carriage_return_found = False
3895 # Remove trailing '\r'.
3896 for linenum in range(len(lines)):
3897 if lines[linenum].endswith('\r'):
3898 lines[linenum] = lines[linenum].rstrip('\r')
3899 carriage_return_found = True
3900
3901 except IOError:
3902 sys.stderr.write(
3903 "Skipping input '%s': Can't open for reading\n" % filename)
3904 return
3905
3906 # Note, if no dot is found, this will give the entire filename as the ext.
3907 file_extension = filename[filename.rfind('.') + 1:]
3908
3909 # When reading from stdin, the extension is unknown, so no cpplint tests
3910 # should rely on the extension.
3911 if filename != '-' and file_extension not in ('cc', 'h', 'cpp', 'hpp'):
3912 sys.stderr.write('Ignoring %s; not a .cc or .h file\n' % filename)
3913 else:
3914 ProcessFileData(filename, file_extension, lines, Error,
3915 extra_check_functions)
3916 if carriage_return_found and os.linesep != '\r\n':

Callers 1

mainFunction · 0.85

Calls 4

_SetVerboseLevelFunction · 0.85
ProcessFileDataFunction · 0.85
ErrorFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected