MCPcopy Index your code
hub / github.com/cpplint/cpplint / ProcessFile

Function ProcessFile

cpplint.py:7518–7610  ·  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 th

(filename, vlevel, extra_check_functions=None)

Source from the content-addressed store, hash-verified

7516
7517
7518def ProcessFile(filename, vlevel, extra_check_functions=None):
7519 """Does google-lint on a single file.
7520
7521 Args:
7522 filename: The name of the file to parse.
7523
7524 vlevel: The level of errors to report. Every error of confidence
7525 >= verbose_level will be reported. 0 is a good default.
7526
7527 extra_check_functions: An array of additional check functions that will be
7528 run on each source line. Each function takes 4
7529 arguments: filename, clean_lines, line, error
7530 """
7531
7532 _SetVerboseLevel(vlevel)
7533 _BackupFilters()
7534 old_errors = _cpplint_state.error_count
7535
7536 if not ProcessConfigOverrides(filename):
7537 _RestoreFilters()
7538 return
7539
7540 lf_lines = []
7541 crlf_lines = []
7542 try:
7543 # Support the UNIX convention of using "-" for stdin. Note that
7544 # we are not opening the file with universal newline support
7545 # (which codecs doesn't support anyway), so the resulting lines do
7546 # contain trailing '\r' characters if we are reading a file that
7547 # has CRLF endings.
7548 # If after the split a trailing '\r' is present, it is removed
7549 # below.
7550 if filename == "-":
7551 lines = sys.stdin.read().split("\n")
7552 else:
7553 with codecs.open(filename, "r", "utf8", "replace") as target_file:
7554 lines = target_file.read().split("\n")
7555
7556 # Remove trailing '\r'.
7557 # The -1 accounts for the extra trailing blank line we get from split()
7558 for linenum in range(len(lines) - 1):
7559 if lines[linenum].endswith("\r"):
7560 lines[linenum] = lines[linenum].rstrip("\r")
7561 crlf_lines.append(linenum + 1)
7562 else:
7563 lf_lines.append(linenum + 1)
7564
7565 except OSError:
7566 # TODO(aaronliu0130): Maybe make this have an exit code of 2 after all is done
7567 _cpplint_state.PrintError(f"Skipping input '{filename}': Can't open for reading\n")
7568 _RestoreFilters()
7569 return
7570
7571 # Note, if no dot is found, this will give the entire filename as the ext.
7572 file_extension = filename[filename.rfind(".") + 1 :]
7573
7574 # When reading from stdin, the extension is unknown, so no cpplint tests
7575 # should rely on the extension.

Callers 1

mainFunction · 0.85

Calls 10

_SetVerboseLevelFunction · 0.85
_BackupFiltersFunction · 0.85
ProcessConfigOverridesFunction · 0.85
_RestoreFiltersFunction · 0.85
GetAllExtensionsFunction · 0.85
ProcessFileDataFunction · 0.85
ErrorFunction · 0.85
openMethod · 0.80
PrintErrorMethod · 0.80
PrintInfoMethod · 0.80

Tested by

no test coverage detected