Fix comment reference issues, among other new lints (dart-lang/stack_trace#119)

diff --git a/pkgs/stack_trace/analysis_options.yaml b/pkgs/stack_trace/analysis_options.yaml
index 1efeefc..48d93f2 100644
--- a/pkgs/stack_trace/analysis_options.yaml
+++ b/pkgs/stack_trace/analysis_options.yaml
@@ -1,3 +1,4 @@
+# https://dart.dev/guides/language/analysis-options
 include: package:lints/recommended.yaml
 
 analyzer:
@@ -8,9 +9,14 @@
 linter:
   rules:
     - always_declare_return_types
+    - avoid_catching_errors
+    - avoid_dynamic_calls
     - avoid_private_typedef_functions
+    - avoid_redundant_argument_values
     - avoid_unused_constructor_parameters
+    - avoid_void_async
     - cancel_subscriptions
+    - comment_references
     - directives_ordering
     - lines_longer_than_80_chars
     - literal_only_boolean_expressions
@@ -19,12 +25,20 @@
     - no_runtimeType_toString
     - omit_local_variable_types
     - package_api_docs
+    - prefer_asserts_in_initializer_lists
+    - prefer_const_constructors
+    - prefer_const_declarations
     - prefer_relative_imports
     - prefer_single_quotes
+    - sort_pub_dependencies
     - test_types_in_equals
     - throw_in_finally
     - type_annotate_public_apis
     - unawaited_futures
     - unnecessary_await_in_return
     - unnecessary_lambdas
+    - unnecessary_parenthesis
+    - unnecessary_statements
+    - use_is_even_rather_than_modulo
+    - use_string_buffers
     - use_super_parameters
diff --git a/pkgs/stack_trace/example/example.dart b/pkgs/stack_trace/example/example.dart
index a65abb1..7d71221 100644
--- a/pkgs/stack_trace/example/example.dart
+++ b/pkgs/stack_trace/example/example.dart
@@ -7,7 +7,7 @@
 }
 
 void _scheduleAsync() {
-  Future.delayed(Duration(seconds: 1)).then((_) => _runAsync());
+  Future.delayed(const Duration(seconds: 1)).then((_) => _runAsync());
 }
 
 void _runAsync() {
diff --git a/pkgs/stack_trace/lib/src/chain.dart b/pkgs/stack_trace/lib/src/chain.dart
index 69f9b0c..6a815c6 100644
--- a/pkgs/stack_trace/lib/src/chain.dart
+++ b/pkgs/stack_trace/lib/src/chain.dart
@@ -21,7 +21,7 @@
 /// A chain of stack traces.
 ///
 /// A stack chain is a collection of one or more stack traces that collectively
-/// represent the path from [main] through nested function calls to a particular
+/// represent the path from `main` through nested function calls to a particular
 /// code location, usually where an error was thrown. Multiple stack traces are
 /// necessary when using asynchronous functions, since the program's stack is
 /// reset before each asynchronous callback is run.
@@ -189,21 +189,19 @@
   /// Returns a new [Chain] comprised of [traces].
   Chain(Iterable<Trace> traces) : traces = List<Trace>.unmodifiable(traces);
 
-  /// Returns a terser version of [this].
+  /// Returns a terser version of this chain.
   ///
   /// This calls [Trace.terse] on every trace in [traces], and discards any
   /// trace that contain only internal frames.
   ///
   /// This won't do anything with a raw JavaScript trace, since there's no way
   /// to determine which frames come from which Dart libraries. However, the
-  /// [`source_map_stack_trace`][source_map_stack_trace] package can be used to
-  /// convert JavaScript traces into Dart-style traces.
-  ///
-  /// [source_map_stack_trace]: https://pub.dev/packages/source_map_stack_trace
+  /// [`source_map_stack_trace`](https://pub.dev/packages/source_map_stack_trace)
+  /// package can be used to convert JavaScript traces into Dart-style traces.
   Chain get terse => foldFrames((_) => false, terse: true);
 
-  /// Returns a new [Chain] based on [this] where multiple stack frames matching
-  /// [predicate] are folded together.
+  /// Returns a new [Chain] based on this chain where multiple stack frames
+  /// matching [predicate] are folded together.
   ///
   /// This means that whenever there are multiple frames in a row that match
   /// [predicate], only the last one is kept. In addition, traces that are
@@ -239,7 +237,7 @@
     return Chain(nonEmptyTraces);
   }
 
