dart_inspect 1.0.0
dart_inspect: ^1.0.0 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 #
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
Usage #
CLI #
Activate globally:
dart pub global activate dart_inspect
Run inspection:
dart_inspect [directory] [options]
Options #
-
--private-onlyInclude only private fields (_field). -
--final-onlyInclude onlyfinalfields. -
--no-finalExcludefinalfields. -
--no-primitivesIgnore primitive/common Dart types such asString,int,bool, etc. -
--no-classesDo not report class fields. -
--no-importsDo not report imports. -
--markdownOutput report in Markdown format. -
-h,--helpShow help message.
Examples #
Inspect the current project:
dart_inspect
Inspect another directory:
dart_inspect ../backend
Generate a Markdown architecture report:
dart_inspect lib --markdown
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 #
lib/src/user.dart
User
int id
String name
Token _token
Markdown Output #
## lib/src/user.dart
### Imports
- `dart:async`
- `package:http/http.dart`
### User
- int id
- String name
- Token _token
Perfect for:
- GitHub documentation
- architecture reports
- automated CI artifacts
- AI input
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);
await for (final report
in inspector.scanDirectory(Directory('lib'))) {
print(report.toMarkdown());
}
}
You can also analyze raw source code:
final inspect = DartInspect(
const DartInspectOptions(),
);
await for (final report in inspect.scanCode(source)) {
print(report);
}
How It Works #
- Parses Dart files using the analyzer AST
- Collects import directives
- Detects class declarations
- Extracts instance fields and types
- 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.