Add static type to sourceUrl arguments (#98)
Closes #97
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1cb12d6..5817dd0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,9 @@
-## 3.0.0-nullsafety
+## 3.0.0-nullsafety.0
+
* Updated to support 2.12.0 and null safety.
* Allow `YamlNode`s to be wrapped with an optional `style` parameter.
+* **BREAKING** The `sourceUrl` named argument is statically typed as `Uri`
+ instead of allowing `String` or `Uri`.
## 2.2.1
diff --git a/lib/src/loader.dart b/lib/src/loader.dart
index c60e673..7333227 100644
--- a/lib/src/loader.dart
+++ b/lib/src/loader.dart
@@ -30,9 +30,7 @@
FileSpan _span;
/// Creates a loader that loads [source].
- ///
- /// [sourceUrl] can be a String or a [Uri].
- factory Loader(String source, {sourceUrl}) {
+ factory Loader(String source, {Uri? sourceUrl}) {
var parser = Parser(source, sourceUrl: sourceUrl);
var event = parser.parse();
assert(event.type == EventType.streamStart);
diff --git a/lib/src/parser.dart b/lib/src/parser.dart
index 625abe6..3443e2e 100644
--- a/lib/src/parser.dart
+++ b/lib/src/parser.dart
@@ -35,9 +35,7 @@
bool get isDone => _state == _State.END;
/// Creates a parser that parses [source].
- ///
- /// [sourceUrl] can be a String or a [Uri].
- Parser(String source, {sourceUrl})
+ Parser(String source, {Uri? sourceUrl})
: _scanner = Scanner(source, sourceUrl: sourceUrl);
/// Consumes and returns the next event.
diff --git a/lib/src/scanner.dart b/lib/src/scanner.dart
index 942e578..a9f64be 100644
--- a/lib/src/scanner.dart
+++ b/lib/src/scanner.dart
@@ -288,9 +288,7 @@
}
/// Creates a scanner that scans [source].
- ///
- /// [sourceUrl] can be a String or a [Uri].
- Scanner(String source, {sourceUrl})
+ Scanner(String source, {Uri? sourceUrl})
: _scanner = SpanScanner.eager(source, sourceUrl: sourceUrl);
/// Consumes and returns the next token.
diff --git a/lib/yaml.dart b/lib/yaml.dart
index 2ef65e7..f80489a 100644
--- a/lib/yaml.dart
+++ b/lib/yaml.dart
@@ -29,8 +29,8 @@
/// operation.
///
/// If [sourceUrl] is passed, it's used as the URL from which the YAML
-/// originated for error reporting. It can be a [String], a [Uri], or `null`.
-dynamic loadYaml(String yaml, {sourceUrl}) =>
+/// originated for error reporting.
+dynamic loadYaml(String yaml, {Uri? sourceUrl}) =>
loadYamlNode(yaml, sourceUrl: sourceUrl).value;
/// Loads a single document from a YAML string as a [YamlNode].
@@ -38,7 +38,7 @@
/// This is just like [loadYaml], except that where [loadYaml] would return a
/// normal Dart value this returns a [YamlNode] instead. This allows the caller
/// to be confident that the return value will always be a [YamlNode].
-YamlNode loadYamlNode(String yaml, {sourceUrl}) =>
+YamlNode loadYamlNode(String yaml, {Uri? sourceUrl}) =>
loadYamlDocument(yaml, sourceUrl: sourceUrl).contents;
/// Loads a single document from a YAML string as a [YamlDocument].
@@ -46,7 +46,7 @@
/// This is just like [loadYaml], except that where [loadYaml] would return a
/// normal Dart value this returns a [YamlDocument] instead. This allows the
/// caller to access document metadata.
-YamlDocument loadYamlDocument(String yaml, {sourceUrl}) {
+YamlDocument loadYamlDocument(String yaml, {Uri? sourceUrl}) {
var loader = Loader(yaml, sourceUrl: sourceUrl);
var document = loader.load();
if (document == null) {
@@ -74,8 +74,8 @@
/// operation.
///
/// If [sourceUrl] is passed, it's used as the URL from which the YAML
-/// originated for error reporting. It can be a [String], a [Uri], or `null`.
-YamlList loadYamlStream(String yaml, {sourceUrl}) {
+/// originated for error reporting.
+YamlList loadYamlStream(String yaml, {Uri? sourceUrl}) {
var loader = Loader(yaml, sourceUrl: sourceUrl);
var documents = <YamlDocument>[];
@@ -97,7 +97,7 @@
///
/// This is like [loadYamlStream], except that it returns [YamlDocument]s with
/// metadata wrapping the document contents.
-List<YamlDocument> loadYamlDocuments(String yaml, {sourceUrl}) {
+List<YamlDocument> loadYamlDocuments(String yaml, {Uri? sourceUrl}) {
var loader = Loader(yaml, sourceUrl: sourceUrl);
var documents = <YamlDocument>[];
diff --git a/pubspec.yaml b/pubspec.yaml
index 10d1004..4117657 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -18,8 +18,13 @@
pedantic: ^1.10.0-nullsafety
test: ^1.16.0-nullsafety
+ # Temporary deps to allow overrides
+ test_core: any
+ test_api: any
+ analyzer: any
+
dependency_overrides:
- analyzer: ^0.40.0
+ analyzer: ^0.41.0
test: ^1.16.0-nullsafety
test_api: ^0.2.19-nullsafety
test_core: ^0.3.12-nullsafety