dart-decimate
v0.0.82
Published
Rust-native codebase intelligence for Dart and Flutter module graphs.
Readme
Dart Decimate

Find dead Dart code, circular dependencies, duplicated code, complex functions, dependency problems, risky Flutter wiring, and PR risk fast.
Dart Decimate is a Rust-native codebase intelligence tool for Dart and Flutter. It looks at your repo as a graph:
- Dart files are nodes.
import,export,part,part of, andlibrary augmentare edges.- The report tells you what is unused, risky, duplicated, tangled, or hard to maintain.
It is not a formatter. It is not a replacement for dart analyze. It is not a
Flutter style guide. It does not enforce opinions like "all providers must use
Riverpod code generation."
The parser accepts Dart 3.13 primary and concise constructors, dot shorthand,
and null-aware collection elements. Flutter UI detection includes the
standalone material_ui and cupertino_ui packages.
It answers practical questions:
- What code can probably be deleted?
- What files depend on each other in a circle?
- What functions are too complex?
- What code was copied around?
- What dependency is unused or missing from
pubspec.yaml? - What changed code is risky before a PR lands?
- What should an AI coding agent inspect before making a fix?
Start Here
Inside any Dart or Flutter project, run this:
pnpm dlx dart-decimate@latestThat checks the current project and prints a readable report covering dead code, circular dependencies, duplicated code, complex functions, dependency hygiene, architecture drift, Flutter graph issues, security candidates, and PR-risk signals. The duplication threshold defaults to zero, so any detected duplicate group fails the check.
To open the same report in your browser:
pnpm dlx dart-decimate@latest htmlTo review only files changed from another branch or ref:
pnpm dlx dart-decimate@latest html --compare origin/main--compare REF aliases --changed-since REF. If the ref is not found,
Dart Decimate suggests similar local or remote branches.
For JSON output that agents and CI can parse:
pnpm dlx dart-decimate@latest jsonIf the human report says FAIL, or JSON says "verdict": "fail", Dart Decimate
worked. It means a configured quality gate failed: an error-level issue, the
duplication threshold, or (with --strict) any visible finding. It does not
mean the tool crashed.
Exit codes:
0: the configured gates passed1: an error, any duplicated code at the default zero threshold, or any finding when--strictis enabled2: command, config, or runtime error8: security gate found new review-required candidates
Install
You do not need to install anything permanently. Use the command above.
For repeatable automation, pin the version:
pnpm dlx [email protected]Add this to package.json if you want a short project command:
{
"scripts": {
"dart-decimate": "dart-decimate json ."
},
"devDependencies": {
"dart-decimate": "0.0.82"
}
}Install with pnpm install, approve the package's required postinstall with pnpm approve-builds, and commit the resulting lockfile and build policy. The postinstall downloads the native release binaries or uses Cargo when a prebuilt binary is unavailable.
Then run:
pnpm run dart-decimateIf you prefer Cargo, install the matching tagged source:
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.82 --lockedThe npm release X.Y.Z and Cargo tag vX.Y.Z are verified against each other
before publication. Do not use an untagged cargo install --git command for a
reproducible gate because it follows the repository's moving default branch.
Confirm a Cargo build's version with:
dart-decimate --version
# dart-decimate 0.0.82pnpm dlx
The npm package name is dart-decimate. These commands do not require a global
install.
Check everything:
pnpm dlx dart-decimate@latestMachine-readable JSON:
pnpm dlx dart-decimate@latest jsonOpen the HTML report in your browser:
pnpm dlx dart-decimate@latest htmlThe html shortcut opens the report by default. On report commands, use
--format html to print static HTML or --open to write a private temporary
file and open it in the default browser.
Generated finding reports group issues by type in numbered, collapsible sections. Search narrows visible findings, and type filters open the selected group.
Human terminal reports strip control characters from user-derived paths and messages; HTML reports escape user-derived content.
Print the HTML report instead:
pnpm dlx dart-decimate@latest html --stdout > dart-decimate-report.htmlChanged files only: pnpm dlx dart-decimate@latest html --compare origin/main.
--compare REF aliases --changed-since REF and suggests similar branches when
the ref is not found.
What Dart Decimate Looks For
1. Dead Code
Dead code is code that is not reachable from your entry points.
Dart Decimate finds:
- dead Dart files
- unused public exports
- unused type aliases
- unused enum values
- unused private class members, and unused public members of classes in
lib/ - unrendered Flutter widgets
- missing entry points
- stale
dart-decimate-ignorecomments
Default entry points are evaluated across the root and discovered local package
roots. They include public lib/ Dart files outside lib/src/, lib/main.dart,
direct bin/ scripts, and, outside production mode, direct test/,
integration_test/, test_driver/, tool/, scripts/, and pigeon/
scripts. Nested test/, integration_test/, and test_driver/ files with
main() are also roots, including files matching Patrol's configured
test_file_suffix. Git-ignored Dart files are excluded from source analysis.
Generated Dart companions, Flutter l10n outputs, and FlutterFire options are
protected from dead-file cleanup; generated-only cycles are also suppressed.
Unused-symbol checks count references from non-raw Dart string interpolation; raw strings and escaped dollars stay literal.
Useful commands:
dart-decimate dead-code . --entry lib/main.dart --format json
dart-decimate check . --unused-files --unused-exports --unused-deps --format json2. Complex Code
Cyclomatic complexity means "how many paths can this function take?"
Cognitive complexity means "how hard is this function to understand?"
CRAP score combines complexity with test coverage. A complex function with poor
coverage gets a worse score. A score equal to max_crap is reported.
Dart Decimate finds:
- high cyclomatic complexity
- high cognitive complexity
- high combined complexity
- high CRAP score
- advisory large functions
- coverage gaps
- low health score files
- hotspots
- refactoring targets
- opt-in Flutter raw-style, near-duplicate theme-token, and unused
ThemeExtensionevidence
Flutter large-function classification uses the Flutter threshold for build
methods owned by StatelessWidget, AnimatedWidget, State, and
ConsumerState. Color matching follows the documented Color constructor
aliases, integer masking, and floating-component clamping.
Useful commands:
dart-decimate health . --format json
dart-decimate health . --complexity-breakdown --top 10 --format json
dart-decimate health . --file-scores --hotspots --targets --format json
dart-decimate health . --flutter-style --format json3. Duplicated Code
Duplication means the same Dart code appears in more than one place.
Dart Decimate finds exact and semantic clone groups. Each clone group gets a stable
fingerprint like dup:abc12345, so agents can trace it before touching code.
Clone windows must meet both line and token thresholds; sparse duplicated blocks
can span more than --min-lines, and line_count reports the actual match.
Bodyless contract declarations are excluded even when a clone window covers
only part of a signature or matches a concrete implementation. Matching concrete
implementations remain eligible for duplication checks. Copied local Pub package
mirrors are canonicalized before same-mirror matches are ignored.
A next-line code-duplication suppression on the reported group anchor removes
that group from findings, clone details, and duplication-threshold accounting.
--top limits displayed groups without reducing the remaining duplication total.
Pair-only class clones joined by an explicit toEntity() or toDomain() mapper
are treated as intentional boundaries by default. Set
dupes.ignore_mapper_pairs = false to report those pairs.
Useful commands:
dart-decimate dupes . --format json
dart-decimate dupes . --mode semantic --min-lines 5 --format json
dart-decimate dupes . --threshold 5 --format json
dart-decimate trace-clone . --fingerprint dup:abc12345 --format json4. Circular Dependencies
A circular dependency means file A depends on file B, and B eventually depends back on A. Cycles make code harder to move, test, and delete.
Dart Decimate finds:
- circular dependencies
- re-export cycles
- import/export/part/augment targets that do not resolve
- invalid
part/part ofrelationships
Canonical typed GoRouter route-registry back-edges are omitted when the importing file uses generated typed-route navigation helpers. Only those proven navigation back-edges are waived: unrelated edges, registry-to-registry imports, exports, and non-route registry API usage remain error-level cycle findings.
Useful commands:
dart-decimate cycles . --format json
dart-decimate check . --circular-deps --re-export-cycles --format json5. Architecture Drift
Architecture drift means code crosses boundaries it should not cross.
Example: lib/domain/ depending on lib/ui/.
Dart Decimate finds:
- boundary violations
- files outside configured boundary zones
- forbidden direct calls across boundaries
- policy-pack violations for banned imports, exports, and calls
Useful command:
dart-decimate check . \
--boundary lib/domain:lib/ui \
--boundary-coverage \
--format json6. Dependency Hygiene
Dependency hygiene means your imports and pubspec.yaml agree.
Dart Decimate finds:
- unused runtime dependencies
- unused dev dependencies
- dev dependencies imported by production-owned
lib/orbin/code - runtime dependencies used only by tests
- imports missing from
pubspec.yaml - unused dependency overrides
- invalid dependency overrides
- local packages that depend on each other, even with no file import cycle
- imports into another package's private
lib/src - duplicate public API exports
Dart Decimate follows Pub package ownership when resolving package: imports,
using .dart_tool/package_config.json when present while keeping same-package
imports and owner-local path dependencies local. Workspace members and copied
nested packages with the same package name are resolved by owner. Non-Dart
tooling references in Flutter config files, including launcher and splash
config, workflow files, Makefiles, and tool/ scripts can count as dependency
usage. Shell scripts anywhere in a package count a dependency they invoke with
dart run <pkg>, dart pub run <pkg>, or flutter pub run <pkg>. Envied annotations count envied_generator/build_runner, FlutterGen
configuration counts flutter_gen_runner, and Dart tests count the test
runner. Known generator-internal imports from generated Dart, such as
package:slang/generated.dart, are not reported as unlisted dependencies.
Useful commands:
dart-decimate trace-dependency . --dependency collection --format json
dart-decimate check . --unused-deps --unlisted-deps --private-src-imports --format json7. Flutter-Specific Graph Issues
Dart Decimate does not care which state-management style you use. It uses Flutter and Dart patterns only to avoid false positives and to find graph problems.
Dart Decimate finds:
- GoRouter route path/name collisions
- raw GoRouter definitions or destination APIs mixed into a typed-route project
- private Flutter widget classes
- top-level widget helper functions
- unused widget constructor parameters
- widget classes that are never constructed
- missing
context.mountedguards after awaited widget work
Typed consistency activates after production code declares an imported
TypedGoRoute/GoRouteData route. From then on, check and audit report raw
GoRoute declarations, resolved BuildContext/GoRouter destination calls,
and literal raw redirect destinations as errors. Generated route-object
navigation and .location redirects remain clean. Raw-only projects,
Navigator flows, pop, incoming deep links, tests, generated files, and
same-named user APIs are not classified as mixed routing. A deliberate
exception can use a reasoned line suppression such as
// dart-decimate-ignore-next-line mixed-go-router-style -- legacy URL migration.
unused-widget-param counts normal field reads, transformed constructor
initializer reads, inherited field reads, forwarding helpers, and Dart object
patterns that destructure the widget class itself. unrendered-widget counts
widgets constructed through builder callbacks and subclass construction, while
type-only references do not count as rendering.
8. Security Candidates
These are review prompts, not proof of an exploit.
Dart Decimate finds candidates for:
- hardcoded secrets
- insecure HTTP transport
- TLS validation bypasses
- risky WebView settings
- process execution
- raw SQL
- Firebase client API keys in
FirebaseOptions - plain local storage of secret-like material
- predictable
dart:math Random()output used by token-, secret-, nonce-, salt-, OTP-, session-, key-, password-, or auth-shaped declarations/calls
Firebase client API keys are warning-level by default because FlutterFire
generates client config. To make them fail a gate, set
"dart-decimate/security-firebase-api-key" = "error" in [rules]. Common
authentication copy is filtered unless bound to a secret-like name or concrete
token-like segment. OAuth endpoints are metadata only without userinfo
credentials or secret-like query/fragment data; cleartext transport remains a
candidate. Stripe secret-key names and sk_test_/sk_live_ values remain
candidates even as placeholders. Fixed dart:io process calls and typed
package:process command lists are excluded; dynamic elements or shell
execution remain candidates.
Remote Uri.http(...) and Uri(scheme: 'http', ...) construction is covered,
while documented local targets and debug/private-host-only branches are
excluded. TLS candidates require a callback that can accept an invalid
certificate; false-only callbacks are excluded and unresolved tear-offs become
blind spots. HttpOverrides.global or an empty SecurityContext alone is not a
bypass. Raw SQL analysis distinguishes literal dollar signs from interpolation
and retains unresolved runtime queries for review.
Random.secure() and confirmed secure factory flows are excluded. Imports from
a uniquely resolved Dart library owner apply to its parts; ambiguous process
provenance, process tear-offs, orphaned or multiply owned part-file calls, and
indirect Random factory flows are reported as redacted security_blind_spots
instead of being called clean. The embedded matcher
catalogue owns rule IDs, callee shapes, import provenance, CWE/effect metadata,
and evidence templates.
Useful commands:
dart-decimate security . --surface --format json
dart-decimate security . --ci --sarif-file dart-decimate-security.sarif
git diff --cached --unified=0 | dart-decimate security . --gate new --diff-stdin --format json
dart-decimate security . --gate newly-reachable --compare origin/main --format json--gate new keeps candidates on added lines. --gate newly-reachable keeps
reachable candidates affected by changed files. Both accept --compare REF,
--changed-since REF, --diff-file PATCH, or --diff-stdin.
9. PR Risk
Use this before merging changed code.
Dart Decimate reports:
- risk score
- pass / warn / fail risk level
- findings introduced by the PR
- findings that already existed
- risky changed files
Compile-time environment feature flags are warning-level only when every
occurrence is in a non-lib/ development, tooling, example, or test path, or in
lib/main_dev.dart, lib/main_debug.dart, lib/main_e2e.dart,
lib/main_test.dart, or lib/main_driver.dart. Other lib/ files, including
lib/dev_flags.dart, services, and screens, remain error-level. SDK/config flag
calls stay error-level by default.
Useful commands:
dart-decimate audit . --base origin/main --format json
dart-decimate audit . --base origin/main --gate new-only --format json10. Runtime Intelligence
Static analysis says what is connected. Runtime coverage says what actually ran.
Dart Decimate can read LCOV, V8, and Istanbul coverage data.
Useful commands:
dart-decimate health . --coverage coverage/lcov.info --coverage-gaps --max-crap 30 --format json
dart-decimate coverage analyze . --runtime-coverage coverage-final.json --format jsonHow To Read The Summary
Example:
{
"files": 466,
"edges": 1231,
"quality_score": 93,
"cycles": 2,
"code_duplications": 26,
"complex_functions": 13,
"dead_files": 11,
"findings": 125
}Plain English:
files: Dart files Dart Decimate parsededges: imports, exports, parts, and augments it resolvedquality_score: project health from0to100cycles: emitted circular dependency findings after policy classificationcode_duplications: duplicated code groupscomplex_functions: functions over the complexity limitsdead_files: files Dart Decimate thinks are unreachablefindings: total issues in the report
JSON For Agents
Use JSON when another tool or AI agent will read the result:
dart-decimate check . --format jsonEvery finding includes:
rule_idkindseveritypathlinecolumnsafe_to_delete- related
files - related dependency
edge, when available - suggested
actions
Example shape:
{
"schema_version": "dart-decimate.report.v1",
"kind": "combined",
"tool": "dart-decimate 0.0.82",
"command": "check",
"verdict": "fail",
"summary": {
"files": 466,
"edges": 1231,
"quality_score": 93,
"findings": 125
},
"findings": [],
"next_steps": []
}The dart-decimate.report.v1 field layout is unchanged. Its existing tool
string includes the producing version so saved reports identify the exact
build, for example dart-decimate 0.0.82.
When grouped security findings hide additional occurrences, next_steps can
include review-security-surface, which reruns
dart-decimate security . --format json --surface.
If a JSON command fails before a report can be built, stdout still stays machine-readable:
{ "error": true, "message": "coverage analyze requires --runtime-coverage PATH", "exit_code": 2 }Fixes
Preview safe fixes:
dart-decimate fix . --format jsonApply confirmed safe fixes:
dart-decimate fix . --apply --confirm --format jsonSafe fixes are intentionally conservative. Dart Decimate can currently apply:
- simple dead-file deletion
- stale suppression removal
- one-line unused Pub dependency removal
- one-line unused top-level Dart declaration removal
Everything else stays review-only.
Watch Mode
Rerun checks while you work:
dart-decimate watch . --no-clearRun once and exit, useful for scripts:
dart-decimate watch . --once --format jsonMCP
Start the MCP server:
dart-decimate-mcpAgents can use it to inspect a project, trace files, trace symbols, inspect duplicates, review PR risk, read runtime coverage slices, preview fixes, and ask what is safest to do next.
fix_apply is the only mutating MCP tool and requires explicit yes: true.
Config
See docs/configuration.md for config discovery, health/style settings, rule levels, security categories, and suppression examples.
Full Issue List
Run this for the live list:
dart-decimate schema --format json | jq .issue_typesCurrent issue types:
See docs/issue-types.md. Prefer the schema command when you need the installed binary's exact list.
CI
For a complete repository check, including discovered local packages:
pnpm dlx [email protected] --strictThis runs every enabled check from the repository root. The default duplication
threshold is zero, and --strict makes warnings fail too. Remove --strict if
CI should fail only for error-level findings or duplicated code.
Use json --strict instead when CI needs the dart-decimate.report.v1 JSON
report rather than the readable terminal report.
CI can use both the JSON verdict and the process exit code:
0: pass1: error-level findings, the duplication threshold failed, or--strictfound any warning2: invalid command, configuration, or runtime error8: new security candidates failed a security gate
See docs/ci.md for CI checks, PR gates, hook setup, CI templates, and review-thread reconciliation.
Scope
Dart Decimate implements local Fallow-style codebase intelligence for Dart and Flutter.
Fallow features that are JS-specific or require hosted backends return clear unsupported JSON instead of pretending to work:
dart-decimate migrate --dry-run --format json
dart-decimate telemetry status --format json
dart-decimate license status --format jsonDevelopment
See docs/ci.md for the local verification commands and CI gates.
This repository forbids unsafe_code.
Release Flow
Current source version: 0.0.82.
After the first public release, changes should go through pull requests. PRs to
main must bump both Cargo.toml and package.json above the base branch and to
an unpublished npm version. The sole exception is a canonical, committed Hard
Eng scaffold update verified by its native check. That verification keeps the
required Rust and npm check active while skipping unchanged release artifacts;
mixed product, configuration, or documentation changes take the normal path.
To release a new version:
- Update
Cargo.toml,package.json, and the pinned commands inREADME.mdanddocs/ci.mdto the same unpublished version. - Open a PR.
- Let CI pass.
- Merge to
main. - GitHub Actions validates the merged commit, builds every release asset, and compares a Cargo install from that exact commit with the npm tarball.
- Only after that parity check passes, GitHub Actions tags the verified commit
as
vX.Y.Z, creates or updates the GitHub release, and publishes[email protected].
Release reruns for the same commit may update GitHub release assets. If the npm package already exists for that commit, the publish step is skipped; a reused tag or npm version from another commit fails.
Local hooks block direct pushes to main, fetch the configured base ref when
needed, and run the same version, release, lint, Fallow, package, and test gates
defined in hard-eng.gates.json.
License
Licensed under the MIT License. See LICENSE.
