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.