flake8-eradicate

1.5.0 · active · verified Sun Apr 12

flake8-eradicate is a Flake8 plugin designed to identify and flag commented-out code within your Python projects. It helps enforce code cleanliness by pointing out code that might be dead, unused, or temporarily disabled. The current version is 1.5.0, and it maintains an active release cadence, typically releasing updates every few months to support newer Python and Flake8 versions.

Warnings

Install

Imports

Quickstart

To use flake8-eradicate, simply install it alongside flake8. The plugin automatically registers itself, and subsequent runs of `flake8` will include checks for commented-out code, reporting them as E7901 errors.

# 1. Install flake8 and flake8-eradicate
pip install flake8 flake8-eradicate

# 2. Create a Python file with commented-out code (e.g., example.py)
#    def old_function():
#        print('This is old code')

def new_function():
    print('This is new code')

#    old_function()

# 3. Run flake8 on your project
#    It will automatically detect and use the flake8-eradicate plugin.
#    The default error code is E7901.
#    Expected output: example.py:3:5: E7901 Found commented out code
import os
if os.getenv('RUN_FLAKE8_EXAMPLE', 'false').lower() == 'true':
    # In a real scenario, you'd run this from your terminal
    # For this example, we simulate the effect by creating a dummy file
    # and noting the expected output.
    with open('temp_example.py', 'w') as f:
        f.write("#    def old_function():\n#        print('This is old code')\n\ndef new_function():\n    print('This is new code')\n\n#    old_function()")
    print("To run, save the code to 'example.py' and execute: 'flake8 example.py'")
    print("Expected output (or similar): 'example.py:3:5: E7901 Found commented out code'")
    # You would typically run 'flake8 temp_example.py' in a shell.

view raw JSON →