scan library
Programmatic scan API for saropa_lints.
Use this when you want to run a scan from code (e.g. from another package or script) without invoking the CLI. The types and functions here are part of the public API and follow semver.
Example:
import 'package:saropa_lints/scan.dart';
void main() {
final runner = ScanRunner(
targetPath: '/path/to/project',
tier: 'recommended', // optional: override config with a tier
dartFiles: ['lib/main.dart'], // optional: scan only these files
messageSink: (msg) => log(msg), // optional: redirect/suppress output
);
final diagnostics = runner.run();
if (diagnostics != null) {
// process diagnostics or serialize with scanDiagnosticsToJson(diagnostics)
}
}
Classes
- ScanConfig
- Rule configuration loaded from a project's config files.
- ScanDiagnostic
- A single lint diagnostic found during scanning.
- ScanRunner
- Scans Dart files using saropa_lints rules without the plugin framework.
Functions
-
loadScanConfig(
String projectRoot) → ScanConfig? -
Attempts to load rule config from the project at
projectRoot. -
scanDiagnosticsToJson(
List< ScanDiagnostic> diagnostics) → Map<String, Object> -
Serializes
diagnosticsto the same JSON structure used bydart run saropa_lints scan --format json. -
scanDiagnosticsToJsonString(
List< ScanDiagnostic> diagnostics) → String -
Encodes
diagnosticsto a JSON string (pretty-printed).
Typedefs
- ScanMessageSink = void Function(String message)
- Optional sink for progress and error messages. When null, output goes to stdout (messages) and stderr (progress). When set, all output is sent to this callback so callers can suppress or redirect.