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)
| 7704 | |
| 7705 | |
| 7706 | def ProcessFile(filename, vlevel, extra_check_functions=None): |
| 7707 | """Does google-lint on a single file. |
| 7708 | |
| 7709 | Args: |
| 7710 | filename: The name of the file to parse. |
| 7711 | |
| 7712 | vlevel: The level of errors to report. Every error of confidence |
| 7713 | >= verbose_level will be reported. 0 is a good default. |
| 7714 | |
| 7715 | extra_check_functions: An array of additional check functions that will be |
| 7716 | run on each source line. Each function takes 4 |
| 7717 | arguments: filename, clean_lines, line, error |
| 7718 | """ |
| 7719 | |
| 7720 | _SetVerboseLevel(vlevel) |
| 7721 | _BackupFilters() |
| 7722 | old_errors = _cpplint_state.error_count |
| 7723 | |
| 7724 | if not ProcessConfigOverrides(filename): |
| 7725 | _RestoreFilters() |
| 7726 | return |
| 7727 | |
| 7728 | try: |
| 7729 | # Support the UNIX convention of using "-" for stdin. |
| 7730 | if filename == "-": |
| 7731 | lines = sys.stdin.read().split("\n") |
| 7732 | else: |
| 7733 | with open(filename, encoding="utf8", errors="replace", newline=None) as target_file: |
| 7734 | lines = target_file.read().split("\n") |
| 7735 | |
| 7736 | except OSError: |
| 7737 | # TODO(aaronliu0130): Maybe make this have an exit code of 2 after all is done |
| 7738 | _cpplint_state.PrintError(f"Skipping input '{filename}': Can't open for reading\n") |
| 7739 | _RestoreFilters() |
| 7740 | return |
| 7741 | |
| 7742 | # Note, if no dot is found, this will give the entire filename as the ext. |
| 7743 | file_extension = filename[filename.rfind(".") + 1 :] |
| 7744 | |
| 7745 | # When reading from stdin, the extension is unknown, so no cpplint tests |
| 7746 | # should rely on the extension. |
| 7747 | if filename != "-" and file_extension not in GetAllExtensions(): |
| 7748 | _cpplint_state.PrintError( |
| 7749 | f"Ignoring {filename}; not a valid file name ({(', '.join(GetAllExtensions()))})\n" |
| 7750 | ) |
| 7751 | else: |
| 7752 | ProcessFileData(filename, file_extension, lines, Error, extra_check_functions) |
| 7753 | |
| 7754 | # Suppress printing anything if --quiet was passed unless the error |
| 7755 | # count has increased after processing this file. |
| 7756 | if not _cpplint_state.quiet or old_errors != _cpplint_state.error_count: |
| 7757 | _cpplint_state.PrintInfo(f"Done processing {filename}\n") |
| 7758 | _RestoreFilters() |
| 7759 | |
| 7760 | |
| 7761 | def PrintUsage(message): |
no test coverage detected
searching dependent graphs…