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

example/dart_inspect_example.dart

import 'dart:io';

import 'package:dart_inspect/dart_inspect.dart';

Future<void> main(List<String> args) async {
  // Directory to inspect.
  final directory = args.isEmpty ? Directory.current : Directory(args.first);

  if (!await directory.exists()) {
    stderr.writeln('** Directory not found: ${directory.path}');
    exit(1);
  }

  // Configure inspection behavior.
  const options = DartInspectOptions(
    markdown: true,
    noPrimitives: false,
    privateOnly: false,
  );

  final inspector = DartInspect(options);

  stdout.writeln('# Dart Inspect Example');
  stdout.writeln();
  stdout.writeln('Directory: ${directory.path}');
  stdout.writeln();

  if (options.options.isNotEmpty) {
    stdout.writeln('Options:');
    for (final opt in options.options) {
      stdout.writeln('  $opt');
    }
    stdout.writeln();
  }

  String? lastFile;

  await for (final report in inspector.scanDirectory(directory)) {
    final filePath = report.filePath;

    // Print file section only when it changes.
    if (filePath != null && filePath != lastFile) {
      lastFile = filePath;

      if (options.markdown) {
        stdout.writeln('---');
        stdout.writeln();
        stdout.writeln('## $filePath');
        stdout.writeln();
      } else {
        stdout.writeln('\n==================================================');
        stdout.writeln(filePath);
        stdout.writeln('==================================================');
      }
    }

    if (options.markdown) {
      stdout.writeln(report.toMarkdown(withFilePath: false));
    } else {
      stdout.writeln(report.toString(withFilePath: false));
    }
  }
}
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

More

Packages that depend on dart_inspect