dart_inspect 1.0.4 copy "dart_inspect: ^1.0.4" to clipboard
dart_inspect: ^1.0.4 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:

dart_inspect [directory] [options]

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-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 another directory:

dart_inspect ../backend

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

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

---

## lib/src/user.dart

### Imports

- `dart:async`

### User

- int id
- String name
- Token _token

Perfect for:

  • GitHub documentation
  • architecture reports
  • automated CI artifacts
  • AI input

Mermaid Output #

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

classDiagram

  class User {
    int id
    String name
    Token token
  }

  class Token {
    String value
  }

  %% Relationships
  User --> Token

Perfect for:

  • visual architecture diagrams
  • class relationship exploration
  • system design documentation

You can render this using:

  • https://mermaid.live
  • GitHub Markdown (with Mermaid enabled)
  • tools like Obsidian, Notion, or VS Code extensions

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
0
points
279
downloads

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

unknown (license)

Dependencies

analyzer, collection

More

Packages that depend on dart_inspect