dart_unused_files 1.0.0
dart_unused_files: ^1.0.0 copied to clipboard
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.
๐ 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 โญ๏ธ