def _filter_docstyle_output()

in scripts/validation/doc_style.py [0:0]


def _filter_docstyle_output(output: str, rules: _Rules, changed_files: List[Path]) -> List[str]:
    lines = [line for line in output.splitlines() if len(line) > 0]
    if lines:
        # Iterate over every other line, since pydocstyle splits output across two lines
        filtered_lines = []
        for i in range(0, len(lines) - 1, 2):
            # Parse filename
            line = lines[i]
            match = FILE_NAME_PATTERN.match(line)
            if not match:
                raise Exception(f"Unable to extract filename from {line}")
            file = Path(match.group(1))

            # Determine whether file should be included in output
            include_file = True
            for exclude in rules.exclude:
                # Check if file is explicitly excluded or in an excluded dir
                if file == exclude or (exclude.is_dir() and file.is_relative_to(exclude)):
                    include_file = False
                    break

            # Include only changed files, if specified
            if include_file and changed_files is not None and file not in changed_files:
                include_file = False

            # Store lines if file is included
            if include_file:
                filtered_lines.append(line)
                filtered_lines.append(lines[i + 1])
        lines = filtered_lines

    return lines