tighten up analysis; add types at the api boundaries (dart-lang/source_maps#73)

diff --git a/pkgs/source_maps/CHANGELOG.md b/pkgs/source_maps/CHANGELOG.md
index 3665019..e29a375 100644
--- a/pkgs/source_maps/CHANGELOG.md
+++ b/pkgs/source_maps/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 0.10.12
+
+* Add additional types at API boundaries.
+
 # 0.10.11
 
 * Populate the pubspec `repository` field.
diff --git a/pkgs/source_maps/README.md b/pkgs/source_maps/README.md
index e81f278..ad8fd25 100644
--- a/pkgs/source_maps/README.md
+++ b/pkgs/source_maps/README.md
@@ -2,8 +2,11 @@
 [![pub package](https://img.shields.io/pub/v/source_maps.svg)](https://pub.dev/packages/source_maps)
 [![package publisher](https://img.shields.io/pub/publisher/source_maps.svg)](https://pub.dev/packages/source_maps/publisher)
 
-This project implements a Dart pub package to work with source maps. The
-implementation is based on the [source map version 3 spec][spec] which was
+This project implements a Dart pub package to work with source maps.
+
+## Docs and usage
+
+The implementation is based on the [source map version 3 spec][spec] which was
 originated from the [Closure Compiler][closure] and has been implemented in
 Chrome and Firefox.
 
@@ -18,13 +21,5 @@
   * A parser that reads the source map format and provides APIs to read the
     mapping information.
 
-Some upcoming features we are planning to add to this package are:
-
-  * A printer that lets you generate code, but record source map information in
-    the process.
-  * A tool that can compose source maps together. This would be useful for
-    instance, if you have 2 tools that produce source maps and you call one with
-    the result of the other.
-
 [closure]: https://github.com/google/closure-compiler/wiki/Source-Maps
 [spec]: https://docs.google.com/a/google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
diff --git a/pkgs/source_maps/analysis_options.yaml b/pkgs/source_maps/analysis_options.yaml
index c09985a..d978f81 100644
--- a/pkgs/source_maps/analysis_options.yaml
+++ b/pkgs/source_maps/analysis_options.yaml
@@ -1,5 +1 @@
-include: package:lints/recommended.yaml
-
-linter:
-  rules:
-    - comment_references
+include: package:dart_flutter_team_lints/analysis_options.yaml
diff --git a/pkgs/source_maps/lib/builder.dart b/pkgs/source_maps/lib/builder.dart
index 5c56ca4..54ba743 100644
--- a/pkgs/source_maps/lib/builder.dart
+++ b/pkgs/source_maps/lib/builder.dart
@@ -45,7 +45,7 @@
   }
 
   /// Encodes all mappings added to this builder as a json map.
-  Map build(String fileUrl) {
+  Map<String, dynamic> build(String fileUrl) {
     return SingleMapping.fromEntries(_entries, fileUrl).toJson();
   }
 
diff --git a/pkgs/source_maps/lib/parser.dart b/pkgs/source_maps/lib/parser.dart
index e3c7179..701a63f 100644
--- a/pkgs/source_maps/lib/parser.dart
+++ b/pkgs/source_maps/lib/parser.dart
@@ -25,7 +25,7 @@
 // `)]}'` begins the string representation of the map.
 Mapping parse(String jsonMap,
         {Map<String, Map>? otherMaps, /*String|Uri*/ Object? mapUrl}) =>
-    parseJson(jsonDecode(jsonMap), otherMaps: otherMaps, mapUrl: mapUrl);
+    parseJson(jsonDecode(jsonMap) as Map, otherMaps: otherMaps, mapUrl: mapUrl);
 
 /// Parses a source map or source map bundle directly from a json string.
 ///
@@ -50,7 +50,7 @@
   return parseJson(json as Map);
 }
 
-/// Parses a source map
+/// Parses a source map.
 ///
 /// [mapUrl], which may be either a [String] or a [Uri], indicates the URL of
 /// the source map file itself. If it's passed, any URLs in the source
@@ -69,10 +69,10 @@
       throw FormatException('map containing "sections" '
           'cannot contain "mappings", "sources", or "names".');
     }
-    return MultiSectionMapping.fromJson(map['sections'], otherMaps,
+    return MultiSectionMapping.fromJson(map['sections'] as List, otherMaps,
         mapUrl: mapUrl);
   }
-  return SingleMapping.fromJson(map, mapUrl: mapUrl);
+  return SingleMapping.fromJson(map.cast<String, dynamic>(), mapUrl: mapUrl);
 }
 
 /// A mapping parsed out of a source map.
@@ -108,21 +108,21 @@
   /// Creates a section mapping from json.
   MultiSectionMapping.fromJson(List sections, Map<String, Map>? otherMaps,
       {/*String|Uri*/ Object? mapUrl}) {
-    for (var section in sections) {
-      var offset = section['offset'];
+    for (var section in sections.cast<Map>()) {
+      var offset = section['offset'] as Map?;
       if (offset == null) throw FormatException('section missing offset');
 
-      var line = section['offset']['line'];
+      var line = offset['line'] as int?;
       if (line == null) throw FormatException('offset missing line');
 
-      var column = section['offset']['column'];
+      var column = offset['column'] as int?;
       if (column == null) throw FormatException('offset missing column');
 
       _lineStart.add(line);
       _columnStart.add(column);
 
-      var url = section['url'];
-      var map = section['map'];
+      var url = section['url'] as String?;
+      var map = section['map'] as Map?;
 
       if (url != null && map != null) {
         throw FormatException("section can't use both url and map entries");
@@ -189,7 +189,7 @@
 
   MappingBundle.fromJson(List json, {/*String|Uri*/ Object? mapUrl}) {
     for (var map in json) {
-      addMapping(parseJson(map, mapUrl: mapUrl) as SingleMapping);
+      addMapping(parseJson(map as Map, mapUrl: mapUrl) as SingleMapping);
     }
   }
 
@@ -342,18 +342,18 @@
         urls.keys.toList(), names.keys.toList(), lines);
   }
 
-  SingleMapping.fromJson(Map map, {mapUrl})
-      : targetUrl = map['file'],
-        urls = List<String>.from(map['sources']),
-        names = List<String>.from(map['names'] ?? []),
-        files = List.filled(map['sources'].length, null),
-        sourceRoot = map['sourceRoot'],
+  SingleMapping.fromJson(Map<String, dynamic> map, {mapUrl})
+      : targetUrl = map['file'] as String?,
+        urls = List<String>.from(map['sources'] as List),
+        names = List<String>.from((map['names'] as List?) ?? []),
+        files = List.filled((map['sources'] as List).length, null),
+        sourceRoot = map['sourceRoot'] as String?,
         lines = <TargetLineEntry>[],
-        _mapUrl = mapUrl is String ? Uri.parse(mapUrl) : mapUrl,
+        _mapUrl = mapUrl is String ? Uri.parse(mapUrl) : (mapUrl as Uri?),
         extensions = {} {
     var sourcesContent = map['sourcesContent'] == null
         ? const <String?>[]
-        : List<String?>.from(map['sourcesContent']);
+        : List<String?>.from(map['sourcesContent'] as List);
     for (var i = 0; i < urls.length && i < sourcesContent.length; i++) {
       var source = sourcesContent[i];
       if (source == null) continue;
@@ -366,7 +366,7 @@
     var srcLine = 0;
     var srcColumn = 0;
     var srcNameId = 0;
-    var tokenizer = _MappingTokenizer(map['mappings']);
+    var tokenizer = _MappingTokenizer(map['mappings'] as String);
     var entries = <TargetEntry>[];
 
     while (tokenizer.hasTokens) {
@@ -432,7 +432,7 @@
   ///
   /// If [includeSourceContents] is `true`, this includes the source file
   /// contents from [files] in the map if possible.
-  Map toJson({bool includeSourceContents = false}) {
+  Map<String, dynamic> toJson({bool includeSourceContents = false}) {
     var buff = StringBuffer();
     var line = 0;
     var column = 0;
@@ -471,12 +471,12 @@
       }
     }
 
-    var result = {
+    var result = <String, dynamic>{
       'version': 3,
       'sourceRoot': sourceRoot ?? '',
       'sources': urls,
       'names': names,
-      'mappings': buff.toString()
+      'mappings': buff.toString(),
     };
     if (targetUrl != null) result['file'] = targetUrl!;
 
@@ -690,6 +690,8 @@
     buff.write('');
     try {
       buff.write(current);
+      // TODO: Determine whether this try / catch can be removed.
+      // ignore: avoid_catching_errors
     } on RangeError catch (_) {}
     buff.write('');
     for (var i = index + 1; i < _internal.length; i++) {
diff --git a/pkgs/source_maps/lib/printer.dart b/pkgs/source_maps/lib/printer.dart
index 7d128f7..17733cd 100644
--- a/pkgs/source_maps/lib/printer.dart
+++ b/pkgs/source_maps/lib/printer.dart
@@ -36,7 +36,7 @@
   /// adds a source map location on each new line, projecting that every new
   /// line in the target file (printed here) corresponds to a new line in the
   /// source file.
-  void add(String str, {projectMarks = false}) {
+  void add(String str, {bool projectMarks = false}) {
     var chars = str.runes.toList();
     var length = chars.length;
     for (var i = 0; i < length; i++) {
@@ -85,7 +85,7 @@
   /// [SourceSpan]. When the mark is a [SourceMapSpan] with `isIdentifier` set,
   /// this also records the name of the identifier in the source map
   /// information.
-  void mark(mark) {
+  void mark(Object mark) {
     late final SourceLocation loc;
     String? identifier;
     if (mark is SourceLocation) {
@@ -105,13 +105,13 @@
 /// including [NestedPrinter]s, and it let's you automatically indent text.
 ///
 /// This class is especially useful when doing code generation, where different
-/// peices of the code are generated independently on separate printers, and are
+/// pieces of the code are generated independently on separate printers, and are
 /// finally put together in the end.
 class NestedPrinter implements NestedItem {
   /// Items recoded by this printer, which can be [String] literals,
   /// [NestedItem]s, and source map information like [SourceLocation] and
   /// [SourceSpan].
-  final _items = <dynamic>[];
+  final List<Object> _items = [];
 
   /// Internal buffer to merge consecutive strings added to this printer.
   StringBuffer? _buff;
@@ -149,7 +149,7 @@
   /// Indicate [isOriginal] when [object] is copied directly from the user code.
   /// Setting [isOriginal] will make this printer propagate source map locations
   /// on every line-break.
-  void add(object,
+  void add(Object object,
       {SourceLocation? location, SourceSpan? span, bool isOriginal = false}) {
     if (object is! String || location != null || span != null || isOriginal) {
       _flush();
diff --git a/pkgs/source_maps/lib/refactor.dart b/pkgs/source_maps/lib/refactor.dart
index 97bd2a7..98e0c93 100644
--- a/pkgs/source_maps/lib/refactor.dart
+++ b/pkgs/source_maps/lib/refactor.dart
@@ -30,7 +30,7 @@
   /// Edit the original text, replacing text on the range [begin] and [end]
   /// with the [replacement]. [replacement] can be either a string or a
   /// [NestedPrinter].
-  void edit(int begin, int end, replacement) {
+  void edit(int begin, int end, Object replacement) {
     _edits.add(_TextEdit(begin, end, replacement));
   }
 
diff --git a/pkgs/source_maps/lib/source_maps.dart b/pkgs/source_maps/lib/source_maps.dart
index 0c6cc08..58f805a 100644
--- a/pkgs/source_maps/lib/source_maps.dart
+++ b/pkgs/source_maps/lib/source_maps.dart
@@ -28,8 +28,8 @@
 
 import 'package:source_span/source_span.dart';
 
-import 'parser.dart';
 import 'builder.dart';
+import 'parser.dart';
 
 export 'builder.dart';
 export 'parser.dart';
diff --git a/pkgs/source_maps/lib/src/source_map_span.dart b/pkgs/source_maps/lib/src/source_map_span.dart
index 65574ca..2840db4 100644
--- a/pkgs/source_maps/lib/src/source_map_span.dart
+++ b/pkgs/source_maps/lib/src/source_map_span.dart
@@ -61,13 +61,13 @@
   @override
   int compareTo(SourceSpan other) => _inner.compareTo(other);
   @override
-  String highlight({color}) => _inner.highlight(color: color);
+  String highlight({Object? color}) => _inner.highlight(color: color);
   @override
   SourceSpan union(SourceSpan other) => _inner.union(other);
   @override
   FileSpan expand(FileSpan other) => _inner.expand(other);
   @override
-  String message(String message, {color}) =>
+  String message(String message, {Object? color}) =>
       _inner.message(message, color: color);
   @override
   String toString() =>
diff --git a/pkgs/source_maps/lib/src/utils.dart b/pkgs/source_maps/lib/src/utils.dart
index eb23834..f70531e 100644
--- a/pkgs/source_maps/lib/src/utils.dart
+++ b/pkgs/source_maps/lib/src/utils.dart
@@ -10,7 +10,7 @@
 /// and all items after `n` match too. The result is -1 when there are no
 /// items, 0 when all items match, and list.length when none does.
 // TODO(sigmund): remove this function after dartbug.com/5624 is fixed.
-int binarySearch(List list, bool Function(dynamic) matches) {
+int binarySearch<T>(List<T> list, bool Function(T) matches) {
   if (list.isEmpty) return -1;
   if (matches(list.first)) return 0;
   if (!matches(list.last)) return list.length;
diff --git a/pkgs/source_maps/lib/src/vlq.dart b/pkgs/source_maps/lib/src/vlq.dart
index 6c41b6e..61b4768 100644
--- a/pkgs/source_maps/lib/src/vlq.dart
+++ b/pkgs/source_maps/lib/src/vlq.dart
@@ -76,7 +76,7 @@
     }
     stop = (digit & vlqContinuationBit) == 0;
     digit &= vlqBaseMask;
-    result += (digit << shift);
+    result += digit << shift;
     shift += vlqBaseShift;
   }
 
diff --git a/pkgs/source_maps/pubspec.yaml b/pkgs/source_maps/pubspec.yaml
index eaaa46c..f716ef6 100644
--- a/pkgs/source_maps/pubspec.yaml
+++ b/pkgs/source_maps/pubspec.yaml
@@ -1,5 +1,5 @@
 name: source_maps
-version: 0.10.11
+version: 0.10.12
 description: A library to programmatically manipulate source map files.
 repository: https://github.com/dart-lang/source_maps
 
@@ -10,6 +10,6 @@
   source_span: ^1.8.0
 
 dev_dependencies:
-  lints: ^2.0.0
+  dart_flutter_team_lints: ^0.1.0
   term_glyph: ^1.2.0
   test: ^1.16.0
diff --git a/pkgs/source_maps/test/parser_test.dart b/pkgs/source_maps/test/parser_test.dart
index 7c7b142..cf320b6 100644
--- a/pkgs/source_maps/test/parser_test.dart
+++ b/pkgs/source_maps/test/parser_test.dart
@@ -373,7 +373,7 @@
     var mapping = parseJson(map) as SingleMapping;
     expect(mapping.toJson(), equals(map));
     expect(mapping.extensions['x_foo'], equals('a'));
-    expect(mapping.extensions['x_bar'].first, equals(3));
+    expect((mapping.extensions['x_bar'] as List).first, equals(3));
   });
 
   group('source files', () {
diff --git a/pkgs/source_maps/test/refactor_test.dart b/pkgs/source_maps/test/refactor_test.dart
index 9a403a1..0389631 100644
--- a/pkgs/source_maps/test/refactor_test.dart
+++ b/pkgs/source_maps/test/refactor_test.dart
@@ -4,11 +4,11 @@
 
 library polymer.test.refactor_test;
 
-import 'package:test/test.dart';
-import 'package:source_maps/refactor.dart';
 import 'package:source_maps/parser.dart' show parse, Mapping;
+import 'package:source_maps/refactor.dart';
 import 'package:source_span/source_span.dart';
 import 'package:term_glyph/term_glyph.dart' as term_glyph;
+import 'package:test/test.dart';
 
 void main() {
   setUpAll(() {
diff --git a/pkgs/source_maps/test/utils_test.dart b/pkgs/source_maps/test/utils_test.dart
index 3064d6b..4abdce2 100644
--- a/pkgs/source_maps/test/utils_test.dart
+++ b/pkgs/source_maps/test/utils_test.dart
@@ -5,8 +5,8 @@
 /// Tests for the binary search utility algorithm.
 library test.utils_test;
 
-import 'package:test/test.dart';
 import 'package:source_maps/src/utils.dart';
+import 'package:test/test.dart';
 
 void main() {
   group('binary search', () {
@@ -31,7 +31,7 @@
 
     test('compare with linear search', () {
       for (var size = 0; size < 100; size++) {
-        var list = [];
+        var list = <int>[];
         for (var i = 0; i < size; i++) {
           list.add(i);
         }
@@ -44,8 +44,8 @@
   });
 }
 
-int _linearSearch(list, predicate) {
-  if (list.length == 0) return -1;
+int _linearSearch<T>(List<T> list, bool Function(T) predicate) {
+  if (list.isEmpty) return -1;
   for (var i = 0; i < list.length; i++) {
     if (predicate(list[i])) return i;
   }
diff --git a/pkgs/source_maps/test/vlq_test.dart b/pkgs/source_maps/test/vlq_test.dart
index 5a4f02a..9419300 100644
--- a/pkgs/source_maps/test/vlq_test.dart
+++ b/pkgs/source_maps/test/vlq_test.dart
@@ -5,8 +5,9 @@
 library test.vlq_test;
 
 import 'dart:math';
-import 'package:test/test.dart';
+
 import 'package:source_maps/src/vlq.dart';
+import 'package:test/test.dart';
 
 void main() {
   test('encode and decode - simple values', () {