ghostbuster-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ghostbuster_cli-0.1.0/.github/workflows/ci.yml +112 -0
- ghostbuster_cli-0.1.0/.gitignore +37 -0
- ghostbuster_cli-0.1.0/CHANGELOG.md +25 -0
- ghostbuster_cli-0.1.0/CONTRIBUTING.md +112 -0
- ghostbuster_cli-0.1.0/LICENSE +21 -0
- ghostbuster_cli-0.1.0/PKG-INFO +239 -0
- ghostbuster_cli-0.1.0/README.md +207 -0
- ghostbuster_cli-0.1.0/assets/npm_package_icon.png +0 -0
- ghostbuster_cli-0.1.0/assets/readme_header.png +0 -0
- ghostbuster_cli-0.1.0/assets/terminal_icon.png +0 -0
- ghostbuster_cli-0.1.0/pyproject.toml +101 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/__init__.py +3 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/__main__.py +5 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/cli/__init__.py +1 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/cli/app.py +76 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/cli/bust.py +116 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/cli/display.py +276 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/cli/scan.py +141 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/config.py +116 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/__init__.py +1 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/dead_imports.py +273 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/models.py +140 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/orphan_files.py +298 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/phantom_env.py +196 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/scanner.py +112 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/scoring.py +83 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/core/zombie_code.py +345 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/fixers/__init__.py +1 -0
- ghostbuster_cli-0.1.0/src/ghostbuster/fixers/import_fixer.py +133 -0
- ghostbuster_cli-0.1.0/tests/__init__.py +1 -0
- ghostbuster_cli-0.1.0/tests/conftest.py +128 -0
- ghostbuster_cli-0.1.0/tests/test_cli.py +65 -0
- ghostbuster_cli-0.1.0/tests/test_dead_imports.py +104 -0
- ghostbuster_cli-0.1.0/tests/test_orphan_files.py +76 -0
- ghostbuster_cli-0.1.0/tests/test_phantom_env.py +104 -0
- ghostbuster_cli-0.1.0/tests/test_scoring.py +116 -0
- ghostbuster_cli-0.1.0/tests/test_zombie_code.py +104 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint:
|
|
14
|
+
name: Lint
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install ruff mypy
|
|
28
|
+
|
|
29
|
+
- name: Ruff check
|
|
30
|
+
run: ruff check src/ tests/
|
|
31
|
+
|
|
32
|
+
- name: Ruff format check
|
|
33
|
+
run: ruff format --check src/ tests/
|
|
34
|
+
|
|
35
|
+
- name: Mypy type check
|
|
36
|
+
run: |
|
|
37
|
+
pip install -e ".[dev]" 2>/dev/null || pip install -e .
|
|
38
|
+
mypy src/
|
|
39
|
+
|
|
40
|
+
test:
|
|
41
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
42
|
+
runs-on: ${{ matrix.os }}
|
|
43
|
+
strategy:
|
|
44
|
+
fail-fast: false
|
|
45
|
+
matrix:
|
|
46
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
47
|
+
os: [ubuntu-latest]
|
|
48
|
+
include:
|
|
49
|
+
- python-version: "3.12"
|
|
50
|
+
os: macos-latest
|
|
51
|
+
- python-version: "3.12"
|
|
52
|
+
os: windows-latest
|
|
53
|
+
|
|
54
|
+
steps:
|
|
55
|
+
- uses: actions/checkout@v4
|
|
56
|
+
|
|
57
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
58
|
+
uses: actions/setup-python@v5
|
|
59
|
+
with:
|
|
60
|
+
python-version: ${{ matrix.python-version }}
|
|
61
|
+
|
|
62
|
+
- name: Install dependencies
|
|
63
|
+
run: |
|
|
64
|
+
python -m pip install --upgrade pip
|
|
65
|
+
pip install -e .
|
|
66
|
+
pip install pytest
|
|
67
|
+
|
|
68
|
+
- name: Run tests
|
|
69
|
+
run: pytest tests/ -v --tb=short
|
|
70
|
+
|
|
71
|
+
build:
|
|
72
|
+
name: Build check
|
|
73
|
+
runs-on: ubuntu-latest
|
|
74
|
+
steps:
|
|
75
|
+
- uses: actions/checkout@v4
|
|
76
|
+
|
|
77
|
+
- name: Set up Python
|
|
78
|
+
uses: actions/setup-python@v5
|
|
79
|
+
with:
|
|
80
|
+
python-version: "3.12"
|
|
81
|
+
|
|
82
|
+
- name: Install build tools
|
|
83
|
+
run: python -m pip install --upgrade pip build twine
|
|
84
|
+
|
|
85
|
+
- name: Build package
|
|
86
|
+
run: python -m build
|
|
87
|
+
|
|
88
|
+
- name: Check package
|
|
89
|
+
run: twine check dist/*
|
|
90
|
+
|
|
91
|
+
- name: Upload artifacts
|
|
92
|
+
uses: actions/upload-artifact@v4
|
|
93
|
+
with:
|
|
94
|
+
name: dist
|
|
95
|
+
path: dist/
|
|
96
|
+
|
|
97
|
+
# Uncomment when ready to publish to PyPI
|
|
98
|
+
# publish:
|
|
99
|
+
# name: Publish to PyPI
|
|
100
|
+
# needs: [lint, test, build]
|
|
101
|
+
# runs-on: ubuntu-latest
|
|
102
|
+
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
|
103
|
+
# environment: pypi
|
|
104
|
+
# permissions:
|
|
105
|
+
# id-token: write # Required for trusted publishing
|
|
106
|
+
# steps:
|
|
107
|
+
# - uses: actions/download-artifact@v4
|
|
108
|
+
# with:
|
|
109
|
+
# name: dist
|
|
110
|
+
# path: dist/
|
|
111
|
+
# - name: Publish to PyPI
|
|
112
|
+
# uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
ENV/
|
|
16
|
+
|
|
17
|
+
# IDE
|
|
18
|
+
.vscode/
|
|
19
|
+
.idea/
|
|
20
|
+
*.swp
|
|
21
|
+
*.swo
|
|
22
|
+
*~
|
|
23
|
+
|
|
24
|
+
# OS
|
|
25
|
+
.DS_Store
|
|
26
|
+
Thumbs.db
|
|
27
|
+
|
|
28
|
+
# Testing
|
|
29
|
+
.pytest_cache/
|
|
30
|
+
.coverage
|
|
31
|
+
htmlcov/
|
|
32
|
+
.mypy_cache/
|
|
33
|
+
.ruff_cache/
|
|
34
|
+
|
|
35
|
+
# Environment
|
|
36
|
+
.env
|
|
37
|
+
.env.local
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-08-29
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `ghostbuster scan` command with 4 built-in scanners
|
|
15
|
+
- **Dead Import Scanner** - detects dependencies declared but never imported
|
|
16
|
+
- **Orphan File Scanner** - finds files/dirs that should be in .gitignore
|
|
17
|
+
- **Zombie Code Scanner** - detects functions/classes that are never called
|
|
18
|
+
- **Phantom Env Scanner** - finds env vars referenced but not set
|
|
19
|
+
- `ghostbuster bust` command with dry-run (default) and --confirm modes
|
|
20
|
+
- **Ghost Score** - weighted 0-100 technical debt score
|
|
21
|
+
- Formatted terminal output with tables, progress bars, and score cards
|
|
22
|
+
- JSON and Markdown output formats (`--format json|markdown`)
|
|
23
|
+
- Configuration via `.ghostbuster.toml` or `pyproject.toml [tool.ghostbuster]`
|
|
24
|
+
- Full test suite with pytest
|
|
25
|
+
- GitHub Actions CI (lint, test, build)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Contributing to Ghostbuster
|
|
2
|
+
|
|
3
|
+
First off, thank you for considering contributing to Ghostbuster!
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Python 3.10+
|
|
10
|
+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
|
|
11
|
+
|
|
12
|
+
### Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Clone the repo
|
|
16
|
+
git clone https://github.com/adewanggar/ghostbuster-cli.git
|
|
17
|
+
cd ghostbuster-cli
|
|
18
|
+
|
|
19
|
+
# Create virtual environment & install in development mode
|
|
20
|
+
python -m venv .venv
|
|
21
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
22
|
+
pip install -e ".[dev]" 2>/dev/null || pip install -e .
|
|
23
|
+
pip install pytest ruff mypy
|
|
24
|
+
|
|
25
|
+
# Run the tool locally
|
|
26
|
+
ghostbuster scan .
|
|
27
|
+
|
|
28
|
+
# Run tests
|
|
29
|
+
pytest tests/ -v
|
|
30
|
+
|
|
31
|
+
# Run linter
|
|
32
|
+
ruff check src/ tests/
|
|
33
|
+
|
|
34
|
+
# Run type checker
|
|
35
|
+
mypy src/
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Making Changes
|
|
39
|
+
|
|
40
|
+
### Code Style
|
|
41
|
+
|
|
42
|
+
- We use **Ruff** for linting and formatting.
|
|
43
|
+
- All code must have **type hints**.
|
|
44
|
+
- Follow the existing code patterns - especially the core/CLI separation.
|
|
45
|
+
|
|
46
|
+
### Architecture Rules
|
|
47
|
+
|
|
48
|
+
1. **`core/`** must NOT import from `cli/`, `rich`, or any UI library.
|
|
49
|
+
2. **`cli/`** is the only layer that touches terminal I/O.
|
|
50
|
+
3. Each scanner is a self-contained module implementing the `Scanner` protocol.
|
|
51
|
+
4. All new scanners must be registered in `scanner.py:create_default_orchestrator()`.
|
|
52
|
+
|
|
53
|
+
### Adding a New Scanner
|
|
54
|
+
|
|
55
|
+
1. Create `src/ghostbuster/core/my_scanner.py`
|
|
56
|
+
2. Implement the `Scanner` protocol (must have `name: str` and `scan(path) -> list[Ghost]`)
|
|
57
|
+
3. Register in `create_default_orchestrator()`
|
|
58
|
+
4. Add tests in `tests/test_my_scanner.py`
|
|
59
|
+
5. Update the README feature list
|
|
60
|
+
|
|
61
|
+
### Testing
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Run all tests
|
|
65
|
+
pytest tests/ -v
|
|
66
|
+
|
|
67
|
+
# Run specific test file
|
|
68
|
+
pytest tests/test_dead_imports.py -v
|
|
69
|
+
|
|
70
|
+
# Run with coverage
|
|
71
|
+
pip install pytest-cov
|
|
72
|
+
pytest tests/ --cov=ghostbuster --cov-report=html
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Commit Messages
|
|
76
|
+
|
|
77
|
+
Use conventional commit messages:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
feat: add Node.js dependency scanner
|
|
81
|
+
fix: handle missing pyproject.toml gracefully
|
|
82
|
+
docs: update README with new scanner info
|
|
83
|
+
test: add edge case for empty requirements.txt
|
|
84
|
+
chore: bump ruff version
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Pull Request Process
|
|
88
|
+
|
|
89
|
+
1. Fork the repo and create a feature branch from `main`.
|
|
90
|
+
2. Make your changes with tests.
|
|
91
|
+
3. Ensure all checks pass: `ruff check`, `mypy`, `pytest`.
|
|
92
|
+
4. Open a PR with a clear description of what you changed and why.
|
|
93
|
+
5. Wait for review - we aim to respond within 48 hours.
|
|
94
|
+
|
|
95
|
+
## Reporting Bugs
|
|
96
|
+
|
|
97
|
+
Open an issue with:
|
|
98
|
+
- Your OS and Python version
|
|
99
|
+
- The command you ran
|
|
100
|
+
- Expected vs actual behavior
|
|
101
|
+
- Minimal reproducible example (if possible)
|
|
102
|
+
|
|
103
|
+
## Feature Requests
|
|
104
|
+
|
|
105
|
+
Open an issue with:
|
|
106
|
+
- What problem does it solve?
|
|
107
|
+
- Who would use it?
|
|
108
|
+
- Any implementation ideas?
|
|
109
|
+
|
|
110
|
+
## Code of Conduct
|
|
111
|
+
|
|
112
|
+
Be kind, be constructive, and respect other contributors.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ghostbuster Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ghostbuster-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Find and bust the ghosts haunting your codebase - unused deps, dead code, orphan files, and phantom env vars.
|
|
5
|
+
Project-URL: Homepage, https://github.com/adewanggar/ghostbuster-cli
|
|
6
|
+
Project-URL: Documentation, https://github.com/adewanggar/ghostbuster-cli#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/adewanggar/ghostbuster-cli
|
|
8
|
+
Project-URL: Issues, https://github.com/adewanggar/ghostbuster-cli/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/adewanggar/ghostbuster-cli/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Ghostbuster Contributors
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: cli,code-quality,dead-code,developer-tools,devtools,linter,unused-dependencies
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
|
+
Classifier: Topic :: Software Development :: Testing
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Requires-Dist: rich>=13.0.0
|
|
29
|
+
Requires-Dist: tomli>=2.0.0; python_version < '3.11'
|
|
30
|
+
Requires-Dist: typer>=0.9.0
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
<div align="center">
|
|
34
|
+
|
|
35
|
+
<img src="assets/readme_header.png" alt="Ghostbuster Header" width="100%" />
|
|
36
|
+
|
|
37
|
+
# Ghostbuster
|
|
38
|
+
|
|
39
|
+
**Find and bust the ghosts haunting your codebase.**
|
|
40
|
+
|
|
41
|
+
[](https://pypi.org/project/ghostbuster-cli/)
|
|
42
|
+
[](https://pypi.org/project/ghostbuster-cli/)
|
|
43
|
+
[](https://github.com/adewanggar/ghostbuster-cli/actions)
|
|
44
|
+
[](https://opensource.org/licenses/MIT)
|
|
45
|
+
[](https://pypi.org/project/ghostbuster-cli/)
|
|
46
|
+
|
|
47
|
+
Unused dependencies, dead functions, orphan files, and phantom environment variables lurk in codebases - slowing down repos, confusing new contributors, and wasting CI minutes.
|
|
48
|
+
|
|
49
|
+
**Ghostbuster finds them all in one command.**
|
|
50
|
+
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## <img src="assets/terminal_icon.png" width="24" height="24" valign="middle" /> Quick Start
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Install
|
|
59
|
+
pip install ghostbuster-cli
|
|
60
|
+
|
|
61
|
+
# Scan your project
|
|
62
|
+
ghostbuster scan
|
|
63
|
+
|
|
64
|
+
# No config needed.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## What It Finds
|
|
68
|
+
|
|
69
|
+
Ghostbuster detects **4 categories** in your codebase:
|
|
70
|
+
|
|
71
|
+
| Category | Identifier | What It Detects |
|
|
72
|
+
|:---------|:-----------|:----------------|
|
|
73
|
+
| **Dead Import** | `dead-import` | Dependencies in `requirements.txt` / `pyproject.toml` that are never imported |
|
|
74
|
+
| **Orphan File** | `orphan-file` | `node_modules/`, `venv/`, `.pyc`, large files that should be in `.gitignore` |
|
|
75
|
+
| **Zombie Code** | `zombie-code` | Functions and classes that are defined but never called from anywhere |
|
|
76
|
+
| **Phantom Env** | `phantom-env` | `os.environ["KEY"]` / `os.getenv("KEY")` where KEY is never set |
|
|
77
|
+
|
|
78
|
+
## Ghost Score
|
|
79
|
+
|
|
80
|
+
Every scan produces a **Ghost Score** (0-100) - the higher the score, the more technical debt in your codebase:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
+----------------------- Ghost Score ------------------------+
|
|
84
|
+
| |
|
|
85
|
+
| 47 / 100 |
|
|
86
|
+
| |
|
|
87
|
+
| #########################-------------------------- |
|
|
88
|
+
| |
|
|
89
|
+
| Noticeable technical debt detected. |
|
|
90
|
+
| |
|
|
91
|
+
+------------------------------------------------------------+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Auto-Fix
|
|
95
|
+
|
|
96
|
+
Ghostbuster can also fix detected issues:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Preview what would be fixed (safe, default)
|
|
100
|
+
ghostbuster bust
|
|
101
|
+
|
|
102
|
+
# Actually apply fixes
|
|
103
|
+
ghostbuster bust --confirm
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Currently auto-fixes:
|
|
107
|
+
- Removes unused import statements
|
|
108
|
+
- Suggests `.gitignore` additions for orphan files
|
|
109
|
+
- Suggests `.env` additions for phantom env vars
|
|
110
|
+
|
|
111
|
+
## Usage
|
|
112
|
+
|
|
113
|
+
### Basic Scan
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Scan current directory
|
|
117
|
+
ghostbuster scan
|
|
118
|
+
|
|
119
|
+
# Scan a specific path
|
|
120
|
+
ghostbuster scan ./my-project
|
|
121
|
+
|
|
122
|
+
# Verbose mode (show locations and fix suggestions)
|
|
123
|
+
ghostbuster scan -v
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Filtered Scan
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Only check for dead imports
|
|
130
|
+
ghostbuster scan --category dead-import
|
|
131
|
+
|
|
132
|
+
# Only check for zombie code
|
|
133
|
+
ghostbuster scan -c zombie-code
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Output Formats
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Default: formatted terminal output
|
|
140
|
+
ghostbuster scan
|
|
141
|
+
|
|
142
|
+
# JSON (for CI pipelines and scripting)
|
|
143
|
+
ghostbuster scan --format json
|
|
144
|
+
|
|
145
|
+
# Markdown (for pasting into issues/PRs)
|
|
146
|
+
ghostbuster scan --format markdown
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### CI Integration
|
|
150
|
+
|
|
151
|
+
```yaml
|
|
152
|
+
# .github/workflows/ghostbuster.yml
|
|
153
|
+
name: Ghost Check
|
|
154
|
+
on: [push, pull_request]
|
|
155
|
+
jobs:
|
|
156
|
+
scan:
|
|
157
|
+
runs-on: ubuntu-latest
|
|
158
|
+
steps:
|
|
159
|
+
- uses: actions/checkout@v4
|
|
160
|
+
- uses: actions/setup-python@v5
|
|
161
|
+
with:
|
|
162
|
+
python-version: "3.12"
|
|
163
|
+
- run: pip install ghostbuster-cli
|
|
164
|
+
- run: ghostbuster scan --format json
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
> Note: `ghostbuster scan` exits with code 1 if issues are found - ideal for CI gates.
|
|
168
|
+
|
|
169
|
+
## Configuration
|
|
170
|
+
|
|
171
|
+
Ghostbuster works with **zero config**, but you can customize it:
|
|
172
|
+
|
|
173
|
+
### `pyproject.toml`
|
|
174
|
+
|
|
175
|
+
```toml
|
|
176
|
+
[tool.ghostbuster]
|
|
177
|
+
exclude_dirs = ["migrations", "generated"]
|
|
178
|
+
ignore_packages = ["my-internal-lib"]
|
|
179
|
+
ignore_env_vars = ["CI", "GITHUB_ACTIONS"]
|
|
180
|
+
ignore_names = ["deprecated_helper"]
|
|
181
|
+
large_file_threshold = 5242880 # 5MB
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `.ghostbuster.toml`
|
|
185
|
+
|
|
186
|
+
```toml
|
|
187
|
+
exclude_dirs = ["vendor", "third_party"]
|
|
188
|
+
categories = ["dead-import", "phantom-env"] # Only run these scanners
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## How It Works
|
|
192
|
+
|
|
193
|
+
Ghostbuster uses **pure AST analysis** - no runtime imports, no code execution, no external services:
|
|
194
|
+
|
|
195
|
+
1. **Dead Imports**: Parses `requirements.txt`/`pyproject.toml` for declared dependencies, walks AST for imports, cross-references with a package-to-import mapping table.
|
|
196
|
+
2. **Orphan Files**: Walks the file tree checking for known ignorable patterns (`node_modules/`, `venv/`, `__pycache__/`, large binary files) and verifies they are covered by `.gitignore`.
|
|
197
|
+
3. **Zombie Code**: Collects all function/class definitions and references across the codebase, identifying definitions with zero references (skipping `__init__`, `test_*`, and decorated functions).
|
|
198
|
+
4. **Phantom Env**: Detects `os.environ["KEY"]`, `os.environ.get("KEY")`, `os.getenv("KEY")` patterns via AST and checks against `.env` files and system environment.
|
|
199
|
+
|
|
200
|
+
## Alternatives
|
|
201
|
+
|
|
202
|
+
| Tool | Scope | Ghostbuster Advantage |
|
|
203
|
+
|:-----|:------|:----------------------|
|
|
204
|
+
| [Vulture](https://github.com/jendrikseipp/vulture) | Dead code only | Ghostbuster also covers dependencies, files, and env vars |
|
|
205
|
+
| [deptry](https://deptry.com/) | Unused deps only | Ghostbuster is a superset with unified output |
|
|
206
|
+
| [deadcode](https://github.com/albertas/deadcode) | Dead code only | Ghostbuster adds auto-fix and unified scoring |
|
|
207
|
+
| [git-sizer](https://github.com/github/git-sizer) | Repo size | Ghostbuster checks .gitignore coverage |
|
|
208
|
+
|
|
209
|
+
## Roadmap
|
|
210
|
+
|
|
211
|
+
- <img src="assets/npm_package_icon.png" width="18" height="18" valign="middle" /> Node.js / TypeScript support (scan `package.json`, dead exports)
|
|
212
|
+
- Pre-commit hook integration
|
|
213
|
+
- GitHub Actions reporter (comment Ghost Score on PRs)
|
|
214
|
+
- Config inheritance for monorepos
|
|
215
|
+
- Ghost Score history tracking & trend chart
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
git clone https://github.com/adewanggar/ghostbuster-cli.git
|
|
223
|
+
cd ghostbuster-cli
|
|
224
|
+
pip install -e .
|
|
225
|
+
pip install pytest ruff mypy
|
|
226
|
+
pytest tests/ -v
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
MIT (c) Ghostbuster Contributors
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
<div align="center">
|
|
236
|
+
|
|
237
|
+
[Report Bug](https://github.com/adewanggar/ghostbuster-cli/issues) | [Request Feature](https://github.com/adewanggar/ghostbuster-cli/issues) | [Changelog](CHANGELOG.md)
|
|
238
|
+
|
|
239
|
+
</div>
|