Skip to content

aiskillstore/marketplace / skills/89jobrien/dead-code-removal

dead-code-removal

Verified

Detects and safely removes unused code (imports, functions, classes) across multiple languages. Use after refactoring, when removing features, or before production deployment. Includes safety checks and validation.

FileKindSize
SKILL.mdskill md7.4 KB
scripts/find-unused-imports.pyexecutablescript3.0 KB
skill-report.jsonconfig49.8 KB

scripts/find-unused-imports.py

View on GitHub
#!/usr/bin/env python3
"""Find unused imports in Python files.
Uses AST parsing to accurately detect unused imports.
"""

import ast
import json
import sys
from pathlib import Path


class ImportVisitor(ast.NodeVisitor):
    """AST visitor to collect imports and their usage."""

    def __init__(self):
        self.imports = {}  # name -> line_number
        self.used_names = set()
        self.import_star = False

    def visit_Import(self, node):
        for alias in node.names:
            name = alias.asname if alias.asname else alias.name.split(".")[0]
            self.imports[name] = node.lineno
        self.generic_visit(node)

    def visit_ImportFrom(self, node):
        if node.module:
            if node.names[0].name == "*":
                self.import_star = True
            else:
                for alias in node.names:
                    name = alias.asname if alias.asname else alias.name
                    self.imports[name] = node.lineno
        self.generic_visit(node)

    def visit_Name(self, node):
        if isinstance(node.ctx, ast.Load):
            self.used_names.add(node.id)
        self.generic_visit(node)

    def visit_Attribute(self, node):
        # Handle cases like os.path, sys.argv
        if isinstance(node.value, ast.Name):
            self.used_names.add(node.value.id)
        self.generic_visit(node)


def find_unused_imports(file_path: Path) -> dict:
    """Find unused imports in a Python file."""
    try:
        content = file_path.read_text()
        tree = ast.parse(content, filename=str(file_path))

        visitor = ImportVisitor()
        visitor.visit(tree)

        # Find unused imports
        unused = []
        for name, line_num in visitor.imports.items():
            if name not in visitor.used_names and not visitor.import_star:
                unused.append(
                    {
                        "name": name,
                        "line": line_num,
                    }
                )

        return {
            "file": str(file_path),
            "unused_imports": unused,
            "total_imports": len(visitor.imports),
            "has_import_star": visitor.import_star,
        }
    except SyntaxError as e:
        return {
            "file": str(file_path),
            "error": f"Syntax error: {e}",
            "unused_imports": [],
        }
    except Exception as e:
        return {
            "file": str(file_path),
            "error": f"Error parsing file: {e}",
            "unused_imports": [],
        }


def main():
    """Main entry point."""
    if len(sys.argv) < 2:
        print("Usage: find_unused_imports.py <python_file> [<python_file>...]")
        sys.exit(1)

    results = []
    for file_path_str in sys.argv[1:]:
        file_path = Path(file_path_str)
        if not file_path.exists():
            print(f"Warning: File not found: {file_path}", file=sys.stderr)
            continue

        result = find_unused_imports(file_path)
        results.append(result)

    print(json.dumps(results, indent=2))


if __name__ == "__main__":
    main()
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall