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 βš™οΈ

Option Alias Description Default
--help -h Print usage information -
--path -p The path to the project directory to scan .
--exclude-pattern -e File patterns to exclude from the scan []
--exclude-folder -f Folders 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 ⭐️

Libraries

dart_unused_files
A library for finding unused Dart files in a project.