Skip to main content

kareki 0.10.1 copy "kareki: ^0.10.1" to clipboard
kareki: ^0.10.1 copied to clipboard

A multi-package dead code detector for Dart and Flutter monorepos. Finds unused public APIs, files, and pub dependencies across Melos / pub workspaces.

example/example.md

kareki example #

This directory is a real, runnable Dart package. Every file under lib/ is wired so that running kareki produces exactly one finding per rule — eight in total. Use it to see what each rule actually catches.

The localization example uses a minimal Dart-only fixture with the same API shape as Flutter gen-l10n, so this example does not require the Flutter SDK. The test suite separately exercises actual Flutter-generated code.

Layout #

example/
├── pubspec.yaml         # declares `collection` but never imports it → unused_pub_dependency
├── kareki-config.yaml   # minimum config kareki picks up by default
├── assets/unused.json  # registered asset without a consumer → unused_asset
├── bin/main.dart        # entry point — keeps everything else reachable
├── lib/
│   ├── api.dart         # public enum value no one uses → unused_element
│   ├── parameters.dart  # body-unused arg → unused_parameter
│   │                    # never-passed optional → unused_parameter_optional
│   ├── test_only.dart   # only test/ references it → test_only_used
│   ├── l10n/app_en.arb  # unused translation key → unused_l10n
│   └── orphan.dart      # never imported → unused_file
├── test/api_test.dart   # references test_only.dart (test-side only)
└── example.dart         # programmatic API demo (run from this dir)

Run kareki on this example #

From the repo root:

$ dart run kareki --root example
• Package: kareki_example
  [test_only_used] lib/test_only.dart:3:8
    Public function 'testOnlyHelper' is only referenced from test code.
  [unused_element] lib/api.dart:12:23
    Unused public enum value 'Status.inactive'.
  [unused_file] lib/orphan.dart:1:1
    File is never imported, parted, or exported.
  [unused_asset] pubspec.yaml:29:7
    Unused asset 'assets/unused.json'.
  [unused_l10n] lib/l10n/app_en.arb:4:3
    Unused localization key 'unusedGreeting' (ExampleLocalizations).
  [unused_parameter] lib/parameters.dart:10:26
    Parameter 'unusedTwo' of 'Service.doWork' is never used.
  [unused_parameter_optional] lib/parameters.dart:3:49
    Optional parameter 'port' of 'buildUrl' is never passed at any call site.
  [unused_pub_dependency] pubspec.yaml:1:1
    Dependency 'collection' is declared in pubspec.yaml but never imported within 'kareki_example'.

kareki: 8 finding(s) across 1 package(s).

Rule-by-rule walkthrough #

Rule Where it's planted Why it fires
unused_asset assets/unused.json Registered in pubspec but never referenced by Dart source.
unused_element lib/api.dart — Status.inactive bin/main.dart references Status.active, but nobody references Status.inactive.
unused_l10n lib/l10n/app_en.arb — unusedGreeting The Dart-only gen-l10n fixture exposes two keys; only greeting is referenced.
unused_file lib/orphan.dart The file is never imported, parted, or exported from anywhere in the package. (Its private _OrphanWidget declaration suppresses unused_element so this example demonstrates each rule exactly once.)
unused_pub_dependency pubspec.yaml — collection Declared under dependencies: but no source file imports package:collection/.... meta, which lib/api.dart does import, is not flagged.
test_only_used lib/test_only.dart — testOnlyHelper Defined in lib/ (production source) but the only reference comes from test/api_test.dart. Production reachability is empty.
unused_parameter lib/parameters.dart — Service.doWork(int a, int unusedTwo) unusedTwo is never referenced in the method body.
unused_parameter_optional lib/parameters.dart — buildUrl({String host, int port}) port has a default value but no call site in the workspace ever passes it.

Filter to one rule at a time #

$ dart run kareki --root example --rule unused_pub_dependency
$ dart run kareki --root example --rule unused_parameter --rule unused_parameter_optional

JSON output for CI #

$ dart run kareki --root example --format json | jq '.findings | length'
7

Programmatic API #

example.dart runs the same analysis through the public Dart API. From inside this directory:

$ dart pub get
$ dart run example.dart
import 'package:kareki/kareki.dart';

Future<void> main() async {
  const root = '.';
  final config = KarekiConfig.load(root);
  final result = await KarekiRunner().run(
    RunRequest(rootPath: root, config: config),
  );
  print(TextReporter().render(result.findings, rootPath: root));
}

KarekiRunner.run and analyze return Futures, as do DoctorRunner.run, DoctorRunner.analyze, runCli, and runDoctor. Await them from an async caller. Analysis warnings are available separately in result.analysisWarnings.

The preview APIs runCliAsync / runDoctorAsync, AnalysisMode and its arguments, and legacy name-reference metadata on ParsedFile, DeclarationRecord, and EntryPointSet have been removed. These API changes do not change the dart run kareki command.

Configuration #

See kareki-config.yaml for the minimum config this example uses, and doc/configuration.md for the full schema (presets, custom annotations, ignore lists, baseline, etc.).

4
likes
60
points
3.22k
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

A multi-package dead code detector for Dart and Flutter monorepos. Finds unused public APIs, files, and pub dependencies across Melos / pub workspaces.

Repository (GitHub)
View/report issues

Topics

#dead-code #linter #monorepo #melos #cli

License

MIT (license)

Dependencies

analyzer, args, crypto, glob, path, pool, pub_semver, xml, yaml

More

Packages that depend on kareki