def process_patch(patch_string): """Does lint on a single patch. Args: patch_string: A string of a patch. """ patch = DiffParser(patch_string.splitlines()) for filename, diff in patch.files.iteritems(): file_extension = os.path.splitext(filename)[1] line_numbers = set() def error_for_patch(filename, line_number, category, confidence, message): """Wrapper function of cpp_style.error for patches. This function outputs errors only if the line number corresponds to lines which are modified or added. """ if not line_numbers: for line in diff.lines: # When deleted line is not set, it means that # the line is newly added. if not line[0]: line_numbers.add(line[1]) if line_number in line_numbers: cpp_style.error(filename, line_number, category, confidence, message) if cpp_style.can_handle(filename): cpp_style.process_file(filename, error=error_for_patch) elif text_style.can_handle(filename): text_style.process_file(filename, error=error_for_patch)
def process_file(filename): """Checks style for the specified file. If the specified filename is '-', applies cpp_style to the standard input. """ if cpp_style.can_handle(filename) or filename == '-': cpp_style.process_file(filename) elif text_style.can_handle(filename): text_style.process_file(filename)