Skip to content

Find unused exports and dead code in JS/TS projects. Code cleanup tool.

Notifications You must be signed in to change notification settings

lxgicstudios/deadcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@lxgicstudios/deadcode

Find unused exports, functions, and dead code in JavaScript/TypeScript projects.

Clean up your codebase. Know what's actually used.

Installation

# Use directly with npx (recommended)
npx @lxgicstudios/deadcode

# Or install globally
npm install -g @lxgicstudios/deadcode

Usage

# Scan current directory
npx @lxgicstudios/deadcode

# Scan specific directory
npx @lxgicstudios/deadcode src/

# Ignore patterns
npx @lxgicstudios/deadcode --ignore test --ignore mock

# JSON output for CI
npx @lxgicstudios/deadcode --json > dead-code-report.json

# Quiet mode (just counts)
npx @lxgicstudios/deadcode -q

Example Output

ℹ Scanning src/ for dead code...

ℹ Scanned 47 files
ℹ Found 234 exports, 189 imports

⚠ Found 12 potentially unused exports:

src/utils/helpers.ts
  L15: function formatDate
  L42: const DEPRECATED_CONFIG

src/components/OldButton.tsx
  L8: class OldButton

src/types/legacy.ts
  L3: interface LegacyUser
  L12: type OldConfig

Note: Some exports may be used dynamically or externally. Review before deleting.

What It Finds

  • ✅ Exported functions that are never imported
  • ✅ Exported constants that are never used
  • ✅ Exported classes that are never instantiated
  • ✅ Exported types/interfaces that are never referenced
  • ✅ Re-exports that go nowhere

What It Skips

  • 📁 node_modules, dist, build directories
  • 📄 Index files (usually re-export hubs)
  • 🧪 Test files (.test.ts, .spec.ts)
  • ⚙️ Config files

Options

Option Description
-d, --dir <path> Directory to scan (default: cwd)
-i, --ignore <pattern> Ignore files matching pattern
--json Output as JSON
-q, --quiet Only show counts
-h, --help Show help

CI Integration

# .github/workflows/deadcode.yml
- name: Check for dead code
  run: npx @lxgicstudios/deadcode --json > report.json
  continue-on-error: true

Programmatic API

import { findDeadCode, getCodeFiles, extractExports } from '@lxgicstudios/deadcode';

// Full scan
const result = findDeadCode('./src', { ignorePatterns: ['test'] });
console.log(result.unusedExports);

// Just get files
const files = getCodeFiles('./src');

// Extract exports from a file
const exports = extractExports(fileContent, filePath);

Built by LXGIC Studios

🔗 GitHub · Twitter

About

Find unused exports and dead code in JS/TS projects. Code cleanup tool.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published