[tools] updating linting in tools/ and reduce use of dynamic

Change-Id: I9e543a384fb10495af4598bfeb12c42944ff614f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375745
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
diff --git a/tools/addlatexhash.dart b/tools/addlatexhash.dart
index c269368..fd06743 100755
--- a/tools/addlatexhash.dart
+++ b/tools/addlatexhash.dart
@@ -190,10 +190,8 @@
 // Analyzing the input to point out "interesting" lines
 
 /// Returns the event information for [lines] as determined by the
-/// given [analyzer].  The method [analyzer.analyze] indicates that a
-/// line is "uninteresting" by returning null (i.e., no events here),
-/// and "interesting" lines may be characterized by [analysisFunc] via
-/// the returned event object.
+/// given [analyzer].  The method [HashAnalyzer.analyze] indicates that a
+/// line is "uninteresting" by returning null (i.e., no events here).
 findEvents(lines, analyzer) {
   var events = [];
   for (var line in lines) {
@@ -523,7 +521,7 @@
 }
 
 /// Transforms LaTeX input to LaTeX output plus hash value list file.
-main([args]) {
+void main(List<String> args) {
   if (args.length != 3) {
     print("Usage: addlatexhash.dart <input-file> <output-file> <list-file>");
     throw "Received ${args.length} arguments, expected three";
diff --git a/tools/analysis_options.yaml b/tools/analysis_options.yaml
index 204e7c6..aeff415 100644
--- a/tools/analysis_options.yaml
+++ b/tools/analysis_options.yaml
@@ -13,5 +13,7 @@
   rules:
     # TODO: Enable this once other issues are addressed.
     # - avoid_dynamic_calls
+    - comment_references
     - depend_on_referenced_packages
     - directives_ordering
+    - unnecessary_library_name
diff --git a/tools/bots/compare_results.dart b/tools/bots/compare_results.dart
index 5ca9f1f..c3ba007 100755
--- a/tools/bots/compare_results.dart
+++ b/tools/bots/compare_results.dart
@@ -9,6 +9,6 @@
 
 import '../../pkg/test_runner/bin/compare_results.dart' as compare_results;
 
-main(List<String> args) {
+void main(List<String> args) {
   compare_results.main(args);
 }
diff --git a/tools/bots/extend_results.dart b/tools/bots/extend_results.dart
index 98fcec8..9d60d16 100644
--- a/tools/bots/extend_results.dart
+++ b/tools/bots/extend_results.dart
@@ -12,7 +12,7 @@
 
 const skipped = 'skipped';
 
-main(List<String> args) async {
+void main(List<String> args) async {
   final resultsPath = args[0];
   final priorResultsPath = args[1];
   final flakyPath = args[2];
diff --git a/tools/bots/find_base_commit.dart b/tools/bots/find_base_commit.dart
index 595871d..c833220 100755
--- a/tools/bots/find_base_commit.dart
+++ b/tools/bots/find_base_commit.dart
@@ -28,7 +28,7 @@
   parser.addFlag("help", help: "Show the program usage.", negatable: false);
 
   final options = parser.parse(args);
-  if (options["help"]) {
+  if (options.flag("help")) {
     print("""
 Usage: find_base_commit.dart [OPTION]...
 Find the newest commit that has a full set of results on the builders.
@@ -39,9 +39,9 @@
     return;
   }
 
-  int count = int.parse(options["count"]);
+  int count = int.parse(options.option("count")!);
   final globs = List<Glob>.from(
-      options["builder"].map((String pattern) => Glob(pattern)));
+      options.multiOption("builder").map((String pattern) => Glob(pattern)));
 
   // Download the most recent builds from buildbucket.
   const maxBuilds = 1000;
@@ -126,7 +126,7 @@
       continue;
     }
     final ref = input["ref"];
-    if (ref != "refs/heads/${options['branch']}") {
+    if (ref != "refs/heads/${options.option('branch')}") {
       // Ignore builds on the wrong branch.
       continue;
     }
diff --git a/tools/bots/get_builder_status.dart b/tools/bots/get_builder_status.dart
index 6abf4ef..32b0c93 100755
--- a/tools/bots/get_builder_status.dart
+++ b/tools/bots/get_builder_status.dart
@@ -68,19 +68,31 @@
       abbr: 's', help: 'use staging database', defaultsTo: false);
 
   final options = parser.parse(args);
-  if (options['help']) {
+  if (options.flag('help')) {
     usage(parser);
   }
 
-  useStagingDatabase = options['staging'];
-  builder = options['builder'];
-  buildNumber = int.parse(options['build_number']);
-  builderBase = builder.replaceFirst(RegExp('-try\$'), '');
-  if (options['auth_token'] == null) {
-    print('Option "--auth_token (-a)" is required\n');
+  useStagingDatabase = options.flag('staging');
+
+  if (options.option('builder') == null) {
+    print('Option "--builder" is required\n');
     usage(parser);
   }
-  token = await readGcloudAuthToken(options['auth_token']);
+  builder = options.option('builder')!;
+  builderBase = builder.replaceFirst(RegExp('-try\$'), '');
+
+  if (options.option('build_number') == null) {
+    print('Option "--build_number" is required\n');
+    usage(parser);
+  }
+  buildNumber = int.parse(options.option('build_number')!);
+
+  if (options.option('auth_token') == null) {
+    print('Option "--auth_token" is required\n');
+    usage(parser);
+  }
+  token = await readGcloudAuthToken(options.option('auth_token')!);
+
   client = http.Client();
   final response = await runFirestoreQuery(buildQuery());
   if (response.statusCode != HttpStatus.ok) {
diff --git a/tools/bots/update_blamelists.dart b/tools/bots/update_blamelists.dart
index 4832c51..00b2dd4 100644
--- a/tools/bots/update_blamelists.dart
+++ b/tools/bots/update_blamelists.dart
@@ -151,7 +151,7 @@
   } while (needsRetry);
 }
 
-main(List<String> arguments) async {
+void main(List<String> arguments) async {
   var parser = ArgParser()
     ..addOption('auth-token',
         abbr: 'a',
@@ -162,12 +162,12 @@
     ..addFlag('staging', abbr: 's', help: 'use staging database');
   var options = parser.parse(arguments);
   if (options.rest.isNotEmpty ||
-      options['results'] == null ||
-      options['auth-token'] == null) {
+      options.option('results') == null ||
+      options.option('auth-token') == null) {
     print(parser.usage);
     exit(1);
   }
-  var results = await loadResultsMap(options['results']);
+  var results = await loadResultsMap(options.option('results')!);
   if (results.isEmpty) {
     print("No test results provided, nothing to update.");
     return;
@@ -176,9 +176,9 @@
   var firstResult = Result.fromMap(results.values.first);
   var commit = firstResult.commitHash!;
   var configuration = firstResult.configuration;
-  var project = options['staging'] ? 'dart-ci-staging' : 'dart-ci';
+  var project = options.flag('staging') ? 'dart-ci-staging' : 'dart-ci';
   database = FirestoreDatabase(
-      project, await readGcloudAuthToken(options['auth-token']));
+      project, await readGcloudAuthToken(options.option('auth-token')!));
   await updateBlameLists(configuration, commit, results);
   database.closeClient();
 }
diff --git a/tools/bots/update_flakiness.dart b/tools/bots/update_flakiness.dart
index f0368bb..31923ed 100755
--- a/tools/bots/update_flakiness.dart
+++ b/tools/bots/update_flakiness.dart
@@ -22,7 +22,7 @@
   parser.addFlag('no-forgive', help: 'Don\'t remove any flaky records');
 
   final options = parser.parse(args);
-  if (options['help']) {
+  if (options.flag('help')) {
     print('''
 Usage: update_flakiness.dart [OPTION]... [RESULT-FILE]...
 Update the flakiness data with a set of fresh results.
@@ -35,8 +35,8 @@
   final parameters = options.rest;
 
   // Load the existing flakiness data, if any.
-  final data = options['input'] != null
-      ? await loadResultsMap(options['input'])
+  final data = options.option('input') != null
+      ? await loadResultsMap(options.option('input')!)
       : <String, Map<String, dynamic>>{};
 
   final resultsForInactiveFlakiness = {
@@ -59,7 +59,7 @@
       testData['configuration'] = configuration;
       testData['name'] = name;
       testData['expected'] = resultObject['expected'];
-      final List<dynamic> outcomes = testData['outcomes'] ??= [];
+      final List<dynamic> outcomes = testData['outcomes'] ??= <dynamic>[];
       if (!outcomes.contains(result)) {
         outcomes
           ..add(result)
@@ -79,19 +79,20 @@
       mapField('first_seen')[result] ??= nowString;
       mapField('last_seen')[result] = nowString;
       mapField('matches')[result] = resultObject['matches'];
-      if (options['build-id'] != null) {
-        mapField('build_ids')[result] = options['build-id'];
+      if (options.option('build-id') != null) {
+        mapField('build_ids')[result] = options.option('build-id')!;
       }
-      if (options['commit'] != null) {
-        mapField('commits')[result] = options['commit'];
+      if (options.option('commit') != null) {
+        mapField('commits')[result] = options.option('commit')!;
       }
     }
   }
 
   // Write out the new flakiness data.
   final flakinessHorizon = now.subtract(Duration(days: 7));
-  final sink =
-      options['output'] != null ? File(options['output']).openWrite() : stdout;
+  final sink = options.option('output') != null
+      ? File(options.option('output')!).openWrite()
+      : stdout;
   final keys = data.keys.toList()..sort();
   for (final key in keys) {
     final testData = data[key]!;
@@ -103,7 +104,7 @@
         testData['reactivation_count'] =
             (testData['reactivation_count'] ?? 0) + 1;
       }
-    } else if (options['no-forgive']) {
+    } else if (options.flag('no-forgive')) {
       testData['active'] = true;
     } else if (testData['current_counter'] >= 100) {
       // Forgive tests that have been stable for 100 builds.
diff --git a/tools/diff_results.dart b/tools/diff_results.dart
index 764e366..c4e2366 100644
--- a/tools/diff_results.dart
+++ b/tools/diff_results.dart
@@ -29,9 +29,9 @@
 
 late bool verbose;
 
-main(List<String> args) async {
+void main(List<String> args) async {
   final options = parser.parse(args);
-  if (options["help"]) {
+  if (options.flag("help")) {
     printUsage();
     return;
   }
@@ -43,9 +43,10 @@
     exitCode = 1;
     return;
   }
-  verbose = options['verbose'] ?? false;
+  verbose = options.flag('verbose');
 
-  final globs = List<Glob>.from(options["bot"].map((pattern) => Glob(pattern)));
+  final globs = List<Glob>.from(
+      options.multiOption('bot').map((pattern) => Glob(pattern)));
   final vmBuilders = loadVmBuildersFromTestMatrix(globs);
 
   final futures = <Future<List<Result>>>[];
@@ -301,7 +302,7 @@
         result == other.result;
   }
 
-  bool equals(other) {
+  bool equals(Object other) {
     if (other is Result) {
       if (name != other.name) return false;
       if (builderName != other.builderName) return false;
diff --git a/tools/generate_package_config.dart b/tools/generate_package_config.dart
index c713edaa..4d486e8 100644
--- a/tools/generate_package_config.dart
+++ b/tools/generate_package_config.dart
@@ -191,7 +191,7 @@
 Iterable<Package> makePkgVmPackageConfigs(List<String> packageDirs) =>
     makeSpecialPackageConfigs('pkg_vm', packageDirs);
 
-/// Finds the paths of the subdirectories of [dirPath] that contain pubspecs.
+/// Finds the paths of the subdirectories of [parentPath] that contain pubspecs.
 ///
 /// This method recurses until it finds a pubspec.yaml file.
 Iterable<String> listSubdirectories(String parentPath) sync* {
diff --git a/tools/line_doc_comments.dart b/tools/line_doc_comments.dart
index c15beb7..9b30959 100755
--- a/tools/line_doc_comments.dart
+++ b/tools/line_doc_comments.dart
@@ -1,8 +1,9 @@
-#!/usr/bin/env dart
+// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
+// 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.
 
 /// Converts block-style Doc comments in Dart code to line style.
-
-library line_doc_comments;
+library;
 
 import 'dart:io';
 
@@ -13,7 +14,7 @@
 final blockLine = RegExp(r'^\s*\*\s?(.*)$');
 final endBlock = RegExp(r'^\s*\*/\s*$');
 
-main(List<String> args) {
+void main(List<String> args) {
   if (args.length != 1) {
     print('Converts "/**"-style block doc comments in a directory ');
     print('containing Dart code to "///"-style line doc comments.');
diff --git a/tools/manage_deps.dart b/tools/manage_deps.dart
index d83d604..20e7a53 100755
--- a/tools/manage_deps.dart
+++ b/tools/manage_deps.dart
@@ -73,7 +73,7 @@
       usageException('No directory $pkgDir');
     }
     final toUpdate = p.split(pkgDir).last;
-    final branchName = argResults['branch'] ?? 'bump_$toUpdate';
+    final branchName = argResults.option('branch') ?? 'bump_$toUpdate';
 
     final exists = runProcessForExitCode(
         ['git', 'rev-parse', '--verify', branchName],
@@ -115,7 +115,7 @@
       'git',
       'rev-parse',
       if (argResults.wasParsed('target'))
-        argResults['target']
+        argResults.option('target')!
       else
         'origin/${defaultBranchTarget(pkgDir)}',
     ], workingDirectory: pkgDir, explanation: 'Finding sha-id');
diff --git a/tools/run_offsets_extractor.dart b/tools/run_offsets_extractor.dart
index 2f9b9d9..fabe1e8 100755
--- a/tools/run_offsets_extractor.dart
+++ b/tools/run_offsets_extractor.dart
@@ -9,7 +9,7 @@
 
 final pool = Pool(Platform.numberOfProcessors);
 
-main(List<String> args) async {
+void main(List<String> args) async {
   final sdkRoot = Platform.script.resolve('../').toFilePath();
   Directory.current = Directory(sdkRoot);
 
diff --git a/tools/spec_parser/spec_parse.dart b/tools/spec_parser/spec_parse.dart
index d680f6d..52971b8 100755
--- a/tools/spec_parser/spec_parse.dart
+++ b/tools/spec_parser/spec_parse.dart
@@ -9,9 +9,9 @@
 const String mainClass = 'SpecParser';
 const String javaExecutable = 'java';
 
-main([arguments]) {
+void main(List<String> arguments) {
   for (String arg in arguments) {
-    handleResult(ProcessResult result) {
+    void handleResult(ProcessResult result) {
       if (result.stderr.length != 0) {
         print('Error parsing $arg:\n${result.stderr}');
       }
diff --git a/tools/validate_test_matrix.dart b/tools/validate_test_matrix.dart
index 3f36bae..f72f03f 100644
--- a/tools/validate_test_matrix.dart
+++ b/tools/validate_test_matrix.dart
@@ -9,7 +9,7 @@
 
 import 'package:smith/smith.dart' show TestMatrix;
 
-main() {
+void main() {
   var path = Platform.script.resolve("bots/test_matrix.json").toFilePath();
   Map<String, dynamic> json;
   try {
diff --git a/tools/verify_docs/bin/verify_docs.dart b/tools/verify_docs/bin/verify_docs.dart
index 97ae4e5..496a28f 100755
--- a/tools/verify_docs/bin/verify_docs.dart
+++ b/tools/verify_docs/bin/verify_docs.dart
@@ -242,7 +242,7 @@
       r'final class\b|class\b|mixin\b|enum\b|extension\b|typedef\b|.*\bmain\('
       r')');
 
-  validateCodeSample(CodeSample sample) async {
+  Future<void> validateCodeSample(CodeSample sample) async {
     final lines = sample.lines;
 
     // The default imports includes the library itself
@@ -381,8 +381,6 @@
     } else {
       throw 'unexpected result type: $result';
     }
-
-    return;
   }
 }
 
diff --git a/tools/yaml2json.dart b/tools/yaml2json.dart
index b8936fe..66c4daa 100644
--- a/tools/yaml2json.dart
+++ b/tools/yaml2json.dart
@@ -8,7 +8,7 @@
 
 import 'package:yaml/yaml.dart' show loadYaml;
 
-main(List<String> rawArguments) {
+void main(List<String> rawArguments) {
   var port = RawReceivePort();
   bool check = false;
   String? relative;