45
loading...
This website collects cookies to deliver better user experience
check-unused-files
, to search for unused Dart files.$ dart run dart_code_metrics:metrics check-unused-files lib
# or for a Flutter package
$ flutter pub run dart_code_metrics:metrics check-unused-files lib
Check unused *.dart files.
Usage: metrics check-unused-files [arguments] <directories>
-h, --help Print this usage information.
-r, --reporter=<console> The format of the output of the analysis.
[console (default), json]
--root-folder=<./> Root folder.
--exclude=<{/**.g.dart,/**.template.dart}> File paths in Glob syntax to be excluded.
(defaults to "{/**.g.dart,/**.template.dart}")
When you need to do a step-by-step refactoring on a large codebase with moving files and it's difficult to know if all the files are being used correctly
Code generation, which creates extra files, is popular in Dart. Sometimes it can be difficult to know if these files are no longer in use.
Unused file: <path_to_file>
...
Unused file: <path_to_file>
Total unused files - N
lib/
src/
entry_point.dart
first_file.dart
second_file.dart
import 'first_file.dart';
void main() {
... // some code
}
class SomeClass {
... // some code
}
import 'first_file.dart';
class SomeOtherClass {
... // some code
}
$ dart run dart_code_metrics:metrics check-unused-files lib
--exclude
option:$ dart run dart_code_metrics:metrics check-unused-files lib --exclude=”lib/**/second_file.dart”
No unused files found!
analyze
command. If you used to call CLI with:$ dart run dart_code_mertics:metrics lib
$ dart run dart_code_mertics:metrics analyze lib.
dart run dart_code_mertics:metrics lib
. It’ll work at least up to version 5.0, so no changes will be required to CI after transitioning to a newer version.45