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.
π 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:
- File Collection: Scans all Dart files in the project
- Dependency Analysis: Builds a complete map of file dependencies
- Entry Point Detection: Identifies all possible entry points
- Reachability Analysis: Marks all files reachable from any entry point
- Pattern Matching: Looks for additional usage patterns
- 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.