flutter_janitor 1.0.0
flutter_janitor: ^1.0.0 copied to clipboard
Conservative Flutter cleanup CLI for unused assets and dependencies with reports, backups, and undo.
flutter_janitor #
flutter_janitor is a conservative Flutter cleanup CLI that scans for:
- unused declared assets (images/fonts/json/yaml)
- unused declared dependencies/dev_dependencies
- potentially unsafe cleanup candidates (dynamic references, tooling-only package mentions)
It outputs Markdown (.md) or text (.txt) reports only and supports safe cleanup with backup + undo.
Features #
scanmode for read-only analysiscleanmode with dry-run by default- safe/unsafe buckets to avoid risky automatic deletions
- backup manifest and
undo - optional pre/post checks (
pub get,analyze,test)
Installation #
dart pub global activate flutter_janitor
Run as:
flutter_janitor scan
Commands #
Scan #
flutter_janitor scan \
--format md \
--output janitor_report.md \
--include test,integration_test,example \
--exclude build,.dart_tool,ios,android,macos,windows,linux,web \
--include-native-scan
Outputs groups:
- Unused assets (safe to remove)
- Potentially unused assets (unsafe)
- Unused dependencies (safe)
- Potentially unused dependencies (unsafe)
- Missing references (referenced but not declared)
- Summary + next actions
Clean #
Dry-run preview:
flutter_janitor clean
Apply safe cleanup:
flutter_janitor clean --apply --yes
Interactive apply:
flutter_janitor clean --apply --interactive
Apply with extra verification:
flutter_janitor clean --apply --yes --run-analyze --run-tests
Undo #
flutter_janitor clean --undo .janitor_backup/manifest_123456.yaml
Safety Model #
- Default is dry-run.
- Only safe buckets are auto-applied.
- Dynamic or prefix-based asset references are marked unsafe.
- Tooling/config-only dependency mentions are marked unsafe.
- Deleted assets are moved to backup (not hard-deleted).
pubspec.yamlis backed up before dependency removal.
Asset Detection #
Supports declared assets/fonts from pubspec.yaml:
- images:
svg,png,jpeg,jpg,webp - fonts: declared in
flutter/fonts+ font files - data/config:
json,yaml,yml(when declared underflutter/assets)
Dart usage patterns scanned:
AssetImage(...)Image.asset(...)SvgPicture.asset(...)Lottie.asset(...)(best effort)rootBundle.loadString/load(...)DefaultAssetBundle.of(context).loadString/load(...)- simple const propagation in file (
const a = 'assets/x.png'thenImage.asset(a))
Dependency Detection #
Uses Dart import/export package usage:
import 'package:xyz/...';export 'package:xyz/...';
Protected packages are never auto-removed:
flutterflutter_testcupertino_icons
Tooling/config references (for example in build.yaml) move dependencies to the unsafe bucket.
Limitations #
- Dynamic asset paths are intentionally conservative and can increase unsafe buckets.
- Dependency usage from external scripts/build systems may be ambiguous.
- Native scan (
--include-native-scan) is best-effort string matching.
Development #
dart pub get
dart format --set-exit-if-changed .
dart analyze
dart test
License #
MIT, see LICENSE.