Coding

eradicate – remove commented-out code from Python files

eradicate is a command-line utility that identifies and removes code left in source files as comments. Such fragments often remain after testing alternative implementations or temporarily disabling statements. Although they do not execute, they can obscure the current logic and make source files harder to maintain.

Rather than deleting every comment, eradicate looks for text resembling executable statements and applies checks intended to distinguish redundant code from genuine explanations. This makes it useful when cleaning an established codebase whose version control history already preserves earlier implementations. Since legitimate comments can sometimes resemble code, proposed removals should be reviewed before files are rewritten.

This is free and open source software.

Key Features

  • Uses tokenization to locate comments without confusing them with hash characters inside strings.
  • Checks suspected commented-out code for syntax and indicators of executable statements.
  • Recognizes commented assignments, imports, function calls, and control-flow statements.
  • Detects some multiline code fragments, including continued statements and bracketed expressions.
  • Displays a unified diff of proposed changes without modifying the original files.
  • Supports in-place editing to remove detected code directly from source files.
  • Recursively scans directories for Python files, excluding hidden directories and files.
  • Offers an aggressive detection mode, which may identify additional code at the risk of false positives.
  • Preserves common development directives, including noqa, pylint, mypy, isort, and formatting annotations.
  • Allows custom regular expression whitelists to replace or extend the default exclusions.
  • Protects inline script metadata blocks and source encoding declarations.
  • Preserves detected file encodings and existing line endings.
  • Provides an optional nonzero exit status when changes are detected, useful for automated checks.
  • Cross-platform support – runs on Linux and Windows.

Website: github.com/PyCQA/eradicate
Support:
Developer: Steven Myint
License: MIT License

eradicate in action

eradicate is written in Python. Learn Python with our recommended free books and free tutorials.


Related Software

Python Code Formatters
RuffExtremely fast Python linter and code formatter
YAPFPython formatter based on clang-format
BlackUncompromising Python code formatter
isortPython utility and library to sort imports
autopep8Formats Python code to conform to the PEP 8 style guide
DarkerApply black reformatting to Python files
PyinkPython code formatter
docformatterAutomatically formats Python docstrings for consistent style
SSortSorts Python statements by dependency for clearer code
reorder-python-importsReorders Python imports into a consistent, readable layout
μsortSorts import statements
eradicateRemove commented-out code from Python files

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted