Removes commented-out code from Python files
Find a file
2024-04-23 00:33:15 +03:00
.github/workflows Add integration tests, using real CLI (#47) 2023-06-08 20:34:34 +03:00
.gitignore Ignore 2013-08-17 08:14:01 -07:00
.pre-commit-hooks.yaml Make eradicate compatible with pre-commit (#14) 2019-08-04 08:08:03 -07:00
eradicate.py Version 2.3.0 release 2023-06-09 09:25:18 +03:00
Makefile Clean up 2018-12-23 10:29:55 -08:00
MANIFEST.in Actually include tests in sdist (#44) 2023-03-02 10:12:43 +03:00
README.rst Added reference for PyLint plugin (#49) 2024-04-23 00:33:15 +03:00
setup.py Check that I can commit to main 2023-06-12 12:19:41 +03:00
test_eradicate.py Add integration tests, using real CLI (#47) 2023-06-08 20:34:34 +03:00

=========
eradicate
=========

.. image:: https://github.com/myint/eradicate/actions/workflows/test.yml/badge.svg
    :target: https://github.com/myint/eradicate/actions/workflows/test.yml
    :alt: Build status

----

``eradicate`` removes commented-out code from Python files.


Introduction
============

With modern revision control available, there is no reason to save
commented-out code to your repository. ``eradicate`` helps cleans up
existing junk comments. It does this by detecting block comments that
contain valid Python syntax that are likely to be commented out code.
(It avoids false positives like the sentence ``this is not good``,
which is valid Python syntax, but is probably not code.)


Example
=======

.. code-block:: bash

    $ eradicate --in-place example.py

Before running ``eradicate``.

.. code-block:: python

    #import os
    # from foo import junk
    #a = 3
    a = 4
    #foo(1, 2, 3)

    def foo(x, y, z):
        # print('hello')
        print(x, y, z)

        # This is a real comment.
        #return True
        return False

After running ``eradicate``.

.. code-block:: python

    a = 4

    def foo(x, y, z):
        print(x, y, z)

        # This is a real comment.
        return False


Whitelisting
============

False positives can happen so there is a whitelist feature to fix them shorthand.
You can either add entries to the default whitelist with ``--whitelist-extend`` or overwrite the default with ``--whitelist``.
Both arguments expect a string of ``#`` separated regex strings (whitespaces are preserved). E.g. ``eradicate --whitelist "foo#b a r" filename``
Those regex strings are matched case insensitive against the start of the comment itself.

For the default whitelist please see ``eradicate.py``.


Related
=======

There are different tools, plugins, and integrations for ``eradicate`` users:

- `flake8-eradicate <https://github.com/sobolevn/flake8-eradicate>`_ - Flake8 plugin to find commented out or dead code.
- `databricks-labs-pylint <https://github.com/databrickslabs/pylint-plugin#eradicate-checker>`_ - Databricks-specific PyLint plugin, that can also find commented out code.