Unused Code Cleaner

Pub Version License: MIT

๐Ÿงน Automatically find and remove unused code from your Flutter/Dart projects

Clean up your codebase in seconds - remove unused assets, functions, packages, and files with one simple command.

โšก Quick Start

# Install
dart pub global activate unused_code_cleaner

# Preview what will be cleaned (always start here!)
dart run unused_code_cleaner --dry-run --all

# Clean your project
dart run unused_code_cleaner --all

โœจ What It Does

  • ๐Ÿ–ผ๏ธ Removes unused assets (images, fonts, JSON files)
  • โšก Deletes unused functions and methods
  • ๐Ÿ“ฆ Cleans unused packages from pubspec.yaml
  • ๐Ÿ“„ Removes unused Dart files
  • ๐Ÿ›ก๏ธ Safe by default - creates backups automatically

๐Ÿ“ฑ Perfect For

  • Flutter apps with too many assets
  • Code cleanup after refactoring
  • Reducing app size before release
  • Maintaining clean codebases

๏ฟฝ๏ธ Safety First

This tool is designed to be safe:

  • โœ… Always creates backups before deletion
  • โœ… Excludes critical files automatically
  • โœ… --dry-run mode to preview changes
  • โœ… Requires confirmation before deletion

Golden Rule: Always run --dry-run first!

๐Ÿ›ก๏ธ Safety Features

๐Ÿš€ Common Commands

# Clean everything (recommended)
dart run unused_code_cleaner --dry-run --all

# Clean only assets
dart run unused_code_cleaner --assets --dry-run

# Clean only unused packages
dart run unused_code_cleaner --packages --dry-run

# Exclude certain files
dart run unused_code_cleaner --exclude "**/*.g.dart" --dry-run --all

๐Ÿ“‹ Example Output

๐Ÿ” Analyzing project...
โœ… Found 3 unused assets (saving 2.1 MB)
โœ… Found 5 unused functions
โœ… Found 1 unused package

๐Ÿ“Š Results:
โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ  unused_logo.png (1.2 MB)
โ”œโ”€โ”€ ๐Ÿ“„ old_config.json (0.9 MB)
โ”œโ”€โ”€ โšก debugHelper() function
โ””โ”€โ”€ ๐Ÿ“ฆ http package

๐Ÿ’พ Total space savings: 2.1 MB
โฑ๏ธ  Analysis completed in 1.2s

โ“ Remove these items? (y/N)

๐Ÿ› ๏ธ Options

Command What it does
--all Clean everything
--assets Clean unused assets only
--functions Clean unused functions only
--packages Clean unused packages only
--dry-run Preview without deleting
--verbose Show detailed info

๐Ÿค Contributing

Found a bug? Want a feature? Open an issue!

๐Ÿ“œ License

MIT License - free to use in your projects.

Libraries

unused_code_cleaner
A comprehensive Dart package for detecting and cleaning unused code in Flutter/Dart projects.