flake8-html

0.4.3 · active · verified Fri Apr 17

flake8-html is a plugin for the flake8 linter that generates an HTML report of code violations, providing a visual and navigable overview of issues. The current version is 0.4.3. It has an infrequent release cadence, primarily updating to maintain compatibility with new versions of flake8.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to use `flake8-html` via the `flake8` command-line interface. It creates a temporary Python file with a linter violation, runs `flake8` to generate an HTML report, and then cleans up. The `--format=html` and `--htmldir` arguments are essential for generating the report.

import subprocess
import os

# Create a dummy Python file with a flake8 violation
code_to_lint = """
import os

def my_func( arg1, arg2 ):
    print( os.path.join(arg1, arg2) )
"""

with open("test_code.py", "w") as f:
    f.write(code_to_lint)

# Ensure the report directory exists
report_dir = "./flake8_html_report"
os.makedirs(report_dir, exist_ok=True)

# Run flake8 with the html format
print(f"Running: flake8 --format=html --htmldir={report_dir} .")
try:
    result = subprocess.run(
        ["flake8", "--format=html", f"--htmldir={report_dir}", "."],
        capture_output=True,
        text=True,
        check=True
    )
    print("Flake8 HTML report generated successfully.")
    print(f"Report saved to: {os.path.abspath(report_dir)}/report.html")
except subprocess.CalledProcessError as e:
    print(f"Error running flake8: {e}\n{e.stderr}")
except FileNotFoundError:
    print("Error: 'flake8' command not found. Please ensure flake8 is installed.")
finally:
    # Clean up dummy file
    if os.path.exists("test_code.py"):
        os.remove("test_code.py")
    # Optionally, remove the report directory for a clean run next time
    # import shutil
    # if os.path.exists(report_dir):
    #     shutil.rmtree(report_dir)

view raw JSON →