Skip to content
Configuration

Configuration

Use kareki-config.yaml at the workspace root to choose packages, retain code used by your tools, and suppress findings you intend to keep. The file and all settings are optional; start with defaults and add only the overrides you need. Check the list replacement rules before overriding a default list. For setup and command options, see the CLI reference . For how kareki decides whether code is used, see How it works .

Packages and entry points

KeyValueDefault / effect
packages.includePackage-directory globsAuto-detect from Melos / pub workspace settings, or use the root package, when omitted or empty. A nonempty list replaces auto-detection.
packages.excludePackage-directory globsAdds to Melos ignore when auto-detecting; otherwise none. Removes matching packages from discovery, including their references.
entry_points.filesFile globs**/*.story.dart, **/widgetbook/**/*.dart. Retains declarations in matching files.
entry_points.namesExact declaration namesNone. Retains matching declarations.

entry_points.files retains declarations in matching files within the scanned source scope ; it does not add source directories.

Dart / Flutter entry-point conventions remain active regardless of these settings: top-level main, main.dart / main_*.dart, flutter_test_config.dart, *_test.dart under test/, and files in bin/, integration_test/, or lib/l10n/.

For example, retain a framework callback that has no visible caller:

entry_points:
  names: [registerBackgroundHandler]

Suppression

Use suppression when a finding is intentional. File and package report exclusions still contribute references to other code.

KeyValueSuppresses
exclude.filesFile globsFindings in matching source or resource paths. See defaults below.
exclude.namesExact namesMatching declaration, localization-key, or resource findings.
exclude.parameter_namesExact namesOnly unused_parameter and unused_parameter_optional findings.
ignore.packagesPub package namesAll findings in those packages.
ignore.rulesRule IDsAll findings for those rules.
ignore.dependenciesPackage name → dependency-name listunused_pub_dependency findings for the listed dependencies in each package.
baselineFile path, relative to workspace rootPreviously recorded findings. See baseline options .

By default, exclude.files contains **/ globs for these filename patterns:

*.g.dart          *.freezed.dart   *.gr.dart         *.generated.dart
*.drift.dart      *.steps.dart     *.pb.dart         *.pbenum.dart
*.pbjson.dart     *.pbserver.dart  *.pbgrpc.dart     *.config.dart
l10n*.dart        *mocks.dart

Generated-file headers and configured Flutter gen-l10n outputs are also recognized automatically; see generated code .

For example, allow a retained parameter and a dependency used by a build script:

exclude:
  parameter_names: [context]
ignore:
  dependencies:
    my_app: [custom_build_support]

Inline comments

Use Dart comments for a local exception instead of a workspace-wide setting:

// kareki: ignore_for_file=unused_element,unused_file

// kareki: ignore=unused_element
class Dead {}

void foo({
  int? unused, // kareki: ignore=unused_parameter_optional
}) {}

ignore_for_file applies to the whole file. ignore applies to its own line when trailing code, or to the next non-blank, non-comment line when standalone. Comma-separated values can be rule IDs or, for ignore, symbol names. ARB files cannot use these comments; use the settings above for localization keys. Doctor finds suppressions that no longer match a finding.

Built-in presets

Presets retain annotated declarations used by generators and recognize the annotations’ implied dependencies. All presets below are enabled by default.

PresetKeep-alive annotationsImplies pub packages
freezed@freezed, @Freezed, @Default, @Assertfreezed_annotation, built_collection
json_serializable@JsonSerializable, @JsonKey, @JsonEnum, @JsonValuejson_annotation
riverpod@Riverpod, @riverpodriverpod_annotation
auto_route@AutoRouterConfig, @RoutePage, @AutoRoute, @CustomRoute, @MaterialRoute, @CupertinoRoute, @AdaptiveRoute—
go_router@TypedGoRoute, @TypedShellRoute, @TypedStatefulShellRoute, @TypedStatefulShellBranchgo_router
drift@DriftDatabase, @DriftAccessor, @UseRowClassdrift
hive@HiveType, @HiveFieldhive
meta (always on)@visibleForTesting, @visibleForOverriding, @protected, @internal, @immutable, @experimental, @mustCallSuper, @sealed, @factory, @useResult, @nonVirtual, @pragmameta
KeyValueDefault / effect
keep_alive_annotations.presetsPreset namesAll built-ins above. A nonempty list selects which to enable; meta stays active.
keep_alive_annotations.customAnnotation names without @None. Retains declarations with these annotations.
custom_presetsPreset name → definitionNone. Each definition is always active; matching a built-in name replaces that preset entirely.
annotation_implied_packagesAnnotation name → pub-package listNone. Adds dependency mappings to the active presets.

For example, select the generators used by your project and add an annotation:

keep_alive_annotations:
  presets: [freezed, json_serializable, riverpod]
  custom: [KeepAlive]

The freezed and drift presets also protect schema-generation inputs. Replacing either preset removes those protections; see schema generation inputs .

Defining or overriding a preset

custom_presets:
  my_internal_di:
    keep_alive_annotations: [Injectable, Singleton]
    annotation_implied_packages:
      Injectable: [my_di_package]
      Singleton: [my_di_package]

  # Replace the built-in preset for a framework fork.
  freezed:
    keep_alive_annotations: [freezed, Freezed]
    annotation_implied_packages:
      freezed: [freezed_annotation_v4]
      Freezed: [freezed_annotation_v4]

Unused localization keys

unused_l10n reads Flutter’s pubspec.yaml and l10n.yaml; it has no separate kareki configuration. Enable flutter.generate: true, generate the code, and resolve workspace dependencies before running dart run kareki --rule unused_l10n.

Flutter settingDefault
arb-dirlib/l10n
template-arb-fileapp_en.arb
output-dirThe ARB directory
output-localization-fileapp_localizations.dart
output-classAppLocalizations

Persist custom paths, template names, and class names in l10n.yaml so kareki can discover them. Generator command-line overrides alone are not discoverable. Flutter Intl / intl_utils, easy_localization, slang, legacy synthetic packages, and paths outside the package are unsupported.

Findings point to keys in the template ARB. Suppress them with exclude.names, ARB globs in exclude.files, ignore.rules, or a baseline. Exclusions do not skip input validation. See localization-key analysis for what counts as usage, warnings, and validation failures.

Flutter resources

unused_asset reads these settings from each package; no extra kareki settings are needed. Resolve dependencies and regenerate FlutterGen output before running.

InputFinding location
flutter.assetsPubspec registration, including directory entries.
flutter.fontsFont family in pubspec.
flutter_gen.colors.inputsColor definition in XML.

Use exclude.names with logical asset paths, font families, or XML color names. exclude.files accepts pubspec, asset, and color XML paths; rule ignores and baselines also apply. Exclusions do not skip input validation. See asset and color usage for how usage and warnings are determined.

SDK packages and output

KeyValueDefault / effect
sdk_packagesPub package namesflutter, flutter_test, flutter_driver, flutter_localizations, flutter_web_plugins, integration_test, sky_engine. Never reported as unused dependencies. Override for SDK forks.
output.formattext or jsontext. The CLI --format option takes precedence.

Replacing default lists

exclude.files and entry_points.files replace, rather than extend, their default lists. Include default patterns you still need; [] clears the list. For example, to keep the story convention but stop treating widgetbook files as entry points:

entry_points:
  files: ["**/*.story.dart"]

keep_alive_annotations.presets and sdk_packages also replace their defaults when nonempty, but [] uses the defaults. meta remains active even when omitted from the selected presets; override it through custom_presets.meta if needed.

Last updated on