Skip to content

Commit

Permalink
[tools] updating linting in tools/ and reduce use of dynamic
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
devoncarew authored and Commit Queue committed Jul 15, 2024
1 parent 9637321 commit 4e7a94b
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 55 deletions.
8 changes: 3 additions & 5 deletions tools/addlatexhash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ sispIsDartEnd(line) => line.contains(dartCodeEndRE);
// 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) {
Expand Down Expand Up @@ -523,7 +521,7 @@ addHashMarks(lines, hashEvents, listSink) {
}

/// 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";
Expand Down
2 changes: 2 additions & 0 deletions tools/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ linter:
rules:
# TODO: Enable this once other issues are addressed.
# - avoid_dynamic_calls
- comment_references
- depend_on_referenced_packages
- directives_ordering
- unnecessary_library_name
2 changes: 1 addition & 1 deletion tools/bots/compare_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion tools/bots/extend_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:test_runner/bot_results.dart';

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];
Expand Down
8 changes: 4 additions & 4 deletions tools/bots/find_base_commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main(List<String> args) async {
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.
Expand All @@ -39,9 +39,9 @@ ${parser.usage}""");
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;
Expand Down Expand Up @@ -126,7 +126,7 @@ ${parser.usage}""");
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;
}
Expand Down
26 changes: 19 additions & 7 deletions tools/bots/get_builder_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,31 @@ void main(List<String> args) async {
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']);
useStagingDatabase = options.flag('staging');

if (options.option('builder') == null) {
print('Option "--builder" is required\n');
usage(parser);
}
builder = options.option('builder')!;
builderBase = builder.replaceFirst(RegExp('-try\$'), '');
if (options['auth_token'] == null) {
print('Option "--auth_token (-a)" is required\n');

if (options.option('build_number') == null) {
print('Option "--build_number" is required\n');
usage(parser);
}
token = await readGcloudAuthToken(options['auth_token']);
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) {
Expand Down
12 changes: 6 additions & 6 deletions tools/bots/update_blamelists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Future<void> updateBlameLists(String configuration, String commit,
} while (needsRetry);
}

main(List<String> arguments) async {
void main(List<String> arguments) async {
var parser = ArgParser()
..addOption('auth-token',
abbr: 'a',
Expand All @@ -162,12 +162,12 @@ main(List<String> arguments) async {
..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;
Expand All @@ -176,9 +176,9 @@ main(List<String> arguments) async {
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();
}
23 changes: 12 additions & 11 deletions tools/bots/update_flakiness.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main(List<String> args) async {
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.
Expand All @@ -35,8 +35,8 @@ ${parser.usage}''');
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 = {
Expand All @@ -59,7 +59,7 @@ ${parser.usage}''');
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)
Expand All @@ -79,19 +79,20 @@ ${parser.usage}''');
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]!;
Expand All @@ -103,7 +104,7 @@ ${parser.usage}''');
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.
Expand Down
11 changes: 6 additions & 5 deletions tools/diff_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ ${parser.usage}""");

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;
}
Expand All @@ -43,9 +43,10 @@ main(List<String> args) async {
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>>>[];
Expand Down Expand Up @@ -301,7 +302,7 @@ class Result {
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;
Expand Down
2 changes: 1 addition & 1 deletion tools/generate_package_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Iterable<Package> makeFrontendServerPackageConfigs(List<String> packageDirs) =>
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* {
Expand Down
9 changes: 5 additions & 4 deletions tools/line_doc_comments.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +14,7 @@ final startBlock = RegExp(r'^(\s*)/\*\*(.*)$');
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.');
Expand Down
4 changes: 2 additions & 2 deletions tools/manage_deps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ This will:
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],
Expand Down Expand Up @@ -115,7 +115,7 @@ This will:
'git',
'rev-parse',
if (argResults.wasParsed('target'))
argResults['target']
argResults.option('target')!
else
'origin/${defaultBranchTarget(pkgDir)}',
], workingDirectory: pkgDir, explanation: 'Finding sha-id');
Expand Down
2 changes: 1 addition & 1 deletion tools/run_offsets_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:pool/pool.dart';

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);

Expand Down
4 changes: 2 additions & 2 deletions tools/spec_parser/spec_parse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const String classPath = '.:/usr/share/java/antlr3-runtime.jar';
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}');
}
Expand Down
2 changes: 1 addition & 1 deletion tools/validate_test_matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'dart:io' show File, Platform;

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 {
Expand Down
4 changes: 1 addition & 3 deletions tools/verify_docs/bin/verify_docs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
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
Expand Down Expand Up @@ -381,8 +381,6 @@ class ValidateCommentCodeSamplesVisitor extends GeneralizingAstVisitor {
} else {
throw 'unexpected result type: $result';
}

return;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/yaml2json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:isolate' show RawReceivePort;

import 'package:yaml/yaml.dart' show loadYaml;

main(List<String> rawArguments) {
void main(List<String> rawArguments) {
var port = RawReceivePort();
bool check = false;
String? relative;
Expand Down

0 comments on commit 4e7a94b

Please sign in to comment.