def check_and_fix_numbered_list()

in security-policies/dev/common.py [0:0]


def check_and_fix_numbered_list(text):
    # Split the text into lines
    lines = text.split("\n")

    # Find the lines that start with a number and a period, and store their indices
    numbered_lines = [(i, line) for i, line in enumerate(lines) if re.match(r"^\d+\.", line)]

    # Check if the numbered lines are consecutively numbered
    for i, (index, line) in enumerate(numbered_lines):
        # Extract the number from the line
        line_number = int(line.split(".")[0])

        # Check if the line number is correct
        if line_number != i + 1:
            # The line number is not correct, fix it by replacing the line with the correct line number
            corrected_line = f"{i + 1}. {line.removeprefix(str(line_number) + '. ')}"
            lines[index] = corrected_line

    # Join the lines back into a single string and return the result
    return "\n".join(lines)