-  /// Converts [this] to a [Trace].
+  /// Converts this chain to a [Trace].
   ///
   /// The trace version of a chain is just the concatenation of all the traces
   /// in the chain.
@@ -248,18 +246,19 @@
   @override
   String toString() {
     // Figure out the longest path so we know how much to pad.
-    var longest = traces.map((trace) {
-      return trace.frames
-          .map((frame) => frame.location.length)
-          .fold(0, math.max);
-    }).fold(0, math.max);
+    var longest = traces
+        .map((trace) => trace.frames
+            .map((frame) => frame.location.length)
+            .fold(0, math.max))
+        .fold(0, math.max);
 
     // Don't call out to [Trace.toString] here because that doesn't ensure that
     // padding is consistent across all traces.
-    return traces.map((trace) {
-      return trace.frames.map((frame) {
-        return '${frame.location.padRight(longest)}  ${frame.member}\n';
-      }).join();
-    }).join(chainGap);
+    return traces
+        .map((trace) => trace.frames
+            .map((frame) =>
+                '${frame.location.padRight(longest)}  ${frame.member}\n')
+            .join())
+        .join(chainGap);
   }
 }
diff --git a/pkgs/stack_trace/lib/src/stack_zone_specification.dart b/pkgs/stack_trace/lib/src/stack_zone_specification.dart
index 8d1b3a7..8408d04 100644
--- a/pkgs/stack_trace/lib/src/stack_zone_specification.dart
+++ b/pkgs/stack_trace/lib/src/stack_zone_specification.dart
@@ -64,15 +64,13 @@
   StackZoneSpecification(this._onError, {bool errorZone = true})
       : _errorZone = errorZone;
 
-  /// Converts [this] to a real [ZoneSpecification].
-  ZoneSpecification toSpec() {
-    return ZoneSpecification(
-        handleUncaughtError: _errorZone ? _handleUncaughtError : null,
-        registerCallback: _registerCallback,
-        registerUnaryCallback: _registerUnaryCallback,
-        registerBinaryCallback: _registerBinaryCallback,
-        errorCallback: _errorCallback);
-  }
+  /// Converts this specification to a real [ZoneSpecification].
+  ZoneSpecification toSpec() => ZoneSpecification(
+      handleUncaughtError: _errorZone ? _handleUncaughtError : null,
+      registerCallback: _registerCallback,
+      registerUnaryCallback: _registerUnaryCallback,
+      registerBinaryCallback: _registerBinaryCallback,
+      errorCallback: _errorCallback);
 
   /// Returns the current stack chain.
   ///
@@ -107,7 +105,7 @@
     }
   }
 
-  /// Tracks the current stack chain so it can be set to [_currentChain] when
+  /// Tracks the current stack chain so it can be set to [_currentNode] when
   /// [f] is run.
   ZoneCallback<R> _registerCallback<R>(
       Zone self, ZoneDelegate parent, Zone zone, R Function() f) {
@@ -116,27 +114,25 @@
     return parent.registerCallback(zone, () => _run(f, node));
   }
 
-  /// Tracks the current stack chain so it can be set to [_currentChain] when
+  /// Tracks the current stack chain so it can be set to [_currentNode] when
   /// [f] is run.
   ZoneUnaryCallback<R, T> _registerUnaryCallback<R, T>(
       Zone self, ZoneDelegate parent, Zone zone, R Function(T) f) {
     if (_disabled) return parent.registerUnaryCallback(zone, f);
     var node = _createNode(1);
-    return parent.registerUnaryCallback(zone, (arg) {
-      return _run(() => f(arg), node);
-    });
+    return parent.registerUnaryCallback(
+        zone, (arg) => _run(() => f(arg), node));
   }
 
-  /// Tracks the current stack chain so it can be set to [_currentChain] when
+  /// Tracks the current stack chain so it can be set to [_currentNode] when
   /// [f] is run.
   ZoneBinaryCallback<R, T1, T2> _registerBinaryCallback<R, T1, T2>(
       Zone self, ZoneDelegate parent, Zone zone, R Function(T1, T2) f) {
     if (_disabled) return parent.registerBinaryCallback(zone, f);
 
     var node = _createNode(1);
-    return parent.registerBinaryCallback(zone, (arg1, arg2) {
-      return _run(() => f(arg1, arg2), node);
-    });
+    return parent.registerBinaryCallback(
+        zone, (arg1, arg2) => _run(() => f(arg1, arg2), node));
   }
 
   /// Looks up the chain associated with [stackTrace] and passes it either to
diff --git a/pkgs/stack_trace/lib/src/trace.dart b/pkgs/stack_trace/lib/src/trace.dart
index 5df7e4d..2e4427d 100644
--- a/pkgs/stack_trace/lib/src/trace.dart
+++ b/pkgs/stack_trace/lib/src/trace.dart
@@ -94,12 +94,13 @@
     }
 
     var trace = Trace.from(StackTrace.current);
-    return LazyTrace(() {
-      // JS includes a frame for the call to StackTrace.current, but the VM
-      // doesn't, so we skip an extra frame in a JS context.
-      return Trace(trace.frames.skip(level + (inJS ? 2 : 1)),
-          original: trace.original.toString());
-    });
+    return LazyTrace(
+      () =>
+          // JS includes a frame for the call to StackTrace.current, but the VM
+          // doesn't, so we skip an extra frame in a JS context.
+          Trace(trace.frames.skip(level + (inJS ? 2 : 1)),
+              original: trace.original.toString()),
+    );
   }
 
   /// Returns a new stack trace containing the same data as [trace].
@@ -250,7 +251,7 @@
   /// platform is being used.
   StackTrace get vmTrace => VMTrace(frames);
 
-  /// Returns a terser version of [this].
+  /// Returns a terser version of this trace.
   ///
   /// This is accomplished by folding together multiple stack frames from the
   /// core library or from this package, as in [foldFrames]. Remaining core
@@ -260,15 +261,13 @@
   ///
   /// This won't do anything with a raw JavaScript trace, since there's no way
   /// to determine which frames come from which Dart libraries. However, the
-  /// [`source_map_stack_trace`][source_map_stack_trace] package can be used to
-  /// convert JavaScript traces into Dart-style traces.
-  ///
-  /// [source_map_stack_trace]: https://pub.dev/packages/source_map_stack_trace
+  /// [`source_map_stack_trace`][https://pub.dev/packages/source_map_stack_trace]
+  /// package can be used to convert JavaScript traces into Dart-style traces.
   ///
   /// For custom folding, see [foldFrames].
   Trace get terse => foldFrames((_) => false, terse: true);
 
-  /// Returns a new [Trace] based on [this] where multiple stack frames matching
+  /// Returns a new [Trace] based on `this` where multiple stack frames matching
   /// [predicate] are folded together.
   ///
   /// This means that whenever there are multiple frames in a row that match
diff --git a/pkgs/stack_trace/lib/src/utils.dart b/pkgs/stack_trace/lib/src/utils.dart
index 0dd1755..bd971fe 100644
--- a/pkgs/stack_trace/lib/src/utils.dart
+++ b/pkgs/stack_trace/lib/src/utils.dart
@@ -12,4 +12,4 @@
 
 // TODO(nweiz): When cross-platform imports work, use them to set this.
 /// Whether we're running in a JS context.
