source_span
1.10.2, released 9 months ago by tools.dart.dev
Standard representation for source code locations, spans, and human-friendly error messages.
What it does
Provides classes like SourceSpan and SourceFile to track positions in source code files. It allows packages to easily pass code locations around and generate clear, human-friendly error messages with line and column highlights.
AI-written summary of version 1.10.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing a parser, compiler, linter, or code generator that needs to report source code errors.
- You want to standardize source location tracking across multiple custom packages.
Skip it when
- You are building a standard mobile application UI without any code parsing requirements.
Strengths
- Generates clean, human-friendly error messages with file context and line numbers.
- Efficient means of computing line and column numbers using SourceFile.
- Supports multi-span highlights and Unicode box-drawing characters.
Weaknesses
- Very niche utility package with no application outside of parsing and tooling.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
import 'package:source_span/source_span.dart';
void main() {
var file = SourceFile.fromString('some code here', url: 'main.dart');
var span = file.span(0, 4);
print(span.message('Here is an error'));
}Alternatives
Packages that do the same job and could replace source_span.
- io
Utilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
88Compare - hotreloader
Automatic hot code reloader for Dart projects that applies file changes to the running process.
70Compare - flutter_patcher
Self-hosted OTA hotfix tool for Flutter with signed code and asset patches.
65Compare - qris
Parses Indonesian QRIS codes into merchant and transaction data.
41Compare
Works with
Packages commonly used together with source_span: ones it builds on, ones built on it, and its own family.
- term_glyphsource_span depends on itProvides useful Unicode glyphs and plain ASCII alternatives for command-line applications.
- source_map_stack_traceSame familyConverts dart2js-compiled JavaScript stack traces into readable native Dart stack traces.
- test_descriptorSame familyDeclarative API for creating and verifying file and directory structures in tests.
- analyzerBuilt on source_spanPerforms static analysis of Dart code for tool integration and embedding.
- yamlBuilt on source_spanA Dart library for parsing YAML documents into Dart data structures.
- dart_styleBuilt on source_spanProvides an API and CLI to format Dart source code automatically.
- test_apiBuilt on source_spanThe user facing API for structuring Dart tests and checking expectations.
- testBuilt on source_spanA full featured library for writing and running Dart tests across platforms.