dart_inspect 1.0.6 copy "dart_inspect: ^1.0.6" to clipboard
dart_inspect: ^1.0.6 copied to clipboard

Dart source inspection tool and CLI for reporting imports, classes, and fields using the analyzer AST, with Markdown and programmatic support.

dart_inspect #

pub package Null Safety GitHub Tag Last Commit License

dart_inspect is a Dart source analysis tool for discovering and reporting project structure.

It analyzes Dart code using the official analyzer AST to extract:

  • 📦 File imports
  • 🧩 Class declarations
  • 🏷 Instance fields and types

The tool can be used both as a CLI utility and as a programmatic inspection library, making it useful for:

  • architecture inspection
  • dependency auditing
  • documentation generation
  • CI validation
  • large codebase exploration
  • generating class diagrams and visual graphics (Mermaid)

Usage #

CLI #

Activate globally:

dart pub global activate dart_inspect

Run inspection on a directory or file:

dart_inspect <path> [options]

<path> can be a single Dart file or a directory containing Dart files.


Options #

  • --private-only – Include only private fields (_field).
  • --final-only – Include only final fields.
  • --no-final – Exclude final fields.
  • --no-primitives – Ignore primitive/common Dart types such as String, int, bool, etc.
  • --no-classes – Do not report class fields.
  • --no-empty-classes – Do not include empty classes.
  • --no-imports – Do not report imports.
  • --markdown – Output report in Markdown format.
  • --mermaid – Output report as a Mermaid class diagram.
  • --simple – Force simple output (default when no format is specified).
  • --sort-entries – Sort fields and classes alphabetically (default: false)
  • -h, --help – Show help message.

Format Notes #

Formats are mutually exclusive:

  • --simple (default)
  • --markdown
  • --mermaid

If none is specified, simple is used automatically.


Examples #

Inspect the current project:

dart_inspect .

Inspect a specific directory:

dart_inspect ../backend

Inspect a single Dart file:

dart_inspect lib/src/user.dart

Generate a Markdown architecture report:

dart_inspect lib --markdown

Generate a Mermaid class diagram:

dart_inspect lib --mermaid

Inspect only private state fields:

dart_inspect lib --private-only

Show only non-primitive domain fields:

dart_inspect lib --no-primitives

Example Output #

Simple Output

dart_inspect
────────────────────────────────────────────

Directory : lib
Format    : simple
Options   : (none)

================================================================================
lib/src/user.dart

Imports:
  dart:async

User
  int id
  String name
  Token _token

Markdown Output

# Dart Inspect Report

## Configuration

- Path: `lib`
- Format: markdown
- Options: (none)

---

## lib/src/user.dart

### Imports

- `dart:async`

### User

- int id
- String name
- Token _token

Mermaid Output

%% Dart Inspect - Mermaid Report
%% Path: lib
%% Options: (none)

classDiagram

  class User {
    int id
    String name
    Token token
  }

  class Token {
    String value
  }

  %% Relationships
  User --> Token

Programmatic Usage #

dart_inspect can be embedded directly into Dart tools and automation workflows.

import 'dart:io';
import 'package:dart_inspect/dart_inspect.dart';

Future<void> main() async {
  const options = DartInspectOptions(
    markdown: true,
    noPrimitives: true,
  );

  final inspector = DartInspect(options);

  final reporter = DartInspectReporterMarkdown('lib', options);

  final output = await reporter.build(
    inspector.scanDirectory(Directory('lib')),
  );

  print(output);
}

Streaming Raw Reports #

final inspect = DartInspect(
  const DartInspectOptions(),
);

await for (final report in inspect.scanCode(source)) {
  print(report);
}

Available Reporters #

  • DartInspectReporterSimple
  • DartInspectReporterMarkdown
  • DartInspectReporterMermaid

Each reporter:

  • consumes a Stream<ReportInfo>
  • produces a formatted String output

How It Works #

  1. Parses Dart files using the analyzer AST
  2. Collects import directives
  3. Detects class declarations
  4. Extracts instance fields and types
  5. Emits structured reports as a stream

This allows inspection of very large projects efficiently.


Issues & Feature Requests #

Please report issues or request features via the issue tracker.


Author #

Graciliano M. Passos: gmpassos@GitHub


License #

Dart free & open-source license.

1
likes
160
points
279
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dart source inspection tool and CLI for reporting imports, classes, and fields using the analyzer AST, with Markdown and programmatic support.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

analyzer, collection

More

Packages that depend on dart_inspect