-final bool inJS = 0.0 is int;
+const bool inJS = 0.0 is int;
diff --git a/pkgs/stack_trace/test/chain/chain_test.dart b/pkgs/stack_trace/test/chain/chain_test.dart
index 892738f..6de759b 100644
--- a/pkgs/stack_trace/test/chain/chain_test.dart
+++ b/pkgs/stack_trace/test/chain/chain_test.dart
@@ -103,7 +103,7 @@
       test("doesn't enable chain-tracking", () {
         return Chain.disable(() {
           return Chain.capture(() {
-            var completer = Completer();
+            var completer = Completer<Chain>();
             inMicrotask(() {
               completer.complete(Chain.current());
             });
@@ -126,7 +126,7 @@
   group('Chain.disable()', () {
     test('disables chain-tracking', () {
       return Chain.disable(() {
-        var completer = Completer();
+        var completer = Completer<Chain>();
         inMicrotask(() => completer.complete(Chain.current()));
 
         return completer.future.then((chain) {
@@ -138,7 +138,7 @@
     test('Chain.capture() re-enables chain-tracking', () {
       return Chain.disable(() {
         return Chain.capture(() {
-          var completer = Completer();
+          var completer = Completer<Chain>();
           inMicrotask(() => completer.complete(Chain.current()));
 
           return completer.future.then((chain) {
@@ -173,7 +173,7 @@
     test("with when: false doesn't disable", () {
       return Chain.capture(() {
         return Chain.disable(() {
-          var completer = Completer();
+          var completer = Completer<Chain>();
           inMicrotask(() => completer.complete(Chain.current()));
 
           return completer.future.then((chain) {
diff --git a/pkgs/stack_trace/test/chain/dart2js_test.dart b/pkgs/stack_trace/test/chain/dart2js_test.dart
index 41eb1ce..5841466 100644
--- a/pkgs/stack_trace/test/chain/dart2js_test.dart
+++ b/pkgs/stack_trace/test/chain/dart2js_test.dart
@@ -184,7 +184,7 @@
 
   group('current() within capture()', () {
     test('called in a microtask', () async {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inMicrotask(() => completer.complete(Chain.current()));
       });
@@ -194,7 +194,7 @@
     });
 
     test('called in a one-shot timer', () async {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inOneShotTimer(() => completer.complete(Chain.current()));
       });
@@ -204,7 +204,7 @@
     });
 
     test('called in a periodic timer', () async {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inPeriodicTimer(() => completer.complete(Chain.current()));
       });
@@ -214,7 +214,7 @@
     });
 
     test('called in a nested series of asynchronous operations', () async {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inPeriodicTimer(() {
           inOneShotTimer(() {
@@ -228,7 +228,7 @@
     });
 
     test('called in a long future chain', () async {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inFutureChain(() => completer.complete(Chain.current()));
       });
@@ -239,11 +239,11 @@
   });
 
   test(
-      'current() outside of capture() returns a chain wrapping the current '
-      'trace', () {
-    // The test runner runs all tests with chains enabled.
-    return Chain.disable(() async {
-      var completer = Completer();
+    'current() outside of capture() returns a chain wrapping the current trace',
+    () =>
+        // The test runner runs all tests with chains enabled.
+        Chain.disable(() async {
+      var completer = Completer<Chain>();
       inMicrotask(() => completer.complete(Chain.current()));
 
       var chain = await completer.future;
@@ -251,14 +251,13 @@
       // chain isn't available and it just returns the current stack when
       // called.
       expect(chain.traces, hasLength(1));
-    });
-  });
+    }),
+  );
 
   group('forTrace() within capture()', () {
     test('called for a stack trace from a microtask', () async {
-      var chain = await Chain.capture(() {
-        return chainForTrace(inMicrotask, () => throw 'error');
-      });
+      var chain = await Chain.capture(
+          () => chainForTrace(inMicrotask, () => throw 'error'));
 
       // Because [chainForTrace] has to set up a future chain to capture the
       // stack trace while still showing it to the zone specification, it adds
@@ -267,17 +266,15 @@
     });
 
     test('called for a stack trace from a one-shot timer', () async {
-      var chain = await Chain.capture(() {
-        return chainForTrace(inOneShotTimer, () => throw 'error');
-      });
+      var chain = await Chain.capture(
+          () => chainForTrace(inOneShotTimer, () => throw 'error'));
 
       expect(chain.traces, hasLength(3));
     });
 
     test('called for a stack trace from a periodic timer', () async {
-      var chain = await Chain.capture(() {
-        return chainForTrace(inPeriodicTimer, () => throw 'error');
-      });
+      var chain = await Chain.capture(
+          () => chainForTrace(inPeriodicTimer, () => throw 'error'));
 
       expect(chain.traces, hasLength(3));
     });
@@ -285,19 +282,16 @@
     test(
         'called for a stack trace from a nested series of asynchronous '
         'operations', () async {
-      var chain = await Chain.capture(() {
-        return chainForTrace((callback) {
-          inPeriodicTimer(() => inOneShotTimer(() => inMicrotask(callback)));
-        }, () => throw 'error');
-      });
+      var chain = await Chain.capture(() => chainForTrace((callback) {
+            inPeriodicTimer(() => inOneShotTimer(() => inMicrotask(callback)));
+          }, () => throw 'error'));
 
       expect(chain.traces, hasLength(5));
     });
 
     test('called for a stack trace from a long future chain', () async {
-      var chain = await Chain.capture(() {
-        return chainForTrace(inFutureChain, () => throw 'error');
-      });
+      var chain = await Chain.capture(
+          () => chainForTrace(inFutureChain, () => throw 'error'));
 
       expect(chain.traces, hasLength(3));
     });
diff --git a/pkgs/stack_trace/test/chain/utils.dart b/pkgs/stack_trace/test/chain/utils.dart
index 0a74d9a..2cc6452 100644
--- a/pkgs/stack_trace/test/chain/utils.dart
+++ b/pkgs/stack_trace/test/chain/utils.dart
@@ -16,7 +16,7 @@
 /// Runs [callback] once in a periodic timer callback.
 void inPeriodicTimer(void Function() callback) {
   var count = 0;
-  Timer.periodic(Duration(milliseconds: 1), (timer) {
+  Timer.periodic(const Duration(milliseconds: 1), (timer) {
     count++;
     if (count != 5) return;
     timer.cancel();
diff --git a/pkgs/stack_trace/test/chain/vm_test.dart b/pkgs/stack_trace/test/chain/vm_test.dart
index 7c8278b..83e01d4 100644
--- a/pkgs/stack_trace/test/chain/vm_test.dart
+++ b/pkgs/stack_trace/test/chain/vm_test.dart
@@ -282,7 +282,7 @@
 
   group('current() within capture()', () {
     test('called in a microtask', () {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inMicrotask(() => completer.complete(Chain.current()));
       });
@@ -296,7 +296,7 @@
     });
 
     test('called in a one-shot timer', () {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inOneShotTimer(() => completer.complete(Chain.current()));
       });
@@ -310,7 +310,7 @@
     });
 
     test('called in a periodic timer', () {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inPeriodicTimer(() => completer.complete(Chain.current()));
       });
@@ -324,7 +324,7 @@
     });
 
     test('called in a nested series of asynchronous operations', () {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inPeriodicTimer(() {
           inOneShotTimer(() {
@@ -346,7 +346,7 @@
     });
 
     test('called in a long future chain', () {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       Chain.capture(() {
         inFutureChain(() => completer.complete(Chain.current()));
       });
@@ -365,7 +365,7 @@
       'trace', () {
     // The test runner runs all tests with chains enabled.
     return Chain.disable(() {
-      var completer = Completer();
+      var completer = Completer<Chain>();
       inMicrotask(() => completer.complete(Chain.current()));
 
       return completer.future.then((chain) {
diff --git a/pkgs/stack_trace/test/utils.dart b/pkgs/stack_trace/test/utils.dart
index 8092efe..98cb5ed 100644
--- a/pkgs/stack_trace/test/utils.dart
+++ b/pkgs/stack_trace/test/utils.dart
@@ -2,37 +2,13 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'package:stack_trace/stack_trace.dart';
 import 'package:test/test.dart';
 
 /// Returns a matcher that runs [matcher] against a [Frame]'s `member` field.
 Matcher frameMember(Object? matcher) =>
-    transform((frame) => frame.member, matcher, 'member');
+    isA<Frame>().having((p0) => p0.member, 'member', matcher);
 
 /// Returns a matcher that runs [matcher] against a [Frame]'s `library` field.
 Matcher frameLibrary(Object? matcher) =>
-    transform((frame) => frame.library, matcher, 'library');
-
-/// Returns a matcher that runs [transformation] on its input, then matches
-/// the output against [matcher].
-///
-/// [description] should be a noun phrase that describes the relation of the
-/// output of [transformation] to its input.
-Matcher transform(void Function(dynamic) transformation, Object? matcher,
-        String description) =>
-    _TransformMatcher(transformation, wrapMatcher(matcher), description);
-
-class _TransformMatcher extends Matcher {
-  final Function _transformation;
-  final Matcher _matcher;
-  final String _description;
-
-  _TransformMatcher(this._transformation, this._matcher, this._description);
-
-  @override
-  bool matches(Object? item, Map<dynamic, dynamic> matchState) =>
-      _matcher.matches(_transformation(item), matchState);
-
-  @override
-  Description describe(Description description) =>
-      description.add(_description).add(' ').addDescriptionOf(_matcher);
-}
+    isA<Frame>().having((p0) => p0.library, 'library', matcher);
diff --git a/pkgs/stack_trace/test/vm_test.dart b/pkgs/stack_trace/test/vm_test.dart
index c9f819a..e0dbcff 100644
--- a/pkgs/stack_trace/test/vm_test.dart
+++ b/pkgs/stack_trace/test/vm_test.dart
@@ -67,7 +67,7 @@
       });
 
       test('at level 0 returns a trace starting at the current frame', () {
-        var trace = Trace.current(0);
+        var trace = Trace.current();
         expect(trace.frames.first.member, equals('main.<fn>.<fn>.<fn>'));
       });