Skip to content

Commit 706e018

Browse files
Initial release v0.1.0: DeadCode CLI
- Scan for unused exports, dead routes, orphaned CSS, unreferenced components - Remove command with --dry-run preview - Stats command for quick overview - pathspec-based file filtering - Rich CLI output with tables - 23 passing tests
0 parents  commit 706e018

11 files changed

Lines changed: 1215 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
environment: pypi
11+
permissions:
12+
id-token: write
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.12"
21+
22+
- name: Install build tools
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build
26+
27+
- name: Build package
28+
run: python -m build
29+
30+
- name: Publish to PyPI
31+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12", "3.13"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -e ".[dev]"
28+
29+
- name: Run tests
30+
run: |
31+
python -m pytest tests/ -v --tb=short
32+
33+
- name: Check CLI works
34+
run: |
35+
deadcode --version
36+
deadcode --help

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
node_modules/
2+
.git/
3+
.next/
4+
dist/
5+
build/
6+
out/
7+
coverage/
8+
__pycache__/
9+
*.min.js
10+
*.min.css
11+
.cache/
12+
public/
13+
static/
14+
.pytest_cache/
15+
src/deadcode.egg-info/

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright 2026 Revenue Holdings
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# DeadCode
2+
3+
CLI tool to detect and auto-remove unused exports, dead routes, orphaned CSS, and unreferenced components in TypeScript/React/Next.js projects.
4+
5+
[![CI](https://github.com/Coding-Dev-Tools/deadcode/actions/workflows/test.yml/badge.svg)](https://github.com/Coding-Dev-Tools/deadcode/actions/workflows/test.yml)
6+
[![PyPI](https://img.shields.io/pypi/v/deadcode)](https://pypi.org/project/deadcode/)
7+
8+
## Features
9+
10+
- **Unused exports** — find functions, classes, constants, types that are exported but never imported
11+
- **Dead routes** — find Next.js pages/api routes with no internal links
12+
- **Orphaned CSS** — find CSS classes defined but never used in JSX
13+
- **Unreferenced components** — find React components defined but never imported
14+
- **Safe auto-removal** — preview with `--dry-run` before making changes
15+
- **Monorepo support** — handles large projects efficiently
16+
- **CI integration** — JSON output for automated pipelines
17+
18+
## Installation
19+
20+
```bash
21+
pip install deadcode
22+
```
23+
24+
## Usage
25+
26+
### Scan for dead code
27+
28+
```bash
29+
deadcode scan
30+
deadcode scan -p /path/to/project
31+
deadcode scan --json-output
32+
deadcode scan -c unused_export # Filter by category
33+
```
34+
35+
### Preview removal (dry run)
36+
37+
```bash
38+
deadcode remove --dry-run
39+
```
40+
41+
### Remove dead code
42+
43+
```bash
44+
deadcode remove
45+
deadcode remove -c orphaned_css
46+
```
47+
48+
### View stats
49+
50+
```bash
51+
deadcode stats
52+
```
53+
54+
## Categories
55+
56+
| Category | Description |
57+
|----------|-------------|
58+
| `unused_export` | Exported names never imported elsewhere |
59+
| `dead_route` | Next.js routes with no internal links |
60+
| `orphaned_css` | CSS classes not referenced in JSX |
61+
| `unreferenced_component` | React components never imported |
62+
63+
## Ignore Patterns
64+
65+
Use `--ignore` to exclude paths (gitignore-style):
66+
67+
```bash
68+
deadcode scan -i "generated/" -i "**/*.generated.ts"
69+
```
70+
71+
Default ignores: `node_modules/`, `.git/`, `.next/`, `dist/`, `build/`, `public/`, `static/`
72+
73+
## CI Integration
74+
75+
```bash
76+
deadcode scan --json-output > deadcode-report.json
77+
```
78+
79+
Exit with findings:
80+
81+
```bash
82+
deadcode scan -j | python3 -c "import sys,json; d=json.load(sys.stdin); sys.exit(1 if d['findings'] else 0)"
83+
```
84+
85+
## License
86+
87+
MIT

conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""pytest configuration — add project src to Python path."""
2+
import site
3+
import sys
4+
from pathlib import Path
5+
6+
# Add user site-packages (contains pathspec, rich, click for Python 3.12)
7+
user_site = site.getusersitepackages()
8+
if user_site and user_site not in sys.path:
9+
sys.path.insert(0, user_site)
10+
11+
# Add src directory to Python path so tests can import deadcode package
12+
src_dir = Path(__file__).parent / "src"
13+
if str(src_dir) not in sys.path:
14+
sys.path.insert(0, str(src_dir))

pyproject.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[build-system]
2+
requires = ["setuptools>=68.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "deadcode"
7+
version = "0.1.0"
8+
description = "CLI tool to detect and auto-remove unused exports, dead routes, orphaned CSS in TS/React/Next.js projects"
9+
readme = "README.md"
10+
requires-python = ">=3.10"
11+
license = "MIT"
12+
authors = [{name = "Revenue Holdings"}]
13+
urls = {Homepage = "https://github.com/Coding-Dev-Tools/deadcode", Repository = "https://github.com/Coding-Dev-Tools/deadcode"}
14+
keywords = ["dead-code", "unused-exports", "typescript", "react", "nextjs", "cli", "css", "tree-shaking"]
15+
classifiers = [
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Developers",
18+
"Topic :: Software Development :: Quality Assurance",
19+
"Topic :: Software Development :: Testing",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Programming Language :: Python :: 3.13",
25+
]
26+
dependencies = [
27+
"click>=8.1.0",
28+
"rich>=13.0.0",
29+
"pathspec>=0.11.0",
30+
]
31+
32+
[project.optional-dependencies]
33+
dev = [
34+
"pytest>=7.0.0",
35+
"pytest-cov>=4.0.0",
36+
]
37+
38+
[project.scripts]
39+
deadcode = "deadcode.cli:cli"
40+
41+
[tool.setuptools.packages.find]
42+
where = ["src"]
43+
44+
[tool.pytest.ini_options]
45+
testpaths = ["tests"]
46+
python_files = ["test_*.py"]

src/deadcode/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""DeadCode CLI — Detect and remove unused code in TS/React/Next.js projects."""
2+
3+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)