dart_unused_files 1.0.0

SDKdartflutter
Platformandroidioswindowslinuxmacos

A Dart CLI tool that scans your Flutter or Dart project to find unused .dart files that can be safely removed.

Dart Unused Files Scanner

A Dart CLI tool that scans your Flutter or Dart project to find unused .dart files that can be safely removed.

pub package License: MIT

🚀 Example and result

Results look like this 👇️

dart_unused_files scan # enter to run

🔍 Scanning for unused Dart files...
📁 Analyzing 369 Dart files
📑 Reading 369 Dart files...
✅ Read 369 Dart files
============================================================
📊 UNUSED FILES ANALYSIS
============================================================
Total files scanned: 369
Files definitely used: 366
Files definitely unused: 3
============================================================
🗑️UNUSED FILES (safe to remove) 🔻
   - 📄 lib/models/menu_item.dart
   - 📄 lib/blocs/NP_Client/add_address_bloc.dart
   - 📄 lib/screens/no_connection.dart
--------------------------------------------------
💡 These files are NOT imported/exported/referenced anywhere.
💡 They are safe to delete after a final manual review.
💾 Total size of unused files: 16.75 KB
--------------------------------------------------

Why Use This Tool? 🔎

  • Reduce Codebase Size: Find and remove unnecessary files to keep your project clean
  • Improve Maintenance: Less unused code means easier maintenance
  • Speed Up Build Times: Fewer files can lead to faster build times
  • Accurate Detection: Comprehensive analysis to avoid false positives
  • Safe to Use: Only recommends files that are truly unused

Installation 📦

dart pub global activate dart_unused_files

Usage 🚀

# Run in the current directory (project root)
dart_unused_files scan

# for advance use u can use the following options ⬇️

# Specify project directory
dart_unused_files scan --path /path/to/your/project

# Exclude specific file patterns
dart_unused_files scan --exclude-pattern "*.g.dart" --exclude-pattern "*.freezed.dart"

# Exclude specific folders
dart_unused_files scan --exclude-folder "generated" --exclude-folder "third_party"

Command Line Options ⚙️

OptionAliasDescriptionDefault
--help-hPrint usage information-
--path-pThe path to the project directory to scan.
--exclude-pattern-eFile patterns to exclude from the scan[]
--exclude-folder-fFolders to exclude from the scan[]

How It Works 🧩

The tool uses a comprehensive approach to find unused Dart files:

  1. File Collection: Scans all Dart files in the project
  2. Dependency Analysis: Builds a complete map of file dependencies
  3. Entry Point Detection: Identifies all possible entry points
  4. Reachability Analysis: Marks all files reachable from any entry point
  5. Pattern Matching: Looks for additional usage patterns
  6. Report Generation: Lists only truly unused files

Default Exclusions 🛡️

The scanner automatically excludes these files and folders:

Files

  • .g.dart (generated code)
  • .gr.dart (generated routes)
  • .freezed.dart (freezed generated code)
  • .mocks.dart (mockito generated mocks)
  • generated_plugin_registrant.dart
  • firebase_options.dart

Folders

  • generated
  • .dart_tool
  • build

License 📄

This project is licensed under the MIT License - see the LICENSE file for details.

Author 👨🏻‍💻

Emad Beltaje

Support 🧡

Don't forget to like the package 👍🏻 and star the repo ⭐️