diff --git a/packages/flutter_tools/lib/src/commands/analyze.dart b/packages/flutter_tools/lib/src/commands/analyze.dart index 63d3ede975..fff00ced75 100644 --- a/packages/flutter_tools/lib/src/commands/analyze.dart +++ b/packages/flutter_tools/lib/src/commands/analyze.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import '../artifacts.dart'; @@ -20,12 +17,12 @@ class AnalyzeCommand extends FlutterCommand { AnalyzeCommand({ bool verboseHelp = false, this.workingDirectory, - @required FileSystem fileSystem, - @required Platform platform, - @required Terminal terminal, - @required Logger logger, - @required ProcessManager processManager, - @required Artifacts artifacts, + required FileSystem fileSystem, + required Platform platform, + required Terminal terminal, + required Logger logger, + required ProcessManager processManager, + required Artifacts artifacts, }) : _artifacts = artifacts, _fileSystem = fileSystem, _processManager = processManager, @@ -35,7 +32,6 @@ class AnalyzeCommand extends FlutterCommand { argParser.addFlag('flutter-repo', negatable: false, help: 'Include all the examples and tests from the Flutter repository.', - defaultsTo: false, hide: !verboseHelp); argParser.addFlag('current-package', help: 'Analyze the current project, if applicable.', defaultsTo: true); @@ -80,17 +76,15 @@ class AnalyzeCommand extends FlutterCommand { 'files that will be analyzed.\n' 'Ignored if "--watch" is specified.'); argParser.addFlag('fatal-infos', - negatable: true, help: 'Treat info level issues as fatal.', defaultsTo: true); argParser.addFlag('fatal-warnings', - negatable: true, help: 'Treat warning level issues as fatal.', defaultsTo: true); } /// The working directory for testing analysis using dartanalyzer. - final Directory workingDirectory; + final Directory? workingDirectory; final Artifacts _artifacts; final FileSystem _fileSystem; @@ -127,9 +121,9 @@ class AnalyzeCommand extends FlutterCommand { Future runCommand() async { if (boolArg('watch')) { await AnalyzeContinuously( - argResults, - runner.getRepoRoots(), - runner.getRepoPackages(), + argResults!, + runner!.getRepoRoots(), + runner!.getRepoPackages(), fileSystem: _fileSystem, logger: _logger, platform: _platform, @@ -139,9 +133,9 @@ class AnalyzeCommand extends FlutterCommand { ).analyze(); } else { await AnalyzeOnce( - argResults, - runner.getRepoRoots(), - runner.getRepoPackages(), + argResults!, + runner!.getRepoRoots(), + runner!.getRepoPackages(), workingDirectory: workingDirectory, fileSystem: _fileSystem, logger: _logger, diff --git a/packages/flutter_tools/lib/src/commands/analyze_continuously.dart b/packages/flutter_tools/lib/src/commands/analyze_continuously.dart index 05e4d6512c..b791ae2b3d 100644 --- a/packages/flutter_tools/lib/src/commands/analyze_continuously.dart +++ b/packages/flutter_tools/lib/src/commands/analyze_continuously.dart @@ -2,10 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:args/args.dart'; -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import '../artifacts.dart'; @@ -23,12 +20,12 @@ class AnalyzeContinuously extends AnalyzeBase { ArgResults argResults, List repoRoots, List repoPackages, { - @required FileSystem fileSystem, - @required Logger logger, - @required Terminal terminal, - @required Platform platform, - @required ProcessManager processManager, - @required Artifacts artifacts, + required FileSystem fileSystem, + required Logger logger, + required Terminal terminal, + required Platform platform, + required ProcessManager processManager, + required Artifacts artifacts, }) : super( argResults, repoPackages: repoPackages, @@ -41,13 +38,13 @@ class AnalyzeContinuously extends AnalyzeBase { artifacts: artifacts, ); - String analysisTarget; + String? analysisTarget; bool firstAnalysis = true; Set analyzedPaths = {}; Map> analysisErrors = >{}; - Stopwatch analysisTimer; + final Stopwatch analysisTimer = Stopwatch(); int lastErrorCount = 0; - Status analysisStatus; + Status? analysisStatus; @override Future analyze() async { @@ -83,7 +80,7 @@ class AnalyzeContinuously extends AnalyzeBase { server.onErrors.listen(_handleAnalysisErrors); await server.start(); - final int exitCode = await server.onExit; + final int? exitCode = await server.onExit; final String message = 'Analysis server exited with code $exitCode.'; if (exitCode != 0) { @@ -104,7 +101,7 @@ class AnalyzeContinuously extends AnalyzeBase { } analysisStatus = logger.startProgress('Analyzing $analysisTarget...'); analyzedPaths.clear(); - analysisTimer = Stopwatch()..start(); + analysisTimer.start(); } else { analysisStatus?.stop(); analysisStatus = null; @@ -114,13 +111,13 @@ class AnalyzeContinuously extends AnalyzeBase { // Remove errors for deleted files, sort, and print errors. final List errors = []; - for (final String path in analysisErrors.keys.toList()) { + analysisErrors.forEach((String path, List errors) { if (fileSystem.isFileSync(path)) { - errors.addAll(analysisErrors[path]); + errors.addAll(errors); } else { analysisErrors.remove(path); } - } + }); errors.sort(); diff --git a/packages/flutter_tools/lib/src/commands/analyze_once.dart b/packages/flutter_tools/lib/src/commands/analyze_once.dart index 0101f0190b..f69f4c65ad 100644 --- a/packages/flutter_tools/lib/src/commands/analyze_once.dart +++ b/packages/flutter_tools/lib/src/commands/analyze_once.dart @@ -2,12 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'package:args/args.dart'; -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import '../artifacts.dart'; @@ -24,12 +21,12 @@ class AnalyzeOnce extends AnalyzeBase { ArgResults argResults, List repoRoots, List repoPackages, { - @required FileSystem fileSystem, - @required Logger logger, - @required Platform platform, - @required ProcessManager processManager, - @required Terminal terminal, - @required Artifacts artifacts, + required FileSystem fileSystem, + required Logger logger, + required Platform platform, + required ProcessManager processManager, + required Terminal terminal, + required Artifacts artifacts, this.workingDirectory, }) : super( argResults, @@ -44,7 +41,7 @@ class AnalyzeOnce extends AnalyzeBase { ); /// The working directory for testing analysis using dartanalyzer. - final Directory workingDirectory; + final Directory? workingDirectory; @override Future analyze() async { @@ -98,10 +95,10 @@ class AnalyzeOnce extends AnalyzeBase { protocolTrafficLog: protocolTrafficLog, ); - Stopwatch timer; - Status progress; + Stopwatch? timer; + Status? progress; try { - StreamSubscription subscription; + StreamSubscription? subscription; void handleAnalysisStatus(bool isAnalyzing) { if (!isAnalyzing) { @@ -123,7 +120,7 @@ class AnalyzeOnce extends AnalyzeBase { await server.start(); // Completing the future in the callback can't fail. - unawaited(server.onExit.then((int exitCode) { + unawaited(server.onExit.then((int? exitCode) { if (!analysisCompleter.isCompleted) { analysisCompleter.completeError( // Include the last 20 lines of server output in exception message @@ -139,7 +136,7 @@ class AnalyzeOnce extends AnalyzeBase { final String message = directories.length > 1 ? '${directories.length} ${directories.length == 1 ? 'directory' : 'directories'}' : fileSystem.path.basename(directories.first); - progress = argResults['preamble'] as bool + progress = argResults['preamble'] == true ? logger.startProgress( 'Analyzing $message...', ) diff --git a/packages/flutter_tools/test/general.shard/commands/analyze_base_test.dart b/packages/flutter_tools/test/general.shard/commands/analyze_base_test.dart index 6a7d5a4707..36cf3c9469 100644 --- a/packages/flutter_tools/test/general.shard/commands/analyze_base_test.dart +++ b/packages/flutter_tools/test/general.shard/commands/analyze_base_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_tools/src/commands/analyze_base.dart'; import '../../src/common.dart';