Skip to main content

code_buster 0.7.2 copy "code_buster: ^0.7.2" to clipboard
code_buster: ^0.7.2 copied to clipboard

Deterministic offline repository architecture and multi-language static-analysis CLI.

example/code_buster_example.dart

import 'package:code_buster/code_buster.dart';

void main() {
  final RuleRegistry registry = RuleRegistry(<CodeBusterRule>[
    const TodoRule(),
  ]);
  final CodeBusterRule rule = registry['example-todo']!;
  final List<Finding> findings = rule
      .analyze(
        const RuleContext(
          config: AnalysisConfig(root: '.'),
          sources: <String, String>{'lib/example.dart': '// TODO: explain'},
          language: 'dart',
        ),
      )
      .toList(growable: false);
  for (final Finding finding in findings) {
    print('${finding.path}:${finding.line} ${finding.message}');
  }
}

final class TodoRule implements CodeBusterRule {
  const TodoRule();

  @override
  RuleMetadata get metadata => const RuleMetadata(
    id: 'example-todo',
    defaultSeverity: RuleSeverity.info,
    group: 'project',
    title: 'Document TODO ownership',
    why: 'Unowned TODO comments are difficult to prioritize.',
    suggestion: 'Add an owner and issue reference.',
  );

  @override
  Iterable<Finding> analyze(RuleContext context) sync* {
    for (final MapEntry<String, String> source in context.sources.entries) {
      final List<String> lines = source.value.split('\n');
      for (var index = 0; index < lines.length; index++) {
        if (!lines[index].contains('TODO')) continue;
        yield Finding(
          code: metadata.id,
          severity: metadata.defaultSeverity,
          path: source.key,
          line: index + 1,
          message: 'TODO has no tracked owner',
        );
      }
    }
  }
}
0
likes
0
points
746
downloads

Publisher

verified publishertoolbunker.dev

Weekly Downloads

Deterministic offline repository architecture and multi-language static-analysis CLI.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, args, crypto, path, toml

More

Packages that depend on code_buster