def process_patch(patch_string, root, cwd, scm): """Does lint on a single patch. Args: patch_string: A string of a patch. """ patch = DiffParser(patch_string.splitlines()) if not len(patch.files): cpplint.error("patch", 0, "patch/notempty", 3, "Patch does not appear to diff against any file.") return if not patch.status_line: cpplint.error("patch", 0, "patch/nosummary", 3, "Patch does not have a summary.") else: proper_format = re.match(r"^Bug [0-9]+ - ", patch.status_line) if not proper_format: proper_format = re.match(r"^No bug - ", patch.status_line) cpplint.error( "patch", 0, "patch/bugnumber", 3, "Patch summary should begin with 'Bug XXXXX - ' " + "or 'No bug -'.") if not patch.patch_description: cpplint.error("patch", 0, "patch/nodescription", 3, "Patch does not have a description.") for filename, diff in patch.files.iteritems(): file_extension = os.path.splitext(filename)[1] if file_extension in ['.cpp', '.c', '.h']: line_numbers = set() orig_filename = filename def error_for_patch(filename, line_number, category, confidence, message): """Wrapper function of cpplint.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: cpplint.error(orig_filename, line_number, category, confidence, message) cpplint.process_file(os.path.join(root, filename), relative_name=orig_filename, error=error_for_patch)
def process_patch(patch_string, root, cwd, scm): """Does lint on a single patch. Args: patch_string: A string of a patch. """ patch = DiffParser(patch_string.splitlines()) if not len(patch.files): cpplint.error("patch", 0, "patch/notempty", 3, "Patch does not appear to diff against any file.") return if not patch.status_line: cpplint.error("patch", 0, "patch/nosummary", 3, "Patch does not have a summary.") else: proper_format = re.match(r"^Bug [0-9]+ - ", patch.status_line) if not proper_format: proper_format = re.match(r"^No bug - ", patch.status_line) cpplint.error("patch", 0, "patch/bugnumber", 3, "Patch summary should begin with 'Bug XXXXX - ' " + "or 'No bug -'.") if not patch.patch_description: cpplint.error("patch", 0, "patch/nodescription", 3, "Patch does not have a description.") for filename, diff in patch.files.iteritems(): file_extension = os.path.splitext(filename)[1] if file_extension in ['.cpp', '.c', '.h']: line_numbers = set() orig_filename = filename def error_for_patch(filename, line_number, category, confidence, message): """Wrapper function of cpplint.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: cpplint.error(orig_filename, line_number, category, confidence, message) cpplint.process_file(os.path.join(root, filename), relative_name=orig_filename, error=error_for_patch)
def error_for_patch(filename, line_number, category, confidence, message): """Wrapper function of cpplint.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: cpplint.error(orig_filename, line_number, category, confidence, message)