Skip to content

Harineko0/dartd

Repository files navigation

dartd logo

dartd

Pub CI Dart SDK License: MIT

dartd

Dead-code sweeper for Dart and Flutter projects. Scan for unused modules (files, classes, globals, generated assets, and more), report them, and prune safely—no edits to generated files.

Usage

  • dartd analyze --root <path> — scan for unused modules and declarations (defaults to the current directory).
  • dartd fix --root <path> — remove unused modules, class members (methods/getters/setters/fields), and delete empty Dart files under lib/ (dry-run to preview).
  • dartd fix --remove method — narrow removals (file, class, function, var, method, member, import; default: all).
  • dartd fix --iteration <count> — cap how many fix passes run before stopping (rerun to continue).
  • dartd analyze --root packages/feature/lib — target a specific package or feature folder.
  • dartd fix --root packages/feature/lib — apply fixes to a different root.

Quick flow:

dartd analyze                  # review what can go
dartd fix                      # prune unused code safely
dartd analyze --root . --json  # optional JSON pass for tooling/CI
dart run build_runner build -d # regenerate assets; generated files stay untouched

Why dartd

  • Module-aware grouping keeps related symbols together so one reference preserves the whole unit.
  • Understands files, classes (and unused members), enums, extensions, typedefs, globals, and generated assets.
  • Framework-agnostic analysis that works across Dart and Flutter codebases.
  • Fast, CLI-first ergonomics with JSON output for automation.

What counts as usage

  • Direct identifier references (e.g. fooProvider, RemoteConfigParameter).
  • Type relationships (e.g. extends LocationBasedUseCase).
  • Extension method calls (e.g. children.withSpaceBetween()).
  • Typedef usage (e.g. FutureCallback<T>).
  • Enum usage (e.g. RemoteConfigParameter.values).

Safety rails

  • Generated files (*.g.dart, *.freezed.dart, *.gen.dart, *.gr.dart) are never modified or deleted.
  • Files are deleted only when they contain no used modules and no used top-level declarations.
  • Constructor params/initializers tied solely to removed fields are pruned alongside those fields.

Limitations

  • Heuristic detection: reflection, string lookups, and dynamic calls may appear unused.
  • Mixed constructors are edited conservatively; review dartd analyze output before committing fixes.

Install

dart pub global activate dartd

Development

dart pub get
dart format .
dart analyze .
dart run bin/dartd.dart analyze --root lib
dart run bin/dartd.dart fix --root lib

License

MIT

About

CLI to analyze and remove unused Dart classes or modules in a project.